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

Enable savvy-cli to handle duplicated definitions #334

Merged
merged 23 commits into from
Jan 11, 2025

Conversation

yutannihilation
Copy link
Owner

Close #333

Users might use #[cfg()] to switch implementations on the same function. However, from the viewpoint of savvy-cli, who cannot evaluate #[cfg()], these are just duplicated definitions. This pull request enables the cli to ignore the duplication to generate the proper C & R bindings.

@yutannihilation yutannihilation marked this pull request as ready for review January 7, 2025 10:39
@yutannihilation
Copy link
Owner Author

The last failure was due to missing #[cfg()] on the *__ffi() version of function. Fixed now.

    #[cfg(not(target_os = "windows"))]
    #[allow(non_snake_case)]
    unsafe fn savvy_StructWithConfig_new_inner(
        self__: savvy::ffi::SEXP,
        x: savvy::ffi::SEXP,
    ) -> savvy::Result<StructWithConfig> {

        ...

    }
    #[allow(clippy::missing_safety_doc)]
    #[no_mangle]
    pub unsafe extern "C" fn savvy_StructWithConfig_new__ffi(
        self__: savvy::ffi::SEXP,
        x: savvy::ffi::SEXP,
    ) -> savvy::ffi::SEXP {
        match savvy_StructWithConfig_new_inner(self__, x) {

        ...

    }
    #[allow(clippy::missing_safety_doc)]
    #[no_mangle]
    pub unsafe extern "C" fn savvy_StructWithConfig_new__ffi(
        self__: savvy::ffi::SEXP,
        x: savvy::ffi::SEXP,
    ) -> savvy::ffi::SEXP {
        match savvy_StructWithConfig_new_inner(self__, x) {

        ...

        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

#(#attrs)* seems needed here too.

            _ => parse_quote!(
                #[allow(clippy::missing_safety_doc)]
                #[no_mangle]
                pub unsafe extern "C" fn #fn_name_ffi( #(#args_pat: #args_ty),* ) -> savvy::ffi::SEXP {
                    match #fn_name_inner(#(#args_pat),*) {
                        Ok(#ok_lhs) => #ok_rhs,
                        Err(e) => savvy::handle_error(e),
                    }
                }
            ),

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ouch. Thanks for catching!

@yutannihilation yutannihilation merged commit aa1290e into main Jan 11, 2025
25 checks passed
@yutannihilation yutannihilation deleted the fix/handle-duplicated-definitions branch January 11, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for disabling functions with feature flags
2 participants