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

middle::Cif needs a variadic variation for its new function #55

Closed
r0nsha opened this issue May 9, 2022 · 1 comment
Closed

middle::Cif needs a variadic variation for its new function #55

r0nsha opened this issue May 9, 2022 · 1 comment

Comments

@r0nsha
Copy link

r0nsha commented May 9, 2022

While transitioning from the low api to the middle api, I found that there is no new_variadic function for Cif, which is a must for me. I can't create a pull request, so I'm pasting the function I created for myself here in hope that some variation of this function will be merged :)

    /// Creates a new variadic [CIF](Cif) for the given argument and result
    /// types.
    ///
    /// Takes ownership of the argument and result [`Type`]s, because
    /// the resulting [`Cif`] retains references to them. Defaults to
    /// the platform’s default calling convention; this can be adjusted
    /// using [`Cif::set_abi`].
    pub fn new_variadic<I>(args: I, fixed_args: usize, result: Type) -> Self
    where
        I: IntoIterator<Item = Type>,
        I::IntoIter: ExactSizeIterator<Item = Type>,
    {
        let args = args.into_iter();
        let nargs = args.len();
        let args = types::TypeArray::new(args);
        let mut cif: low::ffi_cif = Default::default();

        unsafe {
            low::prep_cif_var(
                &mut cif,
                low::ffi_abi_FFI_DEFAULT_ABI,
                fixed_args,
                nargs,
                result.as_raw_ptr(),
                args.as_raw_ptr(),
            )
        }
        .expect("low::prep_cif_var");

        // Note that cif retains references to args and result,
        // which is why we hold onto them here.
        Cif { cif, args, result }
    }
@r0nsha
Copy link
Author

r0nsha commented Jun 20, 2022

Closing in favor of a PR

@r0nsha r0nsha closed this as completed Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants