Skip to content

Commit fa266f9

Browse files
author
Luke Jones
committed
Allow special cases for bitflags in structs (and proper truncation if bitflags)
1 parent c39bdde commit fa266f9

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/codegen/sys/lib_.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ fn generate_enums(w: &mut Write, env: &Env, items: &[&Enumeration]) -> Result<()
312312
}
313313

314314
fn generate_unions(w: &mut Write, env: &Env, items: &[&Union]) -> Result<()> {
315+
315316
if !items.is_empty() {
316317
try!(writeln!(w, "// Unions"));
317318
}
@@ -363,8 +364,11 @@ fn generate_unions(w: &mut Write, env: &Env, items: &[&Union]) -> Result<()> {
363364
}
364365
}
365366
}
366-
if !items.is_empty() {
367-
try!(writeln!(w, ""));
367+
#[cfg(not(feature = "use_unions"))]
368+
{
369+
if !items.is_empty() {
370+
try!(writeln!(w, ""));
371+
}
368372
}
369373

370374
Ok(())
@@ -530,7 +534,7 @@ fn generate_fields(env: &Env, struct_name: &str, fields: &[Field]) -> (Vec<Strin
530534
}
531535
}
532536

533-
if !cfg!(feature = "use_unions") || is_bits {
537+
if !cfg!(feature = "use_unions") || is_bits || !truncated {
534538
if !is_gweakref && !truncated && !is_ptr &&
535539
(is_union || is_bits) &&
536540
!is_union_special_case(&field.c_type)
@@ -543,24 +547,24 @@ fn generate_fields(env: &Env, struct_name: &str, fields: &[Field]) -> (Vec<Strin
543547
lines.push("\t_truncated_record_marker: c_void,".to_owned());
544548
truncated = true;
545549
}
550+
}
546551

547-
if truncated {
548-
if is_union {
549-
lines.push("\t//union,".to_owned());
550-
} else {
551-
let bits = field
552-
.bits
553-
.map(|n| format!(": {}", n))
554-
.unwrap_or_else(|| "".to_owned());
555-
lines.push(format!(
556-
"\t//{}: {}{},",
557-
field.name,
558-
field.c_type.as_ref().map(|s| &s[..]).unwrap_or("fn"),
559-
bits
560-
));
561-
};
562-
continue 'fields;
563-
}
552+
if truncated {
553+
if is_union {
554+
lines.push("\t//union,".to_owned());
555+
} else {
556+
let bits = field
557+
.bits
558+
.map(|n| format!(": {}", n))
559+
.unwrap_or_else(|| "".to_owned());
560+
lines.push(format!(
561+
"\t//{}: {}{},",
562+
field.name,
563+
field.c_type.as_ref().map(|s| &s[..]).unwrap_or("fn"),
564+
bits
565+
));
566+
};
567+
continue 'fields;
564568
}
565569

566570
if let Some(ref c_type) = field.c_type {

0 commit comments

Comments
 (0)