Skip to content

Commit eb7b35a

Browse files
refactor: use more c string literals
1 parent f92590f commit eb7b35a

File tree

7 files changed

+34
-20
lines changed

7 files changed

+34
-20
lines changed

wgpu-hal/src/auxil/dxgi/time.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ impl PresentationTimer {
6262
let kernelbase =
6363
libloading::os::windows::Library::open_already_loaded("kernelbase.dll").unwrap();
6464
// No concerns about lifetimes here as kernelbase is always there.
65-
let ptr = unsafe { kernelbase.get(b"QueryInterruptTimePrecise\0").unwrap() };
65+
let ptr = unsafe {
66+
kernelbase
67+
.get(c"QueryInterruptTimePrecise".to_bytes())
68+
.unwrap()
69+
};
6670
Self::IPresentationManager {
6771
fnQueryInterruptTimePrecise: *ptr,
6872
}

wgpu-hal/src/auxil/renderdoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl RenderDoc {
7171
};
7272

7373
let get_api: libloading::Symbol<GetApiFn> =
74-
match unsafe { renderdoc_lib.get(b"RENDERDOC_GetAPI\0") } {
74+
match unsafe { renderdoc_lib.get(c"RENDERDOC_GetAPI".to_bytes()) } {
7575
Ok(api) => api,
7676
Err(e) => {
7777
return RenderDoc::NotAvailable {

wgpu-hal/src/dx12/device.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
};
3232

3333
// this has to match Naga's HLSL backend, and also needs to be null-terminated
34-
const NAGA_LOCATION_SEMANTIC: &[u8] = b"LOC\0";
34+
const NAGA_LOCATION_SEMANTIC: &[u8] = c"LOC".to_bytes();
3535

3636
impl super::Device {
3737
pub(super) fn new(

wgpu-hal/src/dx12/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ impl D3D12Lib {
158158
riid: *const windows_core::GUID,
159159
ppdevice: *mut *mut core::ffi::c_void,
160160
) -> windows_core::HRESULT;
161-
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"D3D12CreateDevice\0") }?;
161+
let func: libloading::Symbol<Fun> =
162+
unsafe { self.lib.get(c"D3D12CreateDevice".to_bytes()) }?;
162163

163164
let mut result__: Option<Direct3D12::ID3D12Device> = None;
164165

@@ -199,7 +200,7 @@ impl D3D12Lib {
199200
pperrorblob: *mut *mut core::ffi::c_void,
200201
) -> windows_core::HRESULT;
201202
let func: libloading::Symbol<Fun> =
202-
unsafe { self.lib.get(b"D3D12SerializeRootSignature\0") }?;
203+
unsafe { self.lib.get(c"D3D12SerializeRootSignature".to_bytes()) }?;
203204

204205
let desc = Direct3D12::D3D12_ROOT_SIGNATURE_DESC {
205206
NumParameters: parameters.len() as _,
@@ -238,7 +239,8 @@ impl D3D12Lib {
238239
riid: *const windows_core::GUID,
239240
ppvdebug: *mut *mut core::ffi::c_void,
240241
) -> windows_core::HRESULT;
241-
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"D3D12GetDebugInterface\0") }?;
242+
let func: libloading::Symbol<Fun> =
243+
unsafe { self.lib.get(c"D3D12GetDebugInterface".to_bytes()) }?;
242244

243245
let mut result__ = None;
244246

@@ -275,7 +277,8 @@ impl DxgiLib {
275277
riid: *const windows_core::GUID,
276278
pdebug: *mut *mut core::ffi::c_void,
277279
) -> windows_core::HRESULT;
278-
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"DXGIGetDebugInterface1\0") }?;
280+
let func: libloading::Symbol<Fun> =
281+
unsafe { self.lib.get(c"DXGIGetDebugInterface1".to_bytes()) }?;
279282

280283
let mut result__ = None;
281284

@@ -304,7 +307,8 @@ impl DxgiLib {
304307
riid: *const windows_core::GUID,
305308
ppfactory: *mut *mut core::ffi::c_void,
306309
) -> windows_core::HRESULT;
307-
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"CreateDXGIFactory2\0") }?;
310+
let func: libloading::Symbol<Fun> =
311+
unsafe { self.lib.get(c"CreateDXGIFactory2".to_bytes()) }?;
308312

309313
let mut result__ = None;
310314

@@ -326,7 +330,8 @@ impl DxgiLib {
326330
riid: *const windows_core::GUID,
327331
ppfactory: *mut *mut core::ffi::c_void,
328332
) -> windows_core::HRESULT;
329-
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"CreateDXGIFactory1\0") }?;
333+
let func: libloading::Symbol<Fun> =
334+
unsafe { self.lib.get(c"CreateDXGIFactory1".to_bytes()) }?;
330335

331336
let mut result__ = None;
332337

wgpu-hal/src/dx12/shader_compilation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl DxcLib {
112112
-> windows_core::HRESULT;
113113

114114
let func: libloading::Symbol<DxcCreateInstanceFn> =
115-
self.lib.get(b"DxcCreateInstance\0")?;
115+
self.lib.get(c"DxcCreateInstance".to_bytes())?;
116116
dxc_create_instance::<T>(|clsid, iid, ppv| func(clsid, iid, ppv))
117117
}
118118
}

