diff --git a/Cargo.toml b/Cargo.toml index d4636068e..619bd3815 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,9 @@ exclude = [ exception = ["objc_exception"] verify_message = [] -[dependencies] -malloc_buf = "0.0" +[dependencies.mbox] +version = "0.5" +default_features = false [dependencies.objc_exception] version = "0.1" diff --git a/src/encode.rs b/src/encode.rs index 921479da9..b1a70e2ba 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -2,7 +2,7 @@ use std::ffi::CStr; use std::fmt; use std::os::raw::{c_char, c_void}; use std::str; -use malloc_buf::MallocBuffer; +use mbox::MBox; use runtime::{Class, Object, Sel}; @@ -26,7 +26,7 @@ enum Code { Slice(&'static str), Owned(String), Inline(u8, [u8; CODE_INLINE_CAP]), - Malloc(MallocBuffer) + Malloc(MBox<[u8]>) } /// An Objective-C type encoding. @@ -104,7 +104,7 @@ pub unsafe fn from_malloc_str(ptr: *mut c_char) -> Encoding { let s = CStr::from_ptr(ptr); let bytes = s.to_bytes_with_nul(); assert!(str::from_utf8(bytes).is_ok()); - let buf = MallocBuffer::new(ptr as *mut u8, bytes.len()).unwrap(); + let buf = MBox::from_raw_parts(ptr as *mut u8, bytes.len()); Encoding { code: Code::Malloc(buf) } } diff --git a/src/lib.rs b/src/lib.rs index cdd30f5fd..e88d15f86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,7 @@ The bindings can be used on Linux or *BSD utilizing the #![warn(missing_docs)] -extern crate malloc_buf; +extern crate mbox; #[cfg(feature = "exception")] extern crate objc_exception; diff --git a/src/runtime.rs b/src/runtime.rs index 3b533efe6..5fc8cb4b0 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -8,7 +8,7 @@ use std::fmt; use std::os::raw::{c_char, c_int, c_uint, c_void}; use std::ptr; use std::str; -use malloc_buf::MallocBuffer; +use mbox::MBox; use encode; use {Encode, Encoding}; @@ -284,11 +284,11 @@ impl Class { } /// Obtains the list of registered class definitions. - pub fn classes() -> MallocBuffer<&'static Class> { + pub fn classes() -> MBox<[&'static Class]> { unsafe { let mut count: c_uint = 0; let classes = objc_copyClassList(&mut count); - MallocBuffer::new(classes as *mut _, count as usize).unwrap() + MBox::from_raw_parts(classes as *mut _, count as usize) } } @@ -351,11 +351,11 @@ impl Class { } /// Describes the instance methods implemented by self. - pub fn instance_methods(&self) -> MallocBuffer<&Method> { + pub fn instance_methods(&self) -> MBox<[&Method]> { unsafe { let mut count: c_uint = 0; let methods = class_copyMethodList(self, &mut count); - MallocBuffer::new(methods as *mut _, count as usize).unwrap() + MBox::from_raw_parts(methods as *mut _, count as usize) } } @@ -366,20 +366,20 @@ impl Class { } /// Get a list of the protocols to which this class conforms. - pub fn adopted_protocols(&self) -> MallocBuffer<&Protocol> { + pub fn adopted_protocols(&self) -> MBox<[&Protocol]> { unsafe { let mut count: c_uint = 0; let protos = class_copyProtocolList(self, &mut count); - MallocBuffer::new(protos as *mut _, count as usize).unwrap() + MBox::from_raw_parts(protos as *mut _, count as usize) } } /// Describes the instance variables declared by self. - pub fn instance_variables(&self) -> MallocBuffer<&Ivar> { + pub fn instance_variables(&self) -> MBox<[&Ivar]> { unsafe { let mut count: c_uint = 0; let ivars = class_copyIvarList(self, &mut count); - MallocBuffer::new(ivars as *mut _, count as usize).unwrap() + MBox::from_raw_parts(ivars as *mut _, count as usize) } } } @@ -412,20 +412,20 @@ impl Protocol { } /// Obtains the list of registered protocol definitions. - pub fn protocols() -> MallocBuffer<&'static Protocol> { + pub fn protocols() -> MBox<[&'static Protocol]> { unsafe { let mut count: c_uint = 0; let protocols = objc_copyProtocolList(&mut count); - MallocBuffer::new(protocols as *mut _, count as usize).unwrap() + MBox::from_raw_parts(protocols as *mut _, count as usize) } } /// Get a list of the protocols to which this protocol conforms. - pub fn adopted_protocols(&self) -> MallocBuffer<&Protocol> { + pub fn adopted_protocols(&self) -> MBox<[&Protocol]> { unsafe { let mut count: c_uint = 0; let protocols = protocol_copyProtocolList(self, &mut count); - MallocBuffer::new(protocols as *mut _, count as usize).unwrap() + MBox::from_raw_parts(protocols as *mut _, count as usize) } }