examples: Remove remaining CString allocations on string literals
These allocations and runtime assertions can all be replaced with a `CStr` directly wrapping a binary-string literal, as long as it is null-terminated.
This commit is contained in:
parent
57303f52dc
commit
afdab863d0
|
@ -1,5 +1,5 @@
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::CString;
|
use std::ffi::CStr;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::mem::{self, align_of};
|
use std::mem::{self, align_of};
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
|
@ -573,7 +573,7 @@ fn main() {
|
||||||
.create_pipeline_layout(&layout_create_info, None)
|
.create_pipeline_layout(&layout_create_info, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let shader_entry_name = CString::new("main").unwrap();
|
let shader_entry_name = CStr::from_bytes_with_nul_unchecked(b"main\0");
|
||||||
let shader_stage_create_infos = [
|
let shader_stage_create_infos = [
|
||||||
vk::PipelineShaderStageCreateInfo {
|
vk::PipelineShaderStageCreateInfo {
|
||||||
module: vertex_shader_module,
|
module: vertex_shader_module,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ash::util::*;
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
use examples::*;
|
use examples::*;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::CString;
|
use std::ffi::CStr;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::mem::align_of;
|
use std::mem::align_of;
|
||||||
|
@ -226,7 +226,7 @@ fn main() {
|
||||||
.create_pipeline_layout(&layout_create_info, None)
|
.create_pipeline_layout(&layout_create_info, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let shader_entry_name = CString::new("main").unwrap();
|
let shader_entry_name = CStr::from_bytes_with_nul_unchecked(b"main\0");
|
||||||
let shader_stage_create_infos = [
|
let shader_stage_create_infos = [
|
||||||
vk::PipelineShaderStageCreateInfo {
|
vk::PipelineShaderStageCreateInfo {
|
||||||
module: vertex_shader_module,
|
module: vertex_shader_module,
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub use ash::{Device, Instance};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::CStr;
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ impl ExampleBase {
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let entry = Entry::linked();
|
let entry = Entry::linked();
|
||||||
let app_name = CString::new("VulkanTriangle").unwrap();
|
let app_name = CStr::from_bytes_with_nul_unchecked(b"VulkanTriangle\0");
|
||||||
|
|
||||||
let layer_names = [CStr::from_bytes_with_nul_unchecked(
|
let layer_names = [CStr::from_bytes_with_nul_unchecked(
|
||||||
b"VK_LAYER_KHRONOS_validation\0",
|
b"VK_LAYER_KHRONOS_validation\0",
|
||||||
|
@ -236,9 +236,9 @@ impl ExampleBase {
|
||||||
extension_names_raw.push(DebugUtils::name().as_ptr());
|
extension_names_raw.push(DebugUtils::name().as_ptr());
|
||||||
|
|
||||||
let appinfo = vk::ApplicationInfo::builder()
|
let appinfo = vk::ApplicationInfo::builder()
|
||||||
.application_name(&app_name)
|
.application_name(app_name)
|
||||||
.application_version(0)
|
.application_version(0)
|
||||||
.engine_name(&app_name)
|
.engine_name(app_name)
|
||||||
.engine_version(0)
|
.engine_version(0)
|
||||||
.api_version(vk::make_api_version(0, 1, 0, 0));
|
.api_version(vk::make_api_version(0, 1, 0, 0));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue