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

[feature request] Blacklisting functions #1142

Closed
ExpHP opened this issue Nov 6, 2017 · 6 comments
Closed

[feature request] Blacklisting functions #1142

ExpHP opened this issue Nov 6, 2017 · 6 comments

Comments

@ExpHP
Copy link

ExpHP commented Nov 6, 2017

In lammps-sys I have a feature to enable use of system include paths to locate mpi.h. When this feature is disabled, I want to forbid use of functions which depend on the MPI types.

if cfg!(not(feature = "system-mpi")) {
    gen = gen.blacklist_type("([oOpP])?[mM][pP][iI].*");
}

However, one of the functions I am exposing has such a type in its signature, leading to a compile error (cannot find type MPI_Comm in this scope). It is too difficult to write a whitelist pattern that does not match this function, so my workaround has been to instead define an empty enum replacement type when the feature is not enabled. (as a result, my feature flag is, strictly speaking, not purely additive in terms of build artefacts.)

What would be far better is the ability to simply blacklist the function lammps_open.


>_>

<_<

Incidentally, this functionality is already actually possible through the use of the blacklist_type function:

if cfg!(not(feature = "system-mpi")) {
    gen = gen.blacklist_type("([oOpP])?[mM][pP][iI].*");
    gen = gen.blacklist_type("lammps_open");  // this actually blacklists the function!
}

so we pretty much already have the implementation. 😛

@fitzgen
Copy link
Member

fitzgen commented Nov 6, 2017

Sounds reasonable to me.

@maxfurman
Copy link

It sounds like this is just a request to alias blacklist_type to blacklist_function?

@ExpHP
Copy link
Author

ExpHP commented Jan 3, 2018

Heh, when I said "we pretty much already have the implementation", I was joking. Honestly, I'd consider the fact that blacklist_type blacklists functions to be a bug!

...but I guess the best step forward does in fact look more or less like exactly what you said:

  • Add a blacklist_function method which calls blacklist_type
    • (This seems better to me than the alternative of renaming blacklist_type to blacklist, because the intended use-case of blacklist_type is well-documented in the book and I wouldn't want to sully it)
  • Document its use case of allowing one to refine the results grabbed by whitelist_function
  • Open an bug about the fact that blacklist_function and blacklist_type both actually do each other's jobs. 😛

@waywardmonkeys
Copy link
Contributor

I'm working on this.

@jhod0
Copy link
Contributor

jhod0 commented Dec 6, 2018

It looks like this is implemented: https://docs.rs/bindgen/0.44.0/bindgen/struct.Builder.html#method.blacklist_function

Should this issue be closed?

@emilio
Copy link
Contributor

emilio commented Dec 6, 2018

Yup, thanks! Fixed by #1364.

@emilio emilio closed this as completed Dec 6, 2018
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

6 participants