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: Customize pointer types #2023

Open
tbodt opened this issue Apr 5, 2021 · 3 comments · May be fixed by #2708
Open

Feature request: Customize pointer types #2023

tbodt opened this issue Apr 5, 2021 · 3 comments · May be fixed by #2708

Comments

@tbodt
Copy link
Contributor

tbodt commented Apr 5, 2021

I'd like to be able to customize the types of pointer types generated by bindgen. That is, the input:

struct foo {
    int *bar;
};

would produce the output:

struct foo {
    pub bar: CustomPointer<::std::os::raw::c_int>,
}

where CustomPointer is an arbitrary type path specified in configuration.

The idea here is the custom pointer type can be a safe transparent wrapper around an integer value, which can e.g. treat the pointer as belonging to another process and read it from there.

@emilio
Copy link
Contributor

emilio commented Apr 6, 2021

Not opposed to this, seems like a reasonable thing to want. Curious about your use case, can you customize the header? Introducing an annotation for this should be straight-forward. Adding some sort of configuration seems a bit more tricky because we need a way to target fields and such which I don't think we have atm.

@tbodt
Copy link
Contributor Author

tbodt commented Apr 6, 2021

I prefer not to customize the header. This is being generated from linux uapi headers. I don't need a way to target things though, I want this to apply universally.

@emilio
Copy link
Contributor

emilio commented Apr 20, 2021

Ah, alright, then it should also be trivial. A patch that checks the context options here:

TypeKind::Pointer(inner) | TypeKind::Reference(inner) => {

Or even here:

fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream {

Would do and should be straight-forward.

remexre added a commit to remexre/rust-bindgen that referenced this issue Jan 5, 2024
These options allow specifying an alternate type to use where pointer
types would otherwise be used. This is useful for binding to a
WebAssembly guest, as well as for certain kinds of serialization and
deserialization.

Resolves rust-lang#2023.
remexre added a commit to remexre/rust-bindgen that referenced this issue Jan 5, 2024
These options allow specifying an alternate type to use where pointer
types would otherwise be used. This is useful for binding to a
WebAssembly guest, as well as for certain kinds of serialization and
deserialization.

Resolves rust-lang#2023.
remexre added a commit to remexre/rust-bindgen that referenced this issue Jan 5, 2024
These options allow specifying an alternate type to use where pointer
types would otherwise be used. This is useful for binding to a
WebAssembly guest, as well as for certain kinds of serialization and
deserialization.

Resolves rust-lang#2023.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants