-
-
Notifications
You must be signed in to change notification settings - Fork 110
Full enablement of Unions using nightly Rust #402
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
Conversation
@Luke-Nukem Can you rebase this to master with removing merges? #[repr(C)]
pub struct GDate {
- _truncated_record_marker: c_void,
- //julian_days: guint: 32,
- //julian: guint: 1,
- //dmy: guint: 1,
- //day: guint: 6,
- //month: guint: 4,
- //year: guint: 16,
+ pub julian_days: c_uint,
+ pub julian: c_uint,
+ pub dmy: c_uint,
+ pub day: c_uint,
+ pub month: c_uint,
+ pub year: c_uint,
} Strange that GScanner has |
src/parser.rs
Outdated
// TODO: unsure of how to handle this | ||
//if attrs.by_name("is-gtype-struct").is_some() { | ||
// return Ok(()); | ||
//} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems read_record
return type need change to Result<Option<Type>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but it also needs an initialised Type to return. This is where I am unsure what to do... I could maybe return a default()
initialised Type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it can't return Ok(None)
in this case? And don't add type in read_record_start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Result<Option<Type>>
.... I don't know why my mind completely ignored that....
Done.
Regarding the appending of Regarding
Well of course... We can't initialise a newly created struct like that. Have to declare it first, then initialise it. If it were an enum instead of a struct then it might work. If you look at;
each field is a guint, which translates to a c_uint. And they are initialised (which we can't do in rust). |
As I remember size GDate in C will be 64bit or 8bytes with |
Looking at guint it seems it will be a particular size depending on a
|
src/parser.rs
Outdated
@@ -21,6 +21,7 @@ pub fn is_empty_c_type(c_type: &str) -> bool { | |||
c_type == EMPTY_CTYPE | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded extra line
src/parser.rs
Outdated
let mut name = try!(attrs.by_name("name") | ||
.ok_or_else(|| mk_error!("Missing record name", parser))); | ||
let mut c_type = try!(attrs.by_name("type") | ||
.ok_or_else(|| mk_error!("Missing c:type attribute", parser))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt-nigthly change this 2 variables back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, my rustfmt is outdated. Are you running everything through rustfmt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not on regular basic, but sometimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly because latest tend to split function declaration to multiple lines.
Seems you ignore that
stored in one byte and all struct size can be lesser that guint size (not *2 as in your case). Also still not solved problem with including |
Hmm, I thought that was using the full guint, but declaring only 'n' bits of that integer were used... I'll have a look at the bitflags crate.
I don't understand what you mean... The result is;
which to me seems fine. You would need to write the API on top of this to accommodate the nesting... I think the whole issue comes from in the gir;
I can't seem to get those names out, and if I did and the C_Type ended up being name 'u' or 's' then this would cause issues. I can make a small change to not add a number to those two fields, but then I'm not sure it that will cause issues later either. Very sorry if I seem to be lacking an understanding on some things here. |
Result is fine. Problem that it added to all sys crates not only on glib (7 unused copies for each these union and inner struct). |
Same with |
EDIT:
I see we commented at almost the same time 😃 Regarding the bit field structs, I'll see if I can use bitflags crate. |
Yes, it one of functions, that cause problem (I thought that it in Library). It need |
@EPashkin are you sure about the bitflags? Mozilla is using it with bindgen for their servo stuff, and the results seem to wok well. |
You can try ;) |
Strange, but duplicates still present :( |
src/parser.rs
Outdated
|
||
fn read_record(&mut self, parser: &mut Reader, ns_id: u16, attrs: &Attributes) | ||
-> Result<Option<Type>> { | ||
let name = try!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh!
I'm not seeing any duplicates here 😕 |
I meant that (for example) both atk-sys/src/lib.rs and glib-sys/src/lib.rs |
Sorry, something bugged on my machine: duplicate actually removed. |
Minor bug in result formating: |
Okay, that should be the final issue. Except the result formatting? I can't see what you are referring too. |
Seems github generate broken links. if !items.is_empty() {
try!(writeln!(w, ""));
} |
Now produce strange results for GIOChannel, GScannerConfig, gobject-sys::GClosure. gtk-sys::GtkTextAttributes. #[repr(C)]
pub struct GIOChannel {
pub ref_count: c_int,
pub funcs: *mut GIOFuncs,
pub encoding: *mut c_char,
pub read_cd: GIConv,
pub write_cd: GIConv,
pub line_term: *mut c_char,
pub line_term_len: c_uint,
pub buf_size: size_t,
pub read_buf: *mut GString,
pub encoded_read_buf: *mut GString,
pub write_buf: *mut GString,
pub partial_write_buf: [c_char; 6],
_truncated_record_marker: c_void,
//use_buffer: guint: 1,
//do_encode: guint: 1,
//close_on_unref: guint: 1,
//is_readable: guint: 1,
//is_writeable: guint: 1,
//is_seekable: guint: 1,
pub reserved1: gpointer,
pub reserved2: gpointer,
} |
Hm, Seems rust-lang/rust#42068 already stabilized part of unions and it in already beta. |
Good thing that I don't see usage |
We're almost there 😄 I see why the proper truncation is required for fields after bitflags. Just needed to allow either is_bits or !truncated. |
Thanks, @Luke-Nukem, Now I don't see any potential problems in generated code. |
I think I did the squash correctly? It's commit #f56da73. |
Yes, #f56da73 is good, but next is not (it merge again). |
Got it. Figured if there was an issue it would be an easy solve. Never done a squash before, very handy. |
Hold fire a few minutes, I'll clean up the commit log |
Actually you added to squashed commit some changes from current master (like adding external_libraries.rs and using it) but git is smart and will ignore it on merge. |
59a3d75
to
52be615
Compare
Okay, I think we're good now? |
Previous was good (based on 9e3f4cc - current upstream master) |
Just to |
This commit enables full genertion of unions if using nightly Rust with feature "use-unions" enabled. It also enables successful generation of nested (anonymous) struct->union->struct.
Yes, now it good. |
And excuse me for a lot of nitpicking 😉 |
Nitpicking is good. You caught a few things I just didn't think about (or know), or had missed. And it's good practice for me 😉 I'm looking forward to union stabilization in Rust. And when I get more time (or need it) I'll work on the bit-fields in multitype-structs. |
Unions are fully enabled behind a feature-gate. Both non-nightly and nightly Rust appear to be working well.