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

Support error return and out parameters in define_class! #283

Open
madsmtm opened this issue Nov 3, 2022 · 0 comments
Open

Support error return and out parameters in define_class! #283

madsmtm opened this issue Nov 3, 2022 · 0 comments
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates enhancement New feature or request

Comments

@madsmtm
Copy link
Owner

madsmtm commented Nov 3, 2022

Add the equivalent of #276 and #277 to define_class!.

Effectively the implementation is:

// Result<(), Retained<NSError, Shared>> -> Bool
match res {
    Ok(()) => Bool::YES,
    Err(err) => {
        // Intentionally not objc_autoreleaseReturnValue, since the optimization that enables will not be able to kick in
        *__err_param = objc_autorelease(err);
        Bool::NO
    },
}

// Result<Retained<T, O>, Retained<NSError, Shared>> -> *mut T
match res {
    Ok(obj) => obj.release_according_to_memory_management_rules(sel), // See #282
    Err(err) => {
        // Intentionally not objc_autoreleaseReturnValue
        *__err_param = objc_autorelease(err);
        ptr::null_mut()
    },
}

See #277 (comment) for further ABI details.

@madsmtm madsmtm added enhancement New feature or request A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates labels Nov 3, 2022
This was referenced Nov 3, 2022
@madsmtm madsmtm added this to the objc2 v0.3 milestone Jan 27, 2023
@madsmtm madsmtm changed the title Support error return in declare_class! Support error return and out parameters in declare_class! Jan 31, 2023
@madsmtm madsmtm modified the milestones: objc2 v0.3, icrate v0.2.0 Jan 31, 2023
@madsmtm madsmtm added this to the icrate v0.2.0 milestone May 26, 2023
@madsmtm madsmtm modified the milestones: Polish icrate, Usable icrate Sep 5, 2023
@madsmtm madsmtm modified the milestones: Usable icrate, Polish icrate Dec 3, 2023
@madsmtm madsmtm changed the title Support error return and out parameters in declare_class! Support error return and out parameters in define_class! Nov 26, 2024
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

No branches or pull requests

1 participant