Merge pull request #128 from Ralith/optional-pfn

Wrap function pointers in Option since they might be null
This commit is contained in:
Maik Klein 2018-10-11 09:30:07 +02:00 committed by GitHub
commit 6193a256fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1752 additions and 1747 deletions

File diff suppressed because it is too large Load diff

View file

@ -310,7 +310,7 @@ impl ExampleBase {
flags: vk::DebugReportFlagsEXT::ERROR flags: vk::DebugReportFlagsEXT::ERROR
| vk::DebugReportFlagsEXT::WARNING | vk::DebugReportFlagsEXT::WARNING
| vk::DebugReportFlagsEXT::PERFORMANCE_WARNING, | vk::DebugReportFlagsEXT::PERFORMANCE_WARNING,
pfn_callback: vulkan_debug_callback, pfn_callback: Some(vulkan_debug_callback),
p_user_data: ptr::null_mut(), p_user_data: ptr::null_mut(),
}; };
let debug_report_loader = let debug_report_loader =

View file

@ -1142,14 +1142,6 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
_ => None, _ => None,
}); });
let is_structure_type = |field: &vkxml::Field| field.basetype == "VkStructureType"; let is_structure_type = |field: &vkxml::Field| field.basetype == "VkStructureType";
let is_pfn = |field: &vkxml::Field| {
field
.name
.as_ref()
.map(|n| n.contains("pfn"))
.unwrap_or(false)
};
let contains_pfn = members.clone().any(is_pfn);
// This are also pointers, and therefor also don't implement Default. The spec // This are also pointers, and therefor also don't implement Default. The spec
// also doesn't mark them as pointers // also doesn't mark them as pointers
@ -1157,7 +1149,7 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
let contains_ptr = members.clone().any(|field| field.reference.is_some()); let contains_ptr = members.clone().any(|field| field.reference.is_some());
let contains_strucutre_type = members.clone().any(is_structure_type); let contains_strucutre_type = members.clone().any(is_structure_type);
let contains_static_array = members.clone().any(is_static_array); let contains_static_array = members.clone().any(is_static_array);
if !(contains_ptr || contains_pfn || contains_strucutre_type || contains_static_array) { if !(contains_ptr || contains_strucutre_type || contains_static_array) {
return None; return None;
}; };
let default_fields = members.clone().map(|field| { let default_fields = members.clone().map(|field| {
@ -1209,7 +1201,6 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
} }
} }
} else if is_static_array(field) } else if is_static_array(field)
|| is_pfn(field)
|| handles.contains(&field.basetype.as_str()) || handles.contains(&field.basetype.as_str())
{ {
quote!{ quote!{
@ -1266,7 +1257,7 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt
} }
} else if param_ident.as_ref().contains("pfn") { } else if param_ident.as_ref().contains("pfn") {
quote!{ quote!{
&(self.#param_ident as *const()) &(self.#param_ident.map(|x| x as *const ()))
} }
} else if union_types.contains(field.basetype.as_str()) { } else if union_types.contains(field.basetype.as_str()) {
quote!(&"union") quote!(&"union")
@ -1375,7 +1366,7 @@ fn generate_funcptr(fnptr: &vkxml::FunctionPointer) -> Tokens {
}); });
quote!{ quote!{
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub type #name = unsafe extern "system" fn(#(#params),*) -> #ret_ty_tokens; pub type #name = Option<unsafe extern "system" fn(#(#params),*) -> #ret_ty_tokens>;
} }
} }