Adjusted project data.

Properly pointed to the repository location.

Changed the rust edition.
This commit is contained in:
2025-07-29 17:54:46 -04:00
parent 4357a3aff3
commit a370d13f7a
9 changed files with 114 additions and 196 deletions

View File

@ -3,9 +3,9 @@
/// A C Pointer to an undefined structure.
///
/// A lot of C libraries return a pointer to an undefined structure.
/// This is easily wrapped as an empty enum. This keeps users from being
/// able to create an instance of the value.
/// Many C libraries return pointers to opaque or incomplete types.
/// This macro declares an equivalent Rust type that cannot be
/// instantiated directly but can safely be used as a pointer target.
#[macro_export]
macro_rules! c_ptr
{
@ -13,6 +13,13 @@ macro_rules! c_ptr
$name: ident
} =>
{
pub enum $name {}
#[repr(C)]
pub struct $name { _private: __opaque::Private }
};
}
mod __opaque
{
#[allow(dead_code)]
pub enum Private {}
}

View File

@ -3,54 +3,10 @@
//! This defines the primitive types that may be seen
//! when creating 'C' bindings.
//!
//! There are several places where the target architecture and the OS
//! require special consideration. These are handled
//! with configuration statements.
// Character types.
#[cfg(any(target_os="android", target_os="emscripten",
all(target_os="linux",
any(target_arch="aarch64", target_arch="arm",
target_arch="powerpc", target_arch="powerpc64"))))]
pub type CChar = u8;
#[cfg(not(any(target_os="android", target_os="emscripten",
all(target_os="linux",
any(target_arch="aarch64", target_arch="arm",
target_arch="powerpc", target_arch="powerpc64")))))]
pub type CChar = i8;
pub type CUChar = u8;
// Integer types.
#[cfg(any(target_pointer_width="32", target_os="windows"))]
pub type CLong = i32;
#[cfg(any(target_pointer_width="32", target_os="windows"))]
pub type CULong = u32;
#[cfg(all(target_pointer_width="64", not(target_os="windows")))]
pub type CLong = i32;
#[cfg(all(target_pointer_width="64", not(target_os="windows")))]
pub type CULong = u32;
pub type CShort = i16;
pub type CUShort = u16;
pub type CInt = i32;
pub type CUInt = u32;
pub type CLongLong = i64;
pub type CULongLong = u64;
pub type CFloat = f32;
pub type CDouble = f64;
/// CVoid acts as a 'C' void pointer to pass to functions. **DO NOT**
/// use this as a return type from a 'C' function. If a 'C' function
/// returns void, then use the CReturnVoid type for that.
pub use std::ffi::{c_char as CChar, c_double as CDouble, c_float as CFloat, c_int as CInt, c_long as CLong, c_longlong as CLongLong, c_short as CShort, c_uchar as CUChar, c_uint as CUInt, c_ulong as CULong, c_ulonglong as CULongLong, c_ushort as CUShort, c_void as CVoid, CStr};
// Void types.
/// To return void from a 'C' function it should return an empty tuple ().
@ -58,38 +14,5 @@ pub type CDouble = f64;
/// as an argument to a function. Use the CVoid type for that.
pub type CReturnVoid = ();
/// This acts as a 'C' void pointer to pass to functions. **DO NOT**
/// use this as a return type from a 'C' function. If a 'C' function
/// returns void, then use the CReturnVoid type for that.
#[repr(u8)]
pub enum CVoid
{
#[doc(hidden)]
_Variant,
#[doc(hidden)]
_Variant2
}
// String types.
/*
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
pub struct CString
{
chars: Box<[u8]>
}
#[derive(Hash)]
pub struct CStr
{
inner: [CChar]
}
*/
#[cfg(feature="use_std")]
pub type CStr = ::std::ffi::CStr;
#[cfg(feature="use_std")]
#[cfg(feature = "use_std")]
pub type CString = ::std::ffi::CString;
#[cfg(feature="use_std")]
pub type NullByteError = ::std::ffi::NulError;

View File

