Skip to content

Commit c332ede

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 1b24430 commit c332ede

File tree

11 files changed

+1148
-3001
lines changed

11 files changed

+1148
-3001
lines changed

.github/workflows/ci.yml

+2-2
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
- name: Check ash, ash-window and ash-rewrite
2020
run: cargo check -p ash -p ash-rewrite -p ash-window --all-features
2121
- name: Check ash with no_std

ash-examples/src/bin/texture.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::default::Default;
44
use std::error::Error;
5-
use std::ffi;
65
use std::io::Cursor;
76
use std::mem;
87
use std::os::raw::c_void;
@@ -567,7 +566,7 @@ fn main() -> Result<(), Box<dyn Error>> {
567566
.create_pipeline_layout(&layout_create_info, None)
568567
.unwrap();
569568

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

ash-examples/src/bin/triangle.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::default::Default;
44
use std::error::Error;
5-
use std::ffi;
65
use std::io::Cursor;
76
use std::mem;
87

@@ -229,7 +228,7 @@ fn main() -> Result<(), Box<dyn Error>> {
229228
.create_pipeline_layout(&layout_create_info, None)
230229
.unwrap();
231230

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

ash-examples/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,9 @@ impl ExampleBase {
212212
.build(&event_loop)
213213
.unwrap();
214214
let entry = Entry::linked();
215-
let app_name = ffi::CStr::from_bytes_with_nul_unchecked(b"VulkanTriangle\0");
215+
let app_name = c"VulkanTriangle";
216216

217-
let layer_names = [ffi::CStr::from_bytes_with_nul_unchecked(
218-
b"VK_LAYER_KHRONOS_validation\0",
219-
)];
217+
let layer_names = [c"VK_LAYER_KHRONOS_validation"];
220218
let layers_names_raw: Vec<*const c_char> = layer_names
221219
.iter()
222220
.map(|raw_name| raw_name.as_ptr())

ash-window/Cargo.toml

+1-1
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, features = ["std"] }

ash/Cargo.toml

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl Entry {
216216
#[inline]
217217
pub unsafe fn try_enumerate_instance_version(&self) -> VkResult<Option<u32>> {
218218
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
219-
let name = ffi::CStr::from_bytes_with_nul_unchecked(b"vkEnumerateInstanceVersion\0");
219+
let name = c"vkEnumerateInstanceVersion";
220220
mem::transmute((self.static_fn.get_instance_proc_addr)(
221221
vk::Instance::null(),
222222
name.as_ptr(),
@@ -328,7 +328,7 @@ impl crate::StaticFn {
328328
{
329329
Ok(Self {
330330
get_instance_proc_addr: unsafe {
331-
let cname = ffi::CStr::from_bytes_with_nul_unchecked(b"vkGetInstanceProcAddr\0");
331+
let cname = c"vkGetInstanceProcAddr";
332332
let val = _f(cname);
333333
if val.is_null() {
334334
return Err(MissingEntryPoint);

0 commit comments

Comments
 (0)