Skip to content

Commit 9f33b12

Browse files
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.
1 parent 42ec061 commit 9f33b12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+302
-322
lines changed

cocoa-foundation/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ default-target = "x86_64-apple-darwin"
1616
[dependencies]
1717
block = "0.1"
1818
bitflags = "2"
19-
libc = "0.2"
2019
core-foundation = { default-features = false, path = "../core-foundation", version = "0.10" }
2120
core-graphics-types = { default-features = false, path = "../core-graphics-types", version = "0.2" }
2221
objc = "0.2.3"

cocoa-foundation/src/foundation.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212
use crate::base::{id, nil, BOOL, NO, SEL};
1313
use bitflags::bitflags;
1414
use block::Block;
15-
use libc;
15+
use core::ffi::{c_char, c_double, c_ulong, c_ulonglong, c_void};
1616
use objc::{class, msg_send, sel, sel_impl};
17-
use std::os::raw::c_void;
1817
use std::ptr;
1918

2019
#[cfg(target_pointer_width = "32")]
21-
pub type NSInteger = libc::c_int;
20+
pub type NSInteger = core::ffi::c_int;
2221
#[cfg(target_pointer_width = "32")]
23-
pub type NSUInteger = libc::c_uint;
22+
pub type NSUInteger = core::ffi::c_uint;
2423

2524
#[cfg(target_pointer_width = "64")]
26-
pub type NSInteger = libc::c_long;
25+
pub type NSInteger = core::ffi::c_long;
2726
#[cfg(target_pointer_width = "64")]
28-
pub type NSUInteger = libc::c_ulong;
27+
pub type NSUInteger = core::ffi::c_ulong;
2928

3029
pub const NSIntegerMax: NSInteger = NSInteger::max_value();
3130
pub const NSNotFound: NSInteger = NSIntegerMax;
@@ -245,7 +244,7 @@ impl NSProcessInfo for id {
245244
}
246245
}
247246

248-
pub type NSTimeInterval = libc::c_double;
247+
pub type NSTimeInterval = c_double;
249248

250249
pub trait NSArray: Sized {
251250
unsafe fn array(_: Self) -> id {
@@ -401,7 +400,7 @@ pub trait NSDictionary: Sized {
401400
unsafe fn fileOwnerAccountID(self) -> id;
402401
unsafe fn fileOwnerAccountName(self) -> id;
403402
unsafe fn filePosixPermissions(self) -> NSUInteger;
404-
unsafe fn fileSize(self) -> libc::c_ulonglong;
403+
unsafe fn fileSize(self) -> c_ulonglong;
405404
unsafe fn fileSystemFileNumber(self) -> NSUInteger;
406405
unsafe fn fileSystemNumber(self) -> NSInteger;
407406
unsafe fn fileType(self) -> id;
@@ -581,7 +580,7 @@ impl NSDictionary for id {
581580
msg_send![self, filePosixPermissions]
582581
}
583582

584-
unsafe fn fileSize(self) -> libc::c_ulonglong {
583+
unsafe fn fileSize(self) -> c_ulonglong {
585584
msg_send![self, fileSize]
586585
}
587586

@@ -616,7 +615,7 @@ impl NSDictionary for id {
616615

617616
bitflags! {
618617
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
619-
pub struct NSEnumerationOptions: libc::c_ulonglong {
618+
pub struct NSEnumerationOptions: c_ulonglong {
620619
const NSEnumerationConcurrent = 1 << 0;
621620
const NSEnumerationReverse = 1 << 1;
622621
}
@@ -639,7 +638,7 @@ pub trait NSString: Sized {
639638

640639
unsafe fn stringByAppendingString_(self, other: id) -> id;
641640
unsafe fn init_str(self, string: &str) -> Self;
642-
unsafe fn UTF8String(self) -> *const libc::c_char;
641+
unsafe fn UTF8String(self) -> *const c_char;
643642
unsafe fn len(self) -> usize;
644643
unsafe fn isEqualToString(self, string: &str) -> bool;
645644
unsafe fn substringWithRange(self, range: NSRange) -> id;
@@ -667,7 +666,7 @@ impl NSString for id {
667666
msg_send![self, lengthOfBytesUsingEncoding: UTF8_ENCODING]
668667
}
669668

670-
unsafe fn UTF8String(self) -> *const libc::c_char {
669+
unsafe fn UTF8String(self) -> *const c_char {
671670
msg_send![self, UTF8String]
672671
}
673672

@@ -690,18 +689,18 @@ impl NSDate for id {}
690689

691690
#[repr(C)]
692691
struct NSFastEnumerationState {
693-
pub state: libc::c_ulong,
692+
pub state: c_ulong,
694693
pub items_ptr: *mut id,
695-
pub mutations_ptr: *mut libc::c_ulong,
696-
pub extra: [libc::c_ulong; 5],
694+
pub mutations_ptr: *mut c_ulong,
695+
pub extra: [c_ulong; 5],
697696
}
698697

699698
const NS_FAST_ENUM_BUF_SIZE: usize = 16;
700699

701700
pub struct NSFastIterator {
702701
state: NSFastEnumerationState,
703702
buffer: [id; NS_FAST_ENUM_BUF_SIZE],
704-
mut_val: Option<libc::c_ulong>,
703+
mut_val: Option<c_ulong>,
705704
len: usize,
706705
idx: usize,
707706
object: id,
@@ -1596,7 +1595,7 @@ impl NSData for id {
15961595

15971596
bitflags! {
15981597
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1599-
pub struct NSDataReadingOptions: libc::c_ulonglong {
1598+
pub struct NSDataReadingOptions: c_ulonglong {
16001599
const NSDataReadingMappedIfSafe = 1 << 0;
16011600
const NSDataReadingUncached = 1 << 1;
16021601
const NSDataReadingMappedAlways = 1 << 3;
@@ -1605,7 +1604,7 @@ bitflags! {
16051604

16061605
bitflags! {
16071606
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1608-
pub struct NSDataBase64EncodingOptions: libc::c_ulonglong {
1607+
pub struct NSDataBase64EncodingOptions: c_ulonglong {
16091608
const NSDataBase64Encoding64CharacterLineLength = 1 << 0;
16101609
const NSDataBase64Encoding76CharacterLineLength = 1 << 1;
16111610
const NSDataBase64EncodingEndLineWithCarriageReturn = 1 << 4;
@@ -1615,22 +1614,22 @@ bitflags! {
16151614

16161615
bitflags! {
16171616
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1618-
pub struct NSDataBase64DecodingOptions: libc::c_ulonglong {
1617+
pub struct NSDataBase64DecodingOptions: c_ulonglong {
16191618
const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0;
16201619
}
16211620
}
16221621

16231622
bitflags! {
16241623
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1625-
pub struct NSDataWritingOptions: libc::c_ulonglong {
1624+
pub struct NSDataWritingOptions: c_ulonglong {
16261625
const NSDataWritingAtomic = 1 << 0;
16271626
const NSDataWritingWithoutOverwriting = 1 << 1;
16281627
}
16291628
}
16301629

16311630
bitflags! {
16321631
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1633-
pub struct NSDataSearchOptions: libc::c_ulonglong {
1632+
pub struct NSDataSearchOptions: c_ulonglong {
16341633
const NSDataSearchBackwards = 1 << 0;
16351634
const NSDataSearchAnchored = 1 << 1;
16361635
}

0 commit comments

Comments
 (0)