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

Not all constants generated from headers have correct types #1875

Open
YohDeadfall opened this issue Sep 24, 2024 · 3 comments
Open

Not all constants generated from headers have correct types #1875

YohDeadfall opened this issue Sep 24, 2024 · 3 comments

Comments

@YohDeadfall
Copy link
Contributor

Today I found an issue while working with transactions and non-atomic connections:

Spi::check_status(unsafe { pg_sys::SPI_connect_ext(pg_sys::SPI_OPT_NONATOMIC) })?;
                           ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
                           |
                           arguments to this function are incorrect

Not sure that it's possible to be done automatically from the code only, but having a list of hints can fix it.

@eeeebbbbrrrr
Copy link
Contributor

This is fairly common. All the #define constants are considered to be u32s.

Generally an “as” cast is good enough.

I think providing some kind of hint list would be a lot of upkeep

@workingjubilee
Copy link
Member

workingjubilee commented Sep 25, 2024

Yeah, there's no way to fix this generally because the C code doesn't really care what the type is: it is going to impose numeric coercions on inputs until it gets what it wants. So it will be coerced in different ways in different places. So you have to do the same by hand in Rust, sometimes.

@workingjubilee
Copy link
Member

for note, we could tell bindgen to shrink the constants to their smallest applicable type, but that would probably be really fucking annoying rather than helpful.

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

3 participants