Skip to content
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

Convert ptr, count arguments into slice pointers #610

Open
madsmtm opened this issue May 1, 2024 · 0 comments
Open

Convert ptr, count arguments into slice pointers #610

madsmtm opened this issue May 1, 2024 · 0 comments
Labels
A-framework Affects the framework crates and the translator for them enhancement New feature or request

Comments

@madsmtm
Copy link
Owner

madsmtm commented May 1, 2024

Convert things like:

#[method_id(initWithObjects:count:)]
pub unsafe fn initWithObjects_count(
    this: Allocated<Self>,
    objects: *mut NonNull<ObjectType>,
    cnt: NSUInteger,
) -> Id<Self>;

#[method_id(colorWithColorSpace:components:count:)]
pub unsafe fn colorWithColorSpace_components_count(
    space: &NSColorSpace,
    components: NonNull<CGFloat>,
    number_of_components: NSInteger,
) -> Id<NSColor>;

Into:

pub unsafe fn initWithObjects(
    this: Allocated<Self>,
    objects: *mut [NonNull<ObjectType>],
) -> Id<Self>;

pub unsafe fn colorWithColorSpace_components(
    space: &NSColorSpace,
    components: NonNull<[CGFloat]>,
) -> Id<NSColor>;

That is, methods that have a pointer argument and uses count: with a NSInteger/NSUInteger should instead allow passing a slice pointer, and then we extract the count automatically.

This probably requires that we output a shim for the method manually, as doing this kind of rewriting purely in the type-system is very difficult.

Unsure how this should work in declare_class!? Maybe we do need to integrate it into the type-system? Maybe we need a special attribute that says where the count should go?

@madsmtm madsmtm added enhancement New feature or request A-framework Affects the framework crates and the translator for them labels May 1, 2024
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

No branches or pull requests

1 participant