Skip to content

Commit 702d358

Browse files
committed
Add note about ns_string! macro instability
1 parent 7f7bca1 commit 702d358

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

objc2/src/foundation/__ns_string.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
//! generating a pure `NSString`. We don't support that yet (since I don't
1010
//! know the use-case), but we definitely could!
1111
//! See: <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CGObjCMac.cpp#L2007-L2068>
12+
//!
13+
//! See also the following crates that implement UTF-16 conversion:
14+
//! `utf16_lit`, `windows`, `const_utf16`, `wide-literals`, ...
1215
use core::ffi::c_void;
1316
use core::mem::ManuallyDrop;
1417
use core::ptr;
@@ -238,6 +241,12 @@ impl CachedNSString {
238241

239242
/// Creates an [`NSString`][`crate::foundation::NSString`] from a static string.
240243
///
244+
/// Note: This works by placing statics in special sections, which may not
245+
/// work completely reliably yet, see [#258]; until then, you should be
246+
/// careful about using this in libraries intended for others to consume.
247+
///
248+
/// [#258]: https://github.com/madsmtm/objc2/issues/258
249+
///
241250
///
242251
/// # Examples
243252
///

objc2/src/foundation/bundle.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
33

44
use super::{NSCopying, NSDictionary, NSObject, NSString};
55
use crate::rc::{Id, Shared};
6-
use crate::{extern_class, extern_methods, msg_send_id, ns_string, ClassType};
6+
use crate::{extern_class, extern_methods, msg_send_id, ClassType};
77

88
extern_class!(
99
/// A representation of the code and resources stored in a bundle
@@ -36,13 +36,16 @@ extern_methods!(
3636
}
3737

3838
pub fn name(&self) -> Option<Id<NSString, Shared>> {
39-
self.info().get(ns_string!("CFBundleName")).map(|name| {
40-
let ptr: *const NSObject = name;
41-
let ptr: *const NSString = ptr.cast();
42-
// SAFETY: TODO
43-
let name = unsafe { ptr.as_ref().unwrap_unchecked() };
44-
name.copy()
45-
})
39+
// TODO: Use ns_string!
40+
self.info()
41+
.get(&NSString::from_str("CFBundleName"))
42+
.map(|name| {
43+
let ptr: *const NSObject = name;
44+
let ptr: *const NSString = ptr.cast();
45+
// SAFETY: TODO
46+
let name = unsafe { ptr.as_ref().unwrap_unchecked() };
47+
name.copy()
48+
})
4649
}
4750
}
4851
);

0 commit comments

Comments
 (0)