9
9
//! generating a pure `NSString`. We don't support that yet (since I don't
10
10
//! know the use-case), but we definitely could!
11
11
//! See: <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CGObjCMac.cpp#L2007-L2068>
12
+ use core:: ffi:: c_void;
12
13
13
14
use objc2:: runtime:: Class ;
14
15
@@ -35,50 +36,32 @@ const FLAGS_ASCII: usize = 0x07_C8;
35
36
const FLAGS_UTF16 : usize = 0x07_D0 ;
36
37
37
38
#[ repr( C ) ]
38
- pub struct CFStringAscii {
39
+ pub struct CFConstString {
39
40
isa : & ' static Class ,
40
41
flags : usize ,
41
- data : * const u8 ,
42
+ data : * const c_void ,
42
43
len : usize ,
43
44
}
44
45
45
46
// Required to place in a `static`.
46
- unsafe impl Sync for CFStringAscii { }
47
+ unsafe impl Sync for CFConstString { }
47
48
48
- impl CFStringAscii {
49
- pub const unsafe fn new ( isa : & ' static Class , data : & ' static [ u8 ] ) -> Self {
49
+ impl CFConstString {
50
+ pub const unsafe fn new_ascii ( isa : & ' static Class , data : & ' static [ u8 ] ) -> Self {
50
51
Self {
51
52
isa,
52
53
flags : FLAGS_ASCII ,
53
- data : data. as_ptr ( ) ,
54
+ data : data. as_ptr ( ) . cast ( ) ,
54
55
// The length does not include the trailing NUL.
55
56
len : data. len ( ) - 1 ,
56
57
}
57
58
}
58
59
59
- #[ inline]
60
- pub const fn as_nsstring ( & self ) -> & NSString {
61
- unsafe { & * ( self as * const Self as * const NSString ) }
62
- }
63
- }
64
-
65
- #[ repr( C ) ]
66
- pub struct CFStringUtf16 {
67
- isa : & ' static Class ,
68
- flags : usize ,
69
- data : * const u16 ,
70
- len : usize ,
71
- }
72
-
73
- // Required to place in a `static`.
74
- unsafe impl Sync for CFStringUtf16 { }
75
-
76
- impl CFStringUtf16 {
77
- pub const unsafe fn new ( isa : & ' static Class , data : & ' static [ u16 ] ) -> Self {
60
+ pub const unsafe fn new_utf16 ( isa : & ' static Class , data : & ' static [ u16 ] ) -> Self {
78
61
Self {
79
62
isa,
80
63
flags : FLAGS_UTF16 ,
81
- data : data. as_ptr ( ) ,
64
+ data : data. as_ptr ( ) . cast ( ) ,
82
65
// The length does not include the trailing NUL.
83
66
len : data. len ( ) - 1 ,
84
67
}
@@ -304,8 +287,8 @@ macro_rules! ns_string {
304
287
} ;
305
288
306
289
#[ link_section = "__DATA,__cfstring" ]
307
- static CFSTRING : $crate:: __string_macro:: CFStringAscii = unsafe {
308
- $crate:: __string_macro:: CFStringAscii :: new (
290
+ static CFSTRING : $crate:: __string_macro:: CFConstString = unsafe {
291
+ $crate:: __string_macro:: CFConstString :: new_ascii (
309
292
& $crate:: __string_macro:: __CFConstantStringClassReference,
310
293
& ASCII ,
311
294
)
@@ -353,8 +336,8 @@ macro_rules! ns_string {
353
336
} ;
354
337
355
338
#[ link_section = "__DATA,__cfstring" ]
356
- static CFSTRING : $crate:: __string_macro:: CFStringUtf16 = unsafe {
357
- $crate:: __string_macro:: CFStringUtf16 :: new (
339
+ static CFSTRING : $crate:: __string_macro:: CFConstString = unsafe {
340
+ $crate:: __string_macro:: CFConstString :: new_utf16 (
358
341
& $crate:: __string_macro:: __CFConstantStringClassReference,
359
342
& UTF16 ,
360
343
)
0 commit comments