wgpu-hal/src/gles/adapter.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl super::Adapter {
203203
// emscripten doesn't enable "WEBGL_debug_renderer_info" extension by default. so, we do it manually.
204204
// See https://github.com/gfx-rs/wgpu/issues/3245 for context
205205
#[cfg(Emscripten)]
206-
if unsafe { super::emscripten::enable_extension("WEBGL_debug_renderer_info\0") } {
206+
if unsafe {
207+
super::emscripten::enable_extension(c"WEBGL_debug_renderer_info".to_str().unwrap())
208+
} {
207209
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
208210
} else {
209211
(glow::VENDOR, glow::RENDERER)

wgpu-hal/src/gles/egl.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Drop for DisplayOwner {
147147
match self.display {
148148
DisplayRef::X11(ptr) => unsafe {
149149
let func: libloading::Symbol<XCloseDisplayFun> =
150-
self.library.get(b"XCloseDisplay\0").unwrap();
150+
self.library.get(c"XCloseDisplay".to_bytes()).unwrap();
151151
func(ptr.as_ptr());
152152
},
153153
DisplayRef::Wayland => {}
@@ -159,7 +159,8 @@ fn open_x_display() -> Option<DisplayOwner> {
159159
log::debug!("Loading X11 library to get the current display");
160160
unsafe {
161161
let library = find_library(&["libX11.so.6", "libX11.so"])?;
162-
let func: libloading::Symbol<XOpenDisplayFun> = library.get(b"XOpenDisplay\0").unwrap();
162+
let func: libloading::Symbol<XOpenDisplayFun> =
163+
library.get(c"XOpenDisplay".to_bytes()).unwrap();
163164
let result = func(ptr::null());
164165
ptr::NonNull::new(result).map(|ptr| DisplayOwner {
165166
display: DisplayRef::X11(ptr),
@@ -185,10 +186,12 @@ fn test_wayland_display() -> Option<DisplayOwner> {
185186
log::debug!("Loading Wayland library to get the current display");
186187
let library = unsafe {
187188
let client_library = find_library(&["libwayland-client.so.0", "libwayland-client.so"])?;
188-
let wl_display_connect: libloading::Symbol<WlDisplayConnectFun> =
189-
client_library.get(b"wl_display_connect\0").unwrap();
190-
let wl_display_disconnect: libloading::Symbol<WlDisplayDisconnectFun> =
191-
client_library.get(b"wl_display_disconnect\0").unwrap();
189+
let wl_display_connect: libloading::Symbol<WlDisplayConnectFun> = client_library
190+
.get(c"wl_display_connect".to_bytes())
191+
.unwrap();
192+
let wl_display_disconnect: libloading::Symbol<WlDisplayDisconnectFun> = client_library
193+
.get(c"wl_display_disconnect".to_bytes())
194+
.unwrap();
192195
let display = ptr::NonNull::new(wl_display_connect(ptr::null()))?;
193196
wl_display_disconnect(display.as_ptr());
194197
find_library(&["libwayland-egl.so.1", "libwayland-egl.so"])?
@@ -1317,7 +1320,7 @@ impl crate::Surface for Surface {
13171320
(WindowKind::Wayland, Rwh::Wayland(handle)) => {
13181321
let library = &self.wsi.display_owner.as_ref().unwrap().library;
13191322
let wl_egl_window_create: libloading::Symbol<WlEglWindowCreateFun> =
1320-
unsafe { library.get(b"wl_egl_window_create\0") }.unwrap();
1323+
unsafe { library.get(c"wl_egl_window_create".to_bytes()) }.unwrap();
13211324
let window =
13221325
unsafe { wl_egl_window_create(handle.surface.as_ptr(), 640, 480) }
13231326
.cast();
@@ -1429,7 +1432,7 @@ impl crate::Surface for Surface {
14291432
if let Some(window) = wl_window {
14301433
let library = &self.wsi.display_owner.as_ref().unwrap().library;
14311434
let wl_egl_window_resize: libloading::Symbol<WlEglWindowResizeFun> =
1432-
unsafe { library.get(b"wl_egl_window_resize\0") }.unwrap();
1435+
unsafe { library.get(c"wl_egl_window_resize".to_bytes()) }.unwrap();
14331436
unsafe {
14341437
wl_egl_window_resize(
14351438
window,
@@ -1501,7 +1504,7 @@ impl crate::Surface for Surface {
15011504
.expect("unsupported window")
15021505
.library;
15031506
let wl_egl_window_destroy: libloading::Symbol<WlEglWindowDestroyFun> =
1504-
unsafe { library.get(b"wl_egl_window_destroy\0") }.unwrap();
1507+
unsafe { library.get(c"wl_egl_window_destroy".to_bytes()) }.unwrap();
15051508
unsafe { wl_egl_window_destroy(window) };
15061509
}
15071510
}

0 commit comments

Comments
 (0)