Skip to content

Commit dee2e48

Browse files
committed
Removed libc dependency from objc by using std::os::raw types.
1 parent e9577ae commit dee2e48

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ exception = ["objc_exception"]
1717
verify_message = []
1818

1919
[dependencies]
20-
libc = ">= 0.1, < 0.3"
2120
malloc_buf = "0.0"
2221

2322
[dependencies.objc_exception]

src/declare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use std::error::Error;
3838
use std::ffi::CString;
3939
use std::fmt;
4040
use std::mem;
41-
use libc::size_t;
4241

4342
use {Encode, Encoding, Message};
4443
use runtime::{Class, Imp, NO, Object, Sel, self};
@@ -204,7 +203,7 @@ impl ClassDecl {
204203
pub fn add_ivar<T>(&mut self, name: &str) where T: Encode {
205204
let c_name = CString::new(name).unwrap();
206205
let encoding = CString::new(T::encode().as_str()).unwrap();
207-
let size = mem::size_of::<T>() as size_t;
206+
let size = mem::size_of::<T>();
208207
let align = mem::align_of::<T>() as u8;
209208
let success = unsafe {
210209
runtime::class_addIvar(self.cls, c_name.as_ptr(), size, align,

src/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::CStr;
22
use std::fmt;
3+
use std::os::raw::{c_char, c_void};
34
use std::str;
4-
use libc::{c_char, c_void};
55
use malloc_buf::MallocBuffer;
66

77
use runtime::{Class, Object, Sel};

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ preventing Objective-C from unwinding into Rust.
3939

4040
#![warn(missing_docs)]
4141

42-
extern crate libc;
4342
extern crate malloc_buf;
4443
#[cfg(feature = "exception")]
4544
extern crate objc_exception;

src/runtime.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
66
use std::ffi::{CStr, CString};
77
use std::fmt;
8+
use std::os::raw::{c_char, c_int, c_uint, c_void};
89
use std::ptr;
910
use std::str;
10-
use libc::{c_char, c_int, c_uint, c_void, ptrdiff_t, size_t};
1111
use malloc_buf::MallocBuffer;
1212

1313
use encode;
@@ -17,7 +17,7 @@ use {Encode, Encoding};
1717
///
1818
/// To convert an Objective-C `BOOL` into a Rust `bool`, compare it with `NO`.
1919
#[cfg(not(target_arch = "aarch64"))]
20-
pub type BOOL = ::libc::c_schar;
20+
pub type BOOL = ::std::os::raw::c_schar;
2121
/// The equivalent of true for Objective-C's `BOOL` type.
2222
#[cfg(not(target_arch = "aarch64"))]
2323
pub const YES: BOOL = 1;
@@ -85,15 +85,15 @@ extern {
8585

8686
pub fn class_getName(cls: *const Class) -> *const c_char;
8787
pub fn class_getSuperclass(cls: *const Class) -> *const Class;
88-
pub fn class_getInstanceSize(cls: *const Class) -> size_t;
88+
pub fn class_getInstanceSize(cls: *const Class) -> usize;
8989
pub fn class_getInstanceMethod(cls: *const Class, sel: Sel) -> *const Method;
9090
pub fn class_getInstanceVariable(cls: *const Class, name: *const c_char) -> *const Ivar;
9191
pub fn class_copyMethodList(cls: *const Class, outCount: *mut c_uint) -> *mut *const Method;
9292
pub fn class_copyIvarList(cls: *const Class, outCount: *mut c_uint) -> *mut *const Ivar;
9393
pub fn class_addMethod(cls: *mut Class, name: Sel, imp: Imp, types: *const c_char) -> BOOL;
94-
pub fn class_addIvar(cls: *mut Class, name: *const c_char, size: size_t, alignment: u8, types: *const c_char) -> BOOL;
94+
pub fn class_addIvar(cls: *mut Class, name: *const c_char, size: usize, alignment: u8, types: *const c_char) -> BOOL;
9595

96-
pub fn objc_allocateClassPair(superclass: *const Class, name: *const c_char, extraBytes: size_t) -> *mut Class;
96+
pub fn objc_allocateClassPair(superclass: *const Class, name: *const c_char, extraBytes: usize) -> *mut Class;
9797
pub fn objc_disposeClassPair(cls: *mut Class);
9898
pub fn objc_registerClassPair(cls: *mut Class);
9999

@@ -104,7 +104,7 @@ extern {
104104
pub fn objc_getClass(name: *const c_char) -> *const Class;
105105

106106
pub fn ivar_getName(ivar: *const Ivar) -> *const c_char;
107-
pub fn ivar_getOffset(ivar: *const Ivar) -> ptrdiff_t;
107+
pub fn ivar_getOffset(ivar: *const Ivar) -> isize;
108108
pub fn ivar_getTypeEncoding(ivar: *const Ivar) -> *const c_char;
109109

110110
pub fn objc_msgSend(obj: *mut Object, op: Sel, ...) -> *mut Object;

0 commit comments

Comments
 (0)