Skip to content

Add ns_string! macro#207

Merged
madsmtm merged 21 commits into
masterfrom
static-nsstring
Jul 27, 2022
Merged

Add ns_string! macro#207
madsmtm merged 21 commits into
masterfrom
static-nsstring

Conversation

@madsmtm
Copy link
Copy Markdown
Owner

@madsmtm madsmtm commented Jul 21, 2022

Fixes #53.

Add ns_string! macro to create NSStrings at compile-time. This is an improved version of fruity::ns_string!, credit can be found in first commit.

TODO:

  • Check whether the export names of the statics matter?
    • Investigate if including _unnamed_cfstring_ in the symbol for the CFString will improve debuggability see this
    • I'm pretty sure it doesn't, I think the above usage refers to when doing expr @"some string" in lldb.
  • GNUStep implementation Postponed, I've added a caching impl instead.
  • Investigate if Objective-C image info is required (like it is for static classes and selectors)?
    • I looked through a bit of dyld, lldb, lld and ld64, fairly certain it isn't.
  • Consider if we should put behind feature flag?
    • Only really relevant if we didn't consider this stable, but I think we can (in contrast to the static sel! feature)
  • Find a way to properly test the assembly output of this (symbol mangling is preventing us from this)

@madsmtm madsmtm added enhancement New feature or request A-framework Affects the framework crates and the translator for them labels Jul 21, 2022
@madsmtm madsmtm force-pushed the static-nsstring branch 2 times, most recently from d8da2e8 to c80444b Compare July 22, 2022 01:17
@madsmtm madsmtm force-pushed the static-nsstring branch 3 times, most recently from 0660da0 to bfd9989 Compare July 26, 2022 19:32
madsmtm and others added 19 commits July 26, 2022 21:37
Implementation history can be primarily found in the following three commits:

- nvzqz/fruity@0516282
- nvzqz/fruity@3fbc455
- nvzqz/fruity@868fd65

All credit goes to the following people:

Co-authored-by: Nikolai Vazquez <hello@nikolaivazquez.com>
Co-authored-by: Thom Chiovoloni <chiovolonit@gmail.com>
Co-authored-by: rodrimati1992 <rodrimatt1985@gmail.com>
If the user needs the string to end with e.g. two NUL, we really shouldn't stop them.

`fruity` probably did this originally because their NSString truncated at null bytes, see nvzqz/fruity#14
Panics are now possible in `const fn`
I'm unsure if this is really true; the compile-time cost of using this is potentially quite high, since we have to make the compiler convert UTF-8 to UTF-16!
GNUStep support is definitely possible, just hasn't been implemented yet
@madsmtm madsmtm force-pushed the static-nsstring branch 3 times, most recently from 5c7faf1 to cf86b54 Compare July 26, 2022 22:21
This means we have to remove support for putting string references in statics for now at least
@madsmtm madsmtm merged commit 769ea10 into master Jul 27, 2022
@madsmtm madsmtm deleted the static-nsstring branch July 27, 2022 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-framework Affects the framework crates and the translator for them enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static NSString

1 participant