Skip to content

Commit

Permalink
Unions: tweaks to copy,clone, and remove unneeded if/else
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Jones committed Jul 29, 2017
1 parent 8096d96 commit c199ba4
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/codegen/sys/lib_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ fn generate_unions(w: &mut Write, env: &Env, items: &[&Union]) -> Result<()> {
if lines.is_empty() {
try!(writeln!(
w,
"{0}#[repr(C)]\n{0}#[derive(Copy,Clone)]\n{0}pub union {1}(c_void);\n",
"{0}#[repr(C)]\n{0}pub union {1}(c_void);\n",
comment,
c_type
));
Expand Down Expand Up @@ -455,11 +455,6 @@ fn generate_fields(env: &Env, struct_name: &str, fields: &[Field]) -> (Vec<Strin
let mut commented = false;
let mut truncated = false;

//TODO: remove after GObject-2.0.gir fixed
// Fix for wrong GValue size on i686-pc-windows-gnu due `c:type="gpointer"` in data field
// instead guint64
let is_gvalue = env.config.library_name == "GObject" && struct_name == "Value";

// TODO: GLib/GObject special cases until we have proper union support in Rust
let is_gweakref = env.config.library_name == "GObject" && struct_name == "WeakRef";

Expand Down Expand Up @@ -507,18 +502,12 @@ fn generate_fields(env: &Env, struct_name: &str, fields: &[Field]) -> (Vec<Strin
continue 'fields;
}

if is_gweakref {
// union containing a single pointer
lines.push("\tpub priv_: gpointer,".to_owned());
} else if let Some(ref c_type) = field.c_type {
if let Some(ref c_type) = field.c_type {
let name = mangle_keywords(&*field.name);
let mut c_type = ffi_type(env, field.typ, c_type);
let c_type = ffi_type(env, field.typ, c_type);
if c_type.is_err() {
commented = true;
}
if is_gvalue && field.name == "data" {
c_type = Ok("[u64; 2]".to_owned());
}
lines.push(format!("\tpub {}: {},", name, c_type.into_string()));
} else {
let name = mangle_keywords(&*field.name);
Expand Down

0 comments on commit c199ba4

Please sign in to comment.