Skip to content

add unstable-core-ffi-objc feature #761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jbatez
Copy link

@jbatez jbatez commented Jun 7, 2025

For if/when feature(core_ffi_objc) is added to the nightly compiler.
rust-lang/rust@master...jbatez:rust:rustc_objc_class

@jbatez jbatez force-pushed the core_ffi_objc branch 2 times, most recently from 87a792f to 68abe05 Compare June 7, 2025 22:27
Copy link
Owner

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm probably going to wait with merging this until there's at least a rust-lang/rust PR open that we can point people towards.

@madsmtm madsmtm added enhancement New feature or request A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates labels Jun 7, 2025
@jbatez
Copy link
Author

jbatez commented Jun 8, 2025

I added support for the class! macro as well but just realized extern_class! uses __class_inner! directly. Since extern_class! needs to support #[name = "StringLiteral"], that complicates my core::ffi::objc::class! macro which expects an identifier and not a string literal.

I wonder if my core::ffi::objc macros should just take string literals.

@jbatez
Copy link
Author

jbatez commented Jun 9, 2025

I made core::ffi::objc::class! accept either an identifier or a string literal and got it working with extern_class!.

@madsmtm
Copy link
Owner

madsmtm commented Jun 10, 2025

Re identifier vs. string literal: I tend to think the core::ffi::objc::* macros might actually want to only accept string literals for simplicity? Because to the runtime, that is what they are, it is only incidental that Objective-C prevents you from having weird things in them like spaces.

They aren't even limited to UTF-8, so might actually make sense to force c-string literals, to prevent interior NUL bytes by construction?

@jbatez
Copy link
Author

jbatez commented Jun 10, 2025

I'd be ok with string literals only. C-string literals only would make extern_class! #[name = "StringLiteral"] difficult, though, right? I don't know how I'd do that without procedural macros.

@jbatez
Copy link
Author

jbatez commented Jun 10, 2025

#[export_name = ""] and #[link_name = ""] have similar design constraints, fwiw. They disallow interior NUL bytes and I imagine there are platforms out there that support non-Unicode symbols that Rust has no way of handling.

EDIT: Only export_name disallows nulls, but I think the point still stands.

@madsmtm
Copy link
Owner

madsmtm commented Jun 10, 2025

Both good points, then a normal string literal is probably fine.

@jbatez
Copy link
Author

jbatez commented Jun 10, 2025

Done. They now expect string literals and are used in new implementations of __class_inner! and __sel_inner!. Since core::ffi::objc::selector! doesn't expect a null-terminator, I added a new __sel_data_terminate! macro that conditionally null-terminates. It's used in __sel_data! and in common_selectors.rs.

Though now I'm wondering if I should change __sel_inner to never expect null-terminated data and instead have it decide whether or not to add a null-terminator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants