Default trait: set pointers to std::ptr::null()/null_mut() instead of zeroed

This commit is contained in:
Matus Talcik 2018-08-22 22:53:17 +02:00
parent 3e812896ff
commit 7e505347f4
2 changed files with 421 additions and 392 deletions

File diff suppressed because it is too large Load diff

View file

@ -1156,8 +1156,37 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
#param_ident: unsafe { ::std::mem::zeroed() }
}
}
} else if field.reference.is_some()
|| is_static_array(field)
} else if let Some(ref reference) = field.reference {
match reference {
vkxml::ReferenceType::Pointer => {
if field.is_const {
quote!{
#param_ident: ::std::ptr::null()
}
} else {
quote!{
#param_ident: ::std::ptr::null_mut()
}
}
}
vkxml::ReferenceType::PointerToPointer => {
quote!{
#param_ident: ::std::ptr::null_mut()
}
}
vkxml::ReferenceType::PointerToConstPointer => {
if field.is_const {
quote!{
#param_ident: ::std::ptr::null()
}
} else {
quote!{
#param_ident: ::std::ptr::null_mut()
}
}
}
}
} else if is_static_array(field)
|| is_pfn(field)
|| handles.contains(&field.basetype.as_str())
{