Skip to content

Add option to avoid wrapping function pointer fields or arguments #2370

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

Closed
wants to merge 1 commit into from

Conversation

pvdrz
Copy link
Contributor

@pvdrz pvdrz commented Dec 9, 2022

This PR adds a new flag --non-null-fn-ptr=<PATH> that can be used to avoid wrapping function pointer arguments or fields in Option if their path matches the <PATH> regex.

For example if we had the following input headers:

typedef struct foo {
    int (*bar)();
} foo;

typedef struct baz {
    int (*bar)();
} foo;

and we were to call bindgen without this flag we would get an output like this:

pub struct foo {
    pub bar: Option<unsafe extern "C" fn() -> c_int>,
}

pub struct baz {
    pub bar: Option<unsafe extern "C" fn() -> c_int>,
}

However, if we call bindgen --non-null-fn-ptr="foo::.*" the output would be:

pub struct foo {
    pub bar: unsafe extern "C" fn() -> c_int,
}

pub struct baz {
    pub bar: Option<unsafe extern "C" fn() -> c_int>,
}

I understand that the ideal would be to change bindgen so it could process nullability attributes instead but it seems those attributes are not used very often and then we would require people to change their c code to achieve the same.

@pvdrz pvdrz requested a review from emilio December 9, 2022 19:38
@pvdrz pvdrz force-pushed the skip-fn-ptr-wrapping branch 4 times, most recently from 7c3c70c to bf8eed7 Compare December 9, 2022 21:32
@bors-servo
Copy link

☔ The latest upstream changes (presumably ed2d06e) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz pvdrz force-pushed the skip-fn-ptr-wrapping branch from bf8eed7 to cbfd03b Compare February 10, 2023 16:22
@bors-servo
Copy link

☔ The latest upstream changes (presumably 2034a0f) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz pvdrz closed this Jun 15, 2023
@pvdrz pvdrz deleted the skip-fn-ptr-wrapping branch June 15, 2023 20:22
@Bromeon
Copy link

Bromeon commented Aug 13, 2023

What happened to this PR?
No feedback in half a year?

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.

Make it possible so that function pointers aren't always wrapped in an Option.
3 participants