-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a type which is equivalent to _Bool in C99 #992
Comments
Did this ever happen? What should I do if I'm wrapping a C library that uses Edit: Never mind; seems it is still in the works but according to this comment all compilers/systems that you'd care about make |
I would argue that we should define Rust's |
Wouldn't it prevent the compiler to do things like pack 8 bool in a byte? Or does |
@Yamakaky Packing like that would have to be opt-in because you can take references to any fields. |
Well, I'm not a rust pro, but I'd be happy with a |
There are basically 2 ways to define
#[repr(i8)]
enum c_bool {
c_false = 0,
c_true = 1,
} The first one is easier to use, but ties our representation of |
@Amanieu I think that tying our representation of |
See rust-lang/rfcs#992 - bool in Rust does not repr(C) as any C type in particular. I was naively assuming that it would repr(C) as int, which is equivalent to gboolean. This makes tests/fixtures/dimensions/bug612951.svg pass again. We were calling rsvg_node_svg_get_view_box() and getting a garbage value inside vbox.active - the low byte actually set as expected, and the high bits set to garbage.
I feel like this issue needs to be resolved. Currently there is no stable way to use |
@le-jzr it's already de facto resolved (and basically de jure resolved). There's no way to change it without silently breaking a ton of code. |
It's just a matter of adding |
@ubsan According to #954 (comment), specifying that Note carefully that I'm not saying I'm categorically against that. I'm just saying it hasn't been stabilized yet. That's the principal problem. As long as it's unstable, then de jure that "ton of code" you speak of is a ton of undefined behavior, even though it de facto works right now. That said, according to #954 (comment), the current representation of |
@le-jzr but it's also allowed in FFI functions without warning (which is close to de jure confirmation). |
The ABI of bool is reserved, see these links: * rust-lang/rfcs#954 (comment) * rust-lang#46156 (comment) * rust-lang/rfcs#992 Currently the improper_ctypes lint is inconsistent with that position by treating bools as if they had a specified ABI. To fix this inconsistency, this changes treatment of bools by the lint. This might break some code, so possibly it has to be phased in slowly...
Hi! At @torproject, we recently decided for tor that it's permissible to write C99, and we now have a function returning a bool that I'd like to wrap in an FFI definition for exposure to our Rust code (cf. https://bugs.torproject.org/25727). We've noted that On the other hand, it seems the If the ABI of Is it possible to come to a decision on this issue soon? |
@isislovecruft I believe that the RFC was closed, and that the representation of bool will be the same as |
It looks like @withoutboats proposed basically accepting #954 (at rust-lang/rust#46156 (comment)) and also thinks that Rust's I'm not very familiar with the Rust RFC process, so I'm not sure what needs to happen next if we want this to move forward. Does someone need to reopen #954? Or should someone propose a FCP on this RFC? Or something else? |
It seems to me that given rust-lang/rust#46156 (comment) and other changes noted in #992 (comment) the points in OP are completed. |
Postponed RFC
This type would have to ensure two aspects:
This could possibly be done through a new
c_bool
primitive type inliblibc
(not an alias) or perhaps a wrapper struct/wrapper newtype if we're able to enhanceas
semantics enough (for example).The text was updated successfully, but these errors were encountered: