extensions: Don't check extension names for interior nuls at runtime ()

This name is emitted by the generator and already known to not contain
any null-characters: replace the runtime iteration+comparison (hidden
behind `from_bytes_with_nul`) and `.expect()` panic with an `unsafe`
"cast" through `from_bytes_with_nul_unchecked`, just like the
function-pointer loaders.
This commit is contained in:
Marijn Suijten 2021-12-22 01:38:48 +01:00 committed by GitHub
parent 90960efded
commit 0ae56a0961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 740 additions and 900 deletions
Changelog.md
ash/src/vk
generator/src

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Extension names from `fn name()` will not be checked for interior nuls anymore at runtime (#522)
- examples: Use `c_char` for pointer to raw string (#521)
- Device extension `khr::PipelineExecutableProperties` and `khr::TimelineSemaphore` now expose `fn device()` instead of `fn instance()` (#499)
- Changed `khr::PipelineExecutableProperties::new()` and `khr::TimelineSemaphore::new()` to take `instance` and `device` as arguments (#499)

File diff suppressed because it is too large Load diff

View file

@ -1203,7 +1203,6 @@ pub fn generate_extension_commands<'a>(
extension_name.to_camel_case().strip_prefix("Vk").unwrap()
);
let fp = generate_function_pointers(ident.clone(), &commands, &aliases, fn_cache);
let byte_name = format!("{}\0", extension_name);
let spec_version = items
.iter()
@ -1227,11 +1226,11 @@ pub fn generate_extension_commands<'a>(
}
});
let byte_name_ident = syn::LitByteStr::new(byte_name.as_bytes(), Span::call_site());
let byte_name_ident = Literal::byte_string(format!("{}\0", extension_name).as_bytes());
let extension_cstr = quote! {
impl #ident {
pub fn name() -> &'static ::std::ffi::CStr {
::std::ffi::CStr::from_bytes_with_nul(#byte_name_ident).expect("Wrong extension string")
unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(#byte_name_ident) }
}
#spec_version
}