@ -6,7 +6,7 @@
//! for use amoungst all of CyberMages LLC's projects.
// Handle using the core or the std of Rust depending on the chosen feature.
#![cfg_attr(not(feature="use_std"), no_std)]
#![cfg_attr(not(feature = "use_std"), no_std)]
// This crate can only use parts of Rust that are in both the core
// and the standard library. This way the logging system will work for
@ -14,14 +14,9 @@
//
// This is handled by coding using the std library and referencing the core
// library as the std library if the core library is desired.
#[cfg(not(feature="use_std"))]
#[cfg(not(feature = "use_std"))]
extern crate core as std;
// Macros to help create bindings to FFI libraries.
mod macros;
// Basic C type macro modules.
mod c_enum;
mod c_flags;
@ -32,13 +27,7 @@ mod c_types;
// Raw platform data retrieval.
mod raw;
#[cfg(feature="use_std")]
pub use self::c_types::{CStr, CString, NullByteError};
pub use self::c_types::{CChar, CUChar};
pub use self::c_types::{CShort, CUShort, CInt, CUInt, CLong, CULong};
pub use self::c_types::{CLongLong, CULongLong, CFloat, CDouble};
pub use self::c_types::{CVoid, CReturnVoid};
pub use self::raw::{AsRaw, AsRawMut, AsRawPtr, AsRawMutPtr, FromRaw, IntoRaw};
#[cfg(feature = "use_std")]
pub use self::c_types::{from_c_string, to_c_string, CString, NullByteError};
pub use self::c_types::{CChar, CDouble, CFloat, CInt, CLong, CLongLong, CReturnVoid, CShort, CStr, CUChar, CUInt, CULong, CULongLong, CUShort, CVoid};
pub use self::raw::{AsRaw, AsRawMut, AsRawMutPtr, AsRawPtr, FromRaw, IntoRaw};

View File

@ -1,74 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
// Sealed with Magistamp.
#[macro_export]
macro_rules! c_library
{
{
$(statics:
{
$($(#[$satter: meta])* $sname: ident: $stype: ty);+;
}
)?
$(functions:
{
$($(#[$fatter: meta])* $fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+;
}
)?
$(varargs:
{
$($(#[$vatter: meta])* $vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+;
}
)?
} =>
{
extern "C"
{
$($($(#[$satter])* pub static $sname: $stype;)+)?
$($($(#[$fatter])* pub fn $fname($($farg: $fargt),*) -> $fret;)+)?
$($($(#[$vatter])* pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)?
}
};
}
#[macro_export]
macro_rules! external_library
{
{
$name: ident: $link: expr =>
{
$(statics:
{
$($(#[$satter: meta])* $sname: ident: $stype: ty);+;
}
)?
$(functions:
{
$($(#[$fatter: meta])* $fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+;
}
)?
$(varargs:
{
$($(#[$vatter: meta])* $vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+;
}
)?
}
} =>
{
#[link(name=$link)]
extern "C"
{
$($($(#[$satter])* pub static $sname: $stype;)+)?
$($($(#[$fatter])* pub fn $fname($($farg: $fargt),*) -> $fret;)+)?
$($($(#[$vatter])* pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)?
}
};
}

View File

@ -9,11 +9,11 @@
//! to help with understanding the code and to remind the programmer
//! where values are coming from.
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data.
pub trait AsRaw<T> where T: Sized
pub trait AsRaw<T>
where T: Sized
{
fn as_raw(&self) -> &T;
}
@ -21,7 +21,8 @@ pub trait AsRaw<T> where T: Sized
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data in a mutable manner.
pub trait AsRawMut<T> where T: Sized
pub trait AsRawMut<T>
where T: Sized
{
fn as_raw_mut(&mut self) -> &mut T;
}
@ -29,7 +30,8 @@ pub trait AsRawMut<T> where T: Sized
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data as a raw const pointer.
pub trait AsRawPtr<T> where T: Sized
pub trait AsRawPtr<T>
where T: Sized
{
fn as_raw_ptr(&self) -> *const T;
}
@ -37,7 +39,8 @@ pub trait AsRawPtr<T> where T: Sized
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data as a raw mutable pointer.
pub trait AsRawMutPtr<T> where T: Sized
pub trait AsRawMutPtr<T>
where T: Sized
{
fn as_raw_mut_ptr(&mut self) -> *mut T;
}