Skip to content

Commit 1b9d5be

Browse files
committed
generator: Emit new c"" CStr literals
These will land in Rust 1.76 and automatically append a `\0` terminator in the compiler without having to have a checked or `unsafe`-unchecked constructor on `CStr`. Hacking in an invalid `\0` anywhere in the string is disallowed with a compiler error. Note that `proc-macro`, and by extension `proc-macro2` only has support for parsing this literal, but not for emitting it yet.
1 parent 01bfed9 commit 1b9d5be

File tree

10 files changed

+1158
-3545
lines changed

10 files changed

+1158
-3545
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
- run: cargo check --workspace --all-targets --all-features
1212

1313
check_msrv:
14-
name: Check ash, ash-window and ash-rewrite MSRV (1.69.0)
14+
name: Check ash, ash-window and ash-rewrite MSRV (1.77.0)
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18-
- uses: dtolnay/rust-toolchain@1.69.0
18+
- uses: dtolnay/rust-toolchain@1.77.0
1919
- run: cargo check -p ash -p ash-rewrite -p ash-window --all-features
2020

2121
# TODO: add a similar job for the rewrite once that generates code

ash-examples/src/bin/texture.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![warn(unused_qualifications)]
22

33
use std::default::Default;
4-
use std::ffi::CStr;
54
use std::io::Cursor;
65
use std::mem;
76
use std::os::raw::c_void;
@@ -566,7 +565,7 @@ fn main() {
566565
.create_pipeline_layout(&layout_create_info, None)
567566
.unwrap();
568567

569-
let shader_entry_name = CStr::from_bytes_with_nul_unchecked(b"main\0");
568+
let shader_entry_name = c"main";
570569
let shader_stage_create_infos = [
571570
vk::PipelineShaderStageCreateInfo {
572571
module: vertex_shader_module,

ash-examples/src/bin/triangle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![warn(unused_qualifications)]
22

33
use std::default::Default;
4-
use std::ffi::CStr;
54
use std::io::Cursor;
65
use std::mem;
76

@@ -228,7 +227,7 @@ fn main() {
228227
.create_pipeline_layout(&layout_create_info, None)
229228
.unwrap();
230229

231-
let shader_entry_name = CStr::from_bytes_with_nul_unchecked(b"main\0");
230+
let shader_entry_name = c"main";
232231
let shader_stage_create_infos = [
233232
vk::PipelineShaderStageCreateInfo {
234233
module: vertex_shader_module,

ash-examples/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,9 @@ impl ExampleBase {
220220
.build(&event_loop)
221221
.unwrap();
222222
let entry = Entry::linked();
223-
let app_name = CStr::from_bytes_with_nul_unchecked(b"VulkanTriangle\0");
223+
let app_name = c"VulkanTriangle";
224224

225-
let layer_names = [CStr::from_bytes_with_nul_unchecked(
226-
b"VK_LAYER_KHRONOS_validation\0",
227-
)];
225+
let layer_names = [c"VK_LAYER_KHRONOS_validation"];
228226
let layers_names_raw: Vec<*const c_char> = layer_names
229227
.iter()
230228
.map(|raw_name| raw_name.as_ptr())

ash-window/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ categories = [
1616
"rendering::graphics-api"
1717
]
1818
edition = "2021"
19-
rust-version = "1.69.0"
19+
rust-version = "1.77.0"
2020

2121
[dependencies]
2222
ash = { path = "../ash", version = "0.37", default-features = false }

ash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ categories = [
1919
"rendering::graphics-api"
2020
]
2121
edition = "2021"
22-
rust-version = "1.69.0"
22+
rust-version = "1.77.0"
2323

2424
[dependencies]
2525
libloading = { version = "0.8", optional = true }

ash/src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl Entry {
220220
#[inline]
221221
pub unsafe fn try_enumerate_instance_version(&self) -> VkResult<Option<u32>> {
222222
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
223-
let name = CStr::from_bytes_with_nul_unchecked(b"vkEnumerateInstanceVersion\0");
223+
let name = c"vkEnumerateInstanceVersion";
224224
mem::transmute((self.static_fn.get_instance_proc_addr)(
225225
vk::Instance::null(),
226226
name.as_ptr(),
@@ -332,7 +332,7 @@ impl vk::StaticFn {
332332
{
333333
Ok(Self {
334334
get_instance_proc_addr: unsafe {
335-
let cname = CStr::from_bytes_with_nul_unchecked(b"vkGetInstanceProcAddr\0");
335+
let cname = c"vkGetInstanceProcAddr";
336336
let val = _f(cname);
337337
if val.is_null() {
338338
return Err(MissingEntryPoint);

0 commit comments

Comments
 (0)