Use core::ffi over std::os::raw and libc::c_* (#692)

`core::ffi` is the preferred way to access these type definitions.
Begin removing uses of the versions from `libc`.

`libc::c_void` is not exactly the same as `core::ffi::c_void` but
some code has tried using them interchangeably (like in io-surface).

`libc::size_t` is `usize` on all current platforms.
This commit is contained in:
Bruce Mitchener
2024-08-12 03:24:22 +07:00
committed by GitHub
parent 42ec06106d
commit 9f33b121fb
75 changed files with 302 additions and 322 deletions
-1
View File
@@ -16,7 +16,6 @@ default-target = "x86_64-apple-darwin"
[dependencies]
block = "0.1"
bitflags = "2"
libc = "0.2"
core-foundation = { default-features = false, path = "../core-foundation", version = "0.10" }
core-graphics-types = { default-features = false, path = "../core-graphics-types", version = "0.2" }
objc = "0.2.3"
+20 -21
View File
@@ -12,20 +12,19 @@
use crate::base::{id, nil, BOOL, NO, SEL};
use bitflags::bitflags;
use block::Block;
use libc;
use core::ffi::{c_char, c_double, c_ulong, c_ulonglong, c_void};
use objc::{class, msg_send, sel, sel_impl};
use std::os::raw::c_void;
use std::ptr;
#[cfg(target_pointer_width = "32")]
pub type NSInteger = libc::c_int;
pub type NSInteger = core::ffi::c_int;
#[cfg(target_pointer_width = "32")]
pub type NSUInteger = libc::c_uint;
pub type NSUInteger = core::ffi::c_uint;
#[cfg(target_pointer_width = "64")]
pub type NSInteger = libc::c_long;
pub type NSInteger = core::ffi::c_long;
#[cfg(target_pointer_width = "64")]
pub type NSUInteger = libc::c_ulong;
pub type NSUInteger = core::ffi::c_ulong;
pub const NSIntegerMax: NSInteger = NSInteger::max_value();
pub const NSNotFound: NSInteger = NSIntegerMax;
@@ -245,7 +244,7 @@ impl NSProcessInfo for id {
}
}
pub type NSTimeInterval = libc::c_double;
pub type NSTimeInterval = c_double;
pub trait NSArray: Sized {
unsafe fn array(_: Self) -> id {
@@ -401,7 +400,7 @@ pub trait NSDictionary: Sized {
unsafe fn fileOwnerAccountID(self) -> id;
unsafe fn fileOwnerAccountName(self) -> id;
unsafe fn filePosixPermissions(self) -> NSUInteger;
unsafe fn fileSize(self) -> libc::c_ulonglong;
unsafe fn fileSize(self) -> c_ulonglong;
unsafe fn fileSystemFileNumber(self) -> NSUInteger;
unsafe fn fileSystemNumber(self) -> NSInteger;
unsafe fn fileType(self) -> id;
@@ -581,7 +580,7 @@ impl NSDictionary for id {
msg_send![self, filePosixPermissions]
}
unsafe fn fileSize(self) -> libc::c_ulonglong {
unsafe fn fileSize(self) -> c_ulonglong {
msg_send![self, fileSize]
}
@@ -616,7 +615,7 @@ impl NSDictionary for id {
bitflags! {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NSEnumerationOptions: libc::c_ulonglong {
pub struct NSEnumerationOptions: c_ulonglong {
const NSEnumerationConcurrent = 1 << 0;
const NSEnumerationReverse = 1 << 1;
}
@@ -639,7 +638,7 @@ pub trait NSString: Sized {
unsafe fn stringByAppendingString_(self, other: id) -> id;
unsafe fn init_str(self, string: &str) -> Self;
unsafe fn UTF8String(self) -> *const libc::c_char;
unsafe fn UTF8String(self) -> *const c_char;
unsafe fn len(self) -> usize;
unsafe fn isEqualToString(self, string: &str) -> bool;
unsafe fn substringWithRange(self, range: NSRange) -> id;
@@ -667,7 +666,7 @@ impl NSString for id {
msg_send![self, lengthOfBytesUsingEncoding: UTF8_ENCODING]
}
unsafe fn UTF8String(self) -> *const libc::c_char {
unsafe fn UTF8String(self) -> *const c_char {
msg_send![self, UTF8String]
}
@@ -690,10 +689,10 @@ impl NSDate for id {}
#[repr(C)]
struct NSFastEnumerationState {
pub state: libc::c_ulong,
pub state: c_ulong,
pub items_ptr: *mut id,
pub mutations_ptr: *mut libc::c_ulong,
pub extra: [libc::c_ulong; 5],
pub mutations_ptr: *mut c_ulong,
pub extra: [c_ulong; 5],
}
const NS_FAST_ENUM_BUF_SIZE: usize = 16;
@@ -701,7 +700,7 @@ const NS_FAST_ENUM_BUF_SIZE: usize = 16;
pub struct NSFastIterator {
state: NSFastEnumerationState,
buffer: [id; NS_FAST_ENUM_BUF_SIZE],
mut_val: Option<libc::c_ulong>,
mut_val: Option<c_ulong>,
len: usize,
idx: usize,
object: id,
@@ -1596,7 +1595,7 @@ impl NSData for id {
bitflags! {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NSDataReadingOptions: libc::c_ulonglong {
pub struct NSDataReadingOptions: c_ulonglong {
const NSDataReadingMappedIfSafe = 1 << 0;
const NSDataReadingUncached = 1 << 1;
const NSDataReadingMappedAlways = 1 << 3;
@@ -1605,7 +1604,7 @@ bitflags! {
bitflags! {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NSDataBase64EncodingOptions: libc::c_ulonglong {
pub struct NSDataBase64EncodingOptions: c_ulonglong {
const NSDataBase64Encoding64CharacterLineLength = 1 << 0;
const NSDataBase64Encoding76CharacterLineLength = 1 << 1;
const NSDataBase64EncodingEndLineWithCarriageReturn = 1 << 4;
@@ -1615,14 +1614,14 @@ bitflags! {
bitflags! {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NSDataBase64DecodingOptions: libc::c_ulonglong {
pub struct NSDataBase64DecodingOptions: c_ulonglong {
const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0;
}
}
bitflags! {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NSDataWritingOptions: libc::c_ulonglong {
pub struct NSDataWritingOptions: c_ulonglong {
const NSDataWritingAtomic = 1 << 0;
const NSDataWritingWithoutOverwriting = 1 << 1;
}
@@ -1630,7 +1629,7 @@ bitflags! {
bitflags! {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NSDataSearchOptions: libc::c_ulonglong {
pub struct NSDataSearchOptions: c_ulonglong {
const NSDataSearchBackwards = 1 << 0;
const NSDataSearchAnchored = 1 << 1;
}