Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cocoa-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 20 additions & 21 deletions cocoa-foundation/src/foundation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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]
}

Expand All @@ -690,18 +689,18 @@ 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;

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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -1615,22 +1614,22 @@ 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;
}
}

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;
}
Expand Down
Loading