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

Dealing with NULL-able function pointers #30

Open
jgallagher opened this issue Jan 21, 2016 · 4 comments
Open

Dealing with NULL-able function pointers #30

jgallagher opened this issue Jan 21, 2016 · 4 comments

Comments

@jgallagher
Copy link

If I declare the following struct in Rust:

#[repr(C)]
pub struct foo {
    bar: extern "C" fn(blah: *mut libc::c_void)
}

rusty-cheddar (correctly) generates this in its header:

typedef struct foo {
    void (*bar)(void *blah);
} foo;

C code is able to set bar to NULL, but on the Rust side, there's no way to check for that. It appears the expected way of handling this (see here or here) is to change the type on the Rust side to an Option:

#[repr(C)]
pub struct foo {
    bar: Option<extern "C" fn(blah: *mut libc::c_void)>
}

but rusty-cheddar does not handle this appropriately.

@Sean1708
Copy link
Owner

Yep this seems like a good course of action, thanks. It's gonna take a bit of work so I can't promise I'll have a fix out as quickly as last time though.

@jgallagher
Copy link
Author

No worries. I love that this project exists; thanks for making it! I figured this one would be a bit more work. :)

@kinetiknz
Copy link

FWIW, I've added support for this in kinetiknz@bb819e5.

I assume @Sean1708 won't want to merge it because rusty-cheddar is being replaced with rusty-binder, but we (https://github.com/mozilla/mp4parse-rust) need this to fix a UB bug (rust-lang/rust#40913), so I went ahead and hacked something up.

@rillian
Copy link
Contributor

rillian commented Mar 31, 2017

We could still benefit from deploying this fix while rusty-binder is under development. @Sean1708, if you're not interested in merging, would you be willing to add one of us to https://crates.io/crates/rusty-cheddar so we can make releases in the meantime?

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

No branches or pull requests

4 participants