Skip to content

Commit 8ae8c07

Browse files
committed
Tweak some type annotations for better verification.
1 parent 0c157a5 commit 8ae8c07

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

src/array.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::cmp::Ordering;
22
use std::marker::PhantomData;
33
use std::ops::{Index, Range};
4+
use std::os::raw::c_void;
45

56
use objc::runtime::{Class, Object};
67
use objc_id::{Id, Owned, Ownership, Shared, ShareId};
@@ -264,9 +265,11 @@ pub trait INSMutableArray : INSArray {
264265
let f: extern fn(&Self::Item, &Self::Item, &mut F) -> NSComparisonResult =
265266
compare_with_closure;
266267
let mut closure = compare;
268+
let closure_ptr: *mut F = &mut closure;
269+
let context = closure_ptr as *mut c_void;
267270
unsafe {
268271
let _: () = msg_send![self, sortUsingFunction:f
269-
context:&mut closure];
272+
context:context];
270273
}
271274
}
272275
}

src/data.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ pub trait INSData : INSObject {
2929

3030
fn with_bytes(bytes: &[u8]) -> Id<Self> {
3131
let cls = Self::class();
32+
let bytes_ptr = bytes.as_ptr() as *const c_void;
3233
unsafe {
3334
let obj: *mut Self = msg_send![cls, alloc];
34-
let obj: *mut Self = msg_send![obj, initWithBytes:bytes.as_ptr()
35+
let obj: *mut Self = msg_send![obj, initWithBytes:bytes_ptr
3536
length:bytes.len()];
3637
Id::from_retained_ptr(obj)
3738
}
@@ -47,10 +48,11 @@ pub trait INSData : INSObject {
4748
let dealloc: &Block<(*mut c_void, usize), ()> = &dealloc;
4849

4950
let mut bytes = bytes;
51+
let bytes_ptr = bytes.as_mut_ptr() as *mut c_void;
5052
let cls = Self::class();
5153
unsafe {
5254
let obj: *mut Self = msg_send![cls, alloc];
53-
let obj: *mut Self = msg_send![obj, initWithBytesNoCopy:bytes.as_mut_ptr()
55+
let obj: *mut Self = msg_send![obj, initWithBytesNoCopy:bytes_ptr
5456
length:bytes.len()
5557
deallocator:dealloc];
5658
mem::forget(bytes);
@@ -92,17 +94,19 @@ pub trait INSMutableData : INSData {
9294
}
9395

9496
fn append(&mut self, bytes: &[u8]) {
97+
let bytes_ptr = bytes.as_ptr() as *const c_void;
9598
unsafe {
96-
let _: () = msg_send![self, appendBytes:bytes.as_ptr()
99+
let _: () = msg_send![self, appendBytes:bytes_ptr
97100
length:bytes.len()];
98101
}
99102
}
100103

101104
fn replace_range(&mut self, range: Range<usize>, bytes: &[u8]) {
102105
let range = NSRange::from_range(range);
106+
let bytes_ptr = bytes.as_ptr() as *const c_void;
103107
unsafe {
104108
let _: () = msg_send![self, replaceBytesInRange:range
105-
withBytes:bytes.as_ptr()
109+
withBytes:bytes_ptr
106110
length:bytes.len()];
107111
}
108112
}

src/dictionary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait INSDictionary : INSObject {
4444
let len = self.count();
4545
let mut keys = Vec::with_capacity(len);
4646
unsafe {
47-
let _: () = msg_send![self, getObjects:ptr::null_mut::<Self::Value>()
47+
let _: () = msg_send![self, getObjects:ptr::null_mut::<&Self::Value>()
4848
andKeys:keys.as_mut_ptr()];
4949
keys.set_len(len);
5050
}
@@ -56,7 +56,7 @@ pub trait INSDictionary : INSObject {
5656
let mut vals = Vec::with_capacity(len);
5757
unsafe {
5858
let _: () = msg_send![self, getObjects:vals.as_mut_ptr()
59-
andKeys:ptr::null_mut::<Self::Key>()];
59+
andKeys:ptr::null_mut::<&Self::Key>()];
6060
vals.set_len(len);
6161
}
6262
vals

src/string.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os::raw::c_char;
1+
use std::os::raw::{c_char, c_void};
22
use std::slice;
33
use std::str;
44

@@ -51,9 +51,10 @@ pub trait INSString : INSObject {
5151

5252
fn from_str(string: &str) -> Id<Self> {
5353
let cls = Self::class();
54+
let bytes = string.as_ptr() as *const c_void;
5455
unsafe {
5556
let obj: *mut Self = msg_send![cls, alloc];
56-
let obj: *mut Self = msg_send![obj, initWithBytes:string.as_ptr()
57+
let obj: *mut Self = msg_send![obj, initWithBytes:bytes
5758
length:string.len()
5859
encoding:UTF8_ENCODING];
5960
Id::from_retained_ptr(obj)

src/value.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::Any;
22
use std::ffi::{CStr, CString};
33
use std::marker::PhantomData;
44
use std::mem;
5-
use std::os::raw::c_char;
5+
use std::os::raw::{c_char, c_void};
66
use std::str;
77

88
use objc::{Encode, Encoding};
@@ -18,7 +18,9 @@ pub trait INSValue : INSObject {
1818
assert!(Self::Value::encode() == self.encoding());
1919
unsafe {
2020
let mut value = mem::uninitialized::<Self::Value>();
21-
let _: () = msg_send![self, getValue:&mut value];
21+
let value_ptr: *mut Self::Value = &mut value;
22+
let bytes = value_ptr as *mut c_void;
23+
let _: () = msg_send![self, getValue:bytes];
2224
value
2325
}
2426
}
@@ -34,10 +36,12 @@ pub trait INSValue : INSObject {
3436

3537
fn from_value(value: Self::Value) -> Id<Self> {
3638
let cls = Self::class();
39+
let value_ptr: *const Self::Value = &value;
40+
let bytes = value_ptr as *const c_void;
3741
let encoding = CString::new(Self::Value::encode().as_str()).unwrap();
3842
unsafe {
3943
let obj: *mut Self = msg_send![cls, alloc];
40-
let obj: *mut Self = msg_send![obj, initWithBytes:&value
44+
let obj: *mut Self = msg_send![obj, initWithBytes:bytes
4145
objCType:encoding.as_ptr()];
4246
Id::from_retained_ptr(obj)
4347
}

0 commit comments

Comments
 (0)