From 5ad41e93893271c3f1df1552bacdc237372d63e0 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 11:50:52 +0200 Subject: [PATCH 01/11] `std::ptr::{null, null_mut}` -> `core` --- src/graphics/gl.rs | 8 +-- src/native.rs | 4 +- src/native/android.rs | 28 ++++---- src/native/android/ndk_utils.rs | 2 +- src/native/apple/apple_util.rs | 4 +- src/native/ios.rs | 2 +- src/native/linux_wayland.rs | 64 +++++++++---------- src/native/linux_wayland/extensions.rs | 2 +- src/native/linux_wayland/libwayland_client.rs | 2 +- src/native/linux_wayland/libxkbcommon.rs | 2 +- src/native/linux_wayland/shm.rs | 2 +- src/native/linux_x11.rs | 12 ++-- src/native/linux_x11/clipboard.rs | 2 +- src/native/linux_x11/glx.rs | 6 +- src/native/linux_x11/libx11_ex.rs | 12 ++-- src/native/macos.rs | 10 +-- src/native/windows.rs | 14 ++-- src/native/windows/wgl.rs | 4 +- 18 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 9c8c98440..8f62b9d52 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -245,7 +245,7 @@ impl Texture { 0, format, pixel_type, - std::ptr::null() as _, + core::ptr::null() as _, ); } TextureSource::Bytes(source) => { @@ -347,7 +347,7 @@ impl Texture { pixel_type, match source { Some(source) => source.as_ptr() as *const _, - Option::None => std::ptr::null(), + Option::None => core::ptr::null(), }, ); } @@ -650,7 +650,7 @@ pub fn load_shader(shader_type: GLenum, source: &str) -> Result *mut ndk_sys::JNIEnv { - let mut env: *mut ndk_sys::JNIEnv = std::ptr::null_mut(); + let mut env: *mut ndk_sys::JNIEnv = core::ptr::null_mut(); let attach_current_thread = (**VM).AttachCurrentThread.unwrap(); - let res = attach_current_thread(VM, &mut env, std::ptr::null_mut()); + let res = attach_current_thread(VM, &mut env, core::ptr::null_mut()); assert!(res == 0); env @@ -422,7 +422,7 @@ where let (egl_context, egl_config, egl_display) = crate::native::egl::create_egl_context( &mut libegl, - std::ptr::null_mut(), /* EGL_DEFAULT_DISPLAY */ + core::ptr::null_mut(), /* EGL_DEFAULT_DISPLAY */ conf.platform.framebuffer_alpha, conf.sample_count, ) @@ -440,7 +440,7 @@ where egl_display, egl_config, window as _, - std::ptr::null_mut(), + core::ptr::null_mut(), ); if (libegl.eglMakeCurrent)(egl_display, surface, surface, egl_context) == 0 { @@ -504,9 +504,9 @@ where (s.libegl.eglMakeCurrent)( s.egl_display, - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), + core::ptr::null_mut(), + core::ptr::null_mut(), + core::ptr::null_mut(), ); (s.libegl.eglDestroySurface)(s.egl_display, s.surface); (s.libegl.eglDestroyContext)(s.egl_display, s.egl_context); diff --git a/src/native/android/ndk_utils.rs b/src/native/android/ndk_utils.rs index 6b8f5e949..c50e6512c 100644 --- a/src/native/android/ndk_utils.rs +++ b/src/native/android/ndk_utils.rs @@ -73,7 +73,7 @@ macro_rules! call_bool_method { #[macro_export] macro_rules! get_utf_str { ($env:expr, $obj:expr) => {{ - let cstr_dat = (**$env).GetStringUTFChars.unwrap()($env, $obj, std::ptr::null_mut()); + let cstr_dat = (**$env).GetStringUTFChars.unwrap()($env, $obj, core::ptr::null_mut()); let string = std::ffi::CStr::from_ptr(cstr_dat) .to_str() .unwrap() diff --git a/src/native/apple/apple_util.rs b/src/native/apple/apple_util.rs index 8e4268c8b..576cb5b97 100644 --- a/src/native/apple/apple_util.rs +++ b/src/native/apple/apple_util.rs @@ -67,7 +67,7 @@ pub unsafe fn cfstring_ref_to_string(cfstring: CFStringRef) -> String { kCFStringEncodingUTF8, 0, false, - std::ptr::null_mut::(), + core::ptr::null_mut::(), 0, &mut num_bytes, ); @@ -83,7 +83,7 @@ pub unsafe fn cfstring_ref_to_string(cfstring: CFStringRef) -> String { false, buffer.as_mut_ptr(), num_bytes, - std::ptr::null_mut::(), + core::ptr::null_mut::(), ); String::from_utf8(buffer).unwrap_or_default() } diff --git a/src/native/ios.rs b/src/native/ios.rs index a98831eda..eedb92fdb 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -285,7 +285,7 @@ unsafe fn get_proc_address(name: *const u8) -> Option { pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; } } - static mut OPENGL: *mut std::ffi::c_void = std::ptr::null_mut(); + static mut OPENGL: *mut std::ffi::c_void = core::ptr::null_mut(); if OPENGL.is_null() { OPENGL = libc::dlopen( diff --git a/src/native/linux_wayland.rs b/src/native/linux_wayland.rs index 3b8ff0b46..df9d879f5 100644 --- a/src/native/linux_wayland.rs +++ b/src/native/linux_wayland.rs @@ -128,7 +128,7 @@ impl WaylandPayload { match errno { 0 => (), libc::EPROTO => { - let mut interface: *const wl_interface = std::ptr::null(); + let mut interface: *const wl_interface = core::ptr::null(); let mut id = 0; let code = (self.client.wl_display_get_protocol_error)( self.display, @@ -188,7 +188,7 @@ impl WaylandPayload { self.client, self.xdg_toplevel, extensions::xdg_shell::xdg_toplevel::set_fullscreen, - std::ptr::null_mut::() + core::ptr::null_mut::() ); } else { wl_request!( @@ -331,17 +331,17 @@ struct PointerContext { impl PointerContext { fn new() -> Self { Self { - pointer: std::ptr::null_mut(), + pointer: core::ptr::null_mut(), enter_serial: None, position: (0., 0.), cursor_icon: Some(crate::CursorIcon::Default), queued_cursor_icon: None, - cursor_shape_manager: std::ptr::null_mut(), - cursor_shape_device: std::ptr::null_mut(), - pointer_constraints: std::ptr::null_mut(), - locked_pointer: std::ptr::null_mut(), - relative_pointer_manager: std::ptr::null_mut(), - relative_pointer: std::ptr::null_mut(), + cursor_shape_manager: core::ptr::null_mut(), + cursor_shape_device: core::ptr::null_mut(), + pointer_constraints: core::ptr::null_mut(), + locked_pointer: core::ptr::null_mut(), + relative_pointer_manager: core::ptr::null_mut(), + relative_pointer: core::ptr::null_mut(), } } unsafe fn set_cursor_with_serial( @@ -367,7 +367,7 @@ impl PointerContext { self.pointer, WL_POINTER_SET_CURSOR, serial, - std::ptr::null_mut::(), + core::ptr::null_mut::(), 0, 0 ); @@ -404,7 +404,7 @@ impl PointerContext { &extensions::cursor::zwp_locked_pointer_v1_interface, display.surface, self.pointer, - std::ptr::null_mut::(), + core::ptr::null_mut::(), extensions::cursor::zwp_pointer_constraints_v1_lifetime_PERSISTENT ); assert!(!self.locked_pointer.is_null()); @@ -438,12 +438,12 @@ impl PointerContext { if !self.locked_pointer.is_null() { wl_request!(display.client, self.locked_pointer, 0); (display.client.wl_proxy_destroy)(self.locked_pointer as _); - self.locked_pointer = std::ptr::null_mut(); + self.locked_pointer = core::ptr::null_mut(); } if !self.relative_pointer.is_null() { wl_request!(display.client, self.relative_pointer, 0); (display.client.wl_proxy_destroy)(self.relative_pointer as _); - self.relative_pointer = std::ptr::null_mut(); + self.relative_pointer = core::ptr::null_mut(); } } } @@ -553,7 +553,7 @@ unsafe extern "C" fn keyboard_handle_keymap( ) { let display: &mut WaylandPayload = &mut *(data as *mut _); let map_shm = libc::mmap( - std::ptr::null_mut::(), + core::ptr::null_mut::(), size as usize, libc::PROT_READ, libc::MAP_PRIVATE, @@ -1056,7 +1056,7 @@ where let egl = LibWaylandEgl::try_load().ok()?; let xkb = LibXkbCommon::try_load().ok()?; - let wdisplay = (client.wl_display_connect)(std::ptr::null_mut()); + let wdisplay = (client.wl_display_connect)(core::ptr::null_mut()); if wdisplay.is_null() { eprintln!("Failed to connect to Wayland display."); return None; @@ -1078,25 +1078,25 @@ where registry, egl, xkb, - compositor: std::ptr::null_mut(), - subcompositor: std::ptr::null_mut(), - xdg_toplevel: std::ptr::null_mut(), - xdg_wm_base: std::ptr::null_mut(), - surface: std::ptr::null_mut(), - viewporter: std::ptr::null_mut(), - shm: std::ptr::null_mut(), - seat: std::ptr::null_mut(), - data_device_manager: std::ptr::null_mut(), - data_device: std::ptr::null_mut(), + compositor: core::ptr::null_mut(), + subcompositor: core::ptr::null_mut(), + xdg_toplevel: core::ptr::null_mut(), + xdg_wm_base: core::ptr::null_mut(), + surface: core::ptr::null_mut(), + viewporter: core::ptr::null_mut(), + shm: core::ptr::null_mut(), + seat: core::ptr::null_mut(), + data_device_manager: core::ptr::null_mut(), + data_device: core::ptr::null_mut(), xkb_context, keymap: Default::default(), - xkb_state: std::ptr::null_mut(), - egl_window: std::ptr::null_mut(), - keyboard: std::ptr::null_mut(), - touch: std::ptr::null_mut(), + xkb_state: core::ptr::null_mut(), + egl_window: core::ptr::null_mut(), + keyboard: core::ptr::null_mut(), + touch: core::ptr::null_mut(), touch_positions: HashMap::new(), - focused_window: std::ptr::null_mut(), - decoration_manager: std::ptr::null_mut(), + focused_window: core::ptr::null_mut(), + decoration_manager: core::ptr::null_mut(), decorations: decorations::Decorations::None, events: Vec::new(), pointer_context: PointerContext::new(), @@ -1157,7 +1157,7 @@ where egl_display, config, display.egl_window as _, - std::ptr::null_mut(), + core::ptr::null_mut(), ); if egl_surface.is_null() { diff --git a/src/native/linux_wayland/extensions.rs b/src/native/linux_wayland/extensions.rs index 1bf8b2937..e8fe290ef 100644 --- a/src/native/linux_wayland/extensions.rs +++ b/src/native/linux_wayland/extensions.rs @@ -58,7 +58,7 @@ macro_rules! wayland_interface { static mut events: [wl_message; $crate::count!($($event_name)*)] = [$(wl_message { name: concat!($event_name, '\0').as_ptr() as _, signature: concat!($event_sign, '\0').as_ptr() as _, - types: std::ptr::null_mut() + types: core::ptr::null_mut() }),*]; pub static mut $name: wl_interface = wl_interface { diff --git a/src/native/linux_wayland/libwayland_client.rs b/src/native/linux_wayland/libwayland_client.rs index c3486f1be..980276a0e 100644 --- a/src/native/linux_wayland/libwayland_client.rs +++ b/src/native/linux_wayland/libwayland_client.rs @@ -681,7 +681,7 @@ macro_rules! wl_request_constructor { $instance as _, $request_name, $interface as _, - std::ptr::null_mut::(), + core::ptr::null_mut::(), $($arg,)* ); diff --git a/src/native/linux_wayland/libxkbcommon.rs b/src/native/linux_wayland/libxkbcommon.rs index fba6b47db..135eed974 100644 --- a/src/native/linux_wayland/libxkbcommon.rs +++ b/src/native/linux_wayland/libxkbcommon.rs @@ -82,7 +82,7 @@ pub mod libxkbcommon_ex { impl Default for XkbKeymap { fn default() -> Self { XkbKeymap { - xkb_keymap: std::ptr::null_mut(), + xkb_keymap: core::ptr::null_mut(), shift: 0, ctrl: 0, alt: 0, diff --git a/src/native/linux_wayland/shm.rs b/src/native/linux_wayland/shm.rs index 657b44118..5019ece7d 100644 --- a/src/native/linux_wayland/shm.rs +++ b/src/native/linux_wayland/shm.rs @@ -51,7 +51,7 @@ pub unsafe fn create_shm_buffer( panic!("Failed to create temporary file"); } let data = libc::mmap( - std::ptr::null_mut(), + core::ptr::null_mut(), length as _, libc::PROT_READ | libc::PROT_WRITE, libc::MAP_SHARED, diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index 31c9605bd..53d376da5 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -65,10 +65,10 @@ impl X11Display { let mut keysym: KeySym = 0; (self.libx11.XLookupString)( &mut event.xkey, - std::ptr::null_mut(), + core::ptr::null_mut(), 0 as libc::c_int, &mut keysym, - std::ptr::null_mut(), + core::ptr::null_mut(), ); let chr = keycodes::keysym_to_unicode(&mut self.libxkbcommon, keysym); if chr > 0 { @@ -537,7 +537,7 @@ where display.window = display .libx11 - .create_window(display.root, display.display, std::ptr::null_mut(), 0, conf); + .create_window(display.root, display.display, core::ptr::null_mut(), 0, conf); let (context, config, egl_display) = egl::create_egl_context( &mut egl_lib, @@ -548,7 +548,7 @@ where .unwrap(); let egl_surface = - (egl_lib.eglCreateWindowSurface)(egl_display, config, display.window, std::ptr::null_mut()); + (egl_lib.eglCreateWindowSurface)(egl_display, config, display.window, core::ptr::null_mut()); if egl_surface.is_null() { // == EGL_NO_SURFACE @@ -639,7 +639,7 @@ where (libx11.XInitThreads)(); (libx11.XrmInitialize)(); - let x11_display = (libx11.XOpenDisplay)(std::ptr::null()); + let x11_display = (libx11.XOpenDisplay)(core::ptr::null()); if x11_display.is_null() { panic!("XOpenDisplay() failed!"); } @@ -659,7 +659,7 @@ where // released. If DetectableAutoRepeat is not supported or has not been // requested, the server synthesizes a KeyRelease event for each // repeating KeyPress event it generates. - (libx11.XkbSetDetectableAutoRepeat)(x11_display, true as _, std::ptr::null_mut()); + (libx11.XkbSetDetectableAutoRepeat)(x11_display, true as _, core::ptr::null_mut()); libx11.load_extensions(x11_display); let mut display = X11Display { diff --git a/src/native/linux_x11/clipboard.rs b/src/native/linux_x11/clipboard.rs index b53a91ed0..bac2f5d1f 100644 --- a/src/native/linux_x11/clipboard.rs +++ b/src/native/linux_x11/clipboard.rs @@ -65,7 +65,7 @@ pub(crate) unsafe fn get_property_bytes( property: Atom, ) -> Vec { let mut bytes = Vec::new(); - let mut buf = std::ptr::null_mut::(); + let mut buf = core::ptr::null_mut::(); let mut size: libc::c_ulong = 0; let mut actual_type = 0 as Atom; let mut actual_format: libc::c_int = 0; diff --git a/src/native/linux_x11/glx.rs b/src/native/linux_x11/glx.rs index 804e80173..03f05595a 100644 --- a/src/native/linux_x11/glx.rs +++ b/src/native/linux_x11/glx.rs @@ -336,7 +336,7 @@ impl Glx { let glx_ctx = self.extensions.glxCreateContextAttribsARB.unwrap()( display, self.fbconfig, - std::ptr::null_mut(), + core::ptr::null_mut(), true as _, attribs.as_ptr(), ); @@ -344,7 +344,7 @@ impl Glx { // _sapp_x11_release_error_handler(libx11); let glx_window = - self.libgl.glxCreateWindow.unwrap()(display, self.fbconfig, window, std::ptr::null()); + self.libgl.glxCreateWindow.unwrap()(display, self.fbconfig, window, core::ptr::null()); assert!(glx_window != 0, "GLX: failed to create window"); (glx_ctx, glx_window) @@ -501,7 +501,7 @@ pub unsafe extern "C" fn gl_choose_fbconfig( let mut extra_diff; let mut least_extra_diff: i32 = 10000000; let mut current: *const GLFBConfig; - let mut closest = std::ptr::null(); + let mut closest = core::ptr::null(); for i in 0..count as i32 { current = alternatives.offset(i as isize); diff --git a/src/native/linux_x11/libx11_ex.rs b/src/native/linux_x11/libx11_ex.rs index 7a859d861..b4a152c58 100644 --- a/src/native/linux_x11/libx11_ex.rs +++ b/src/native/linux_x11/libx11_ex.rs @@ -10,9 +10,9 @@ impl LibX11 { if !db.is_null() { let mut value = XrmValue { size: 0, - addr: std::ptr::null_mut::(), + addr: core::ptr::null_mut::(), }; - let mut type_ = std::ptr::null_mut(); + let mut type_ = core::ptr::null_mut(); if (self.XrmGetResource)( db, b"Xft.dpi\x00".as_ptr() as _, @@ -74,11 +74,11 @@ impl LibX11 { window, c_title.as_ptr(), c_title.as_ptr(), - std::ptr::null_mut(), + core::ptr::null_mut(), 0 as libc::c_int, - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), + core::ptr::null_mut(), + core::ptr::null_mut(), + core::ptr::null_mut(), ); (self.XChangeProperty)( display, diff --git a/src/native/macos.rs b/src/native/macos.rs index 8bdb3d187..2b1c77433 100644 --- a/src/native/macos.rs +++ b/src/native/macos.rs @@ -407,7 +407,7 @@ unsafe fn get_proc_address(name: *const u8) -> Option { pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; } } - static mut OPENGL: *mut std::ffi::c_void = std::ptr::null_mut(); + static mut OPENGL: *mut std::ffi::c_void = core::ptr::null_mut(); if OPENGL.is_null() { OPENGL = libc::dlopen( @@ -910,7 +910,7 @@ unsafe fn set_icon(ns_app: ObjcId, icon: &Icon) { rgb, kCGBitmapByteOrderDefault | kCGImageAlphaLast, provider, - std::ptr::null(), + core::ptr::null(), false, kCGRenderingIntentDefault, ); @@ -1033,9 +1033,9 @@ where }); let mut display = MacosDisplay { - view: std::ptr::null_mut(), - window: std::ptr::null_mut(), - gl_context: std::ptr::null_mut(), + view: core::ptr::null_mut(), + window: core::ptr::null_mut(), + gl_context: core::ptr::null_mut(), fullscreen: false, occluded: false, cursor_shown: true, diff --git a/src/native/windows.rs b/src/native/windows.rs index de328aad4..4a675dd04 100644 --- a/src/native/windows.rs +++ b/src/native/windows.rs @@ -517,7 +517,7 @@ unsafe extern "system" fn win32_wndproc( WM_DROPFILES => { let hdrop = wparam as HDROP; let mut path = core::mem::MaybeUninit::<[u16; MAX_PATH]>::uninit(); - let num_drops = DragQueryFileW(hdrop, u32::MAX, std::ptr::null_mut(), 0); + let num_drops = DragQueryFileW(hdrop, u32::MAX, core::ptr::null_mut(), 0); let mut d = crate::native_display().lock().unwrap(); for i in 0..num_drops { @@ -555,25 +555,25 @@ unsafe fn create_win_icon_from_image(width: u32, height: u32, colors: &[u8]) -> bi.bV5BlueMask = 0x000000FF; bi.bV5AlphaMask = 0xFF000000; - let mut target = std::ptr::null_mut(); + let mut target = core::ptr::null_mut(); // const uint8_t* source = (const uint8_t*)desc->pixels.ptr; - let dc = GetDC(std::ptr::null_mut()); + let dc = GetDC(core::ptr::null_mut()); let color = CreateDIBSection( dc, &bi as *const _ as *const BITMAPINFO, DIB_RGB_COLORS, &mut target, - std::ptr::null_mut(), + core::ptr::null_mut(), 0, ); - ReleaseDC(std::ptr::null_mut(), dc); + ReleaseDC(core::ptr::null_mut(), dc); if color.is_null() { return None; } assert!(!target.is_null()); - let mask = CreateBitmap(width as _, height as _, 1, 1, std::ptr::null()); + let mask = CreateBitmap(width as _, height as _, 1, 1, core::ptr::null()); if mask.is_null() { DeleteObject(color as *mut _); return None; @@ -908,7 +908,7 @@ where mouse_y: 0., show_cursor: true, user_cursor: false, - cursor: std::ptr::null_mut(), + cursor: core::ptr::null_mut(), libopengl32, _msg_wnd: msg_wnd, msg_dc, diff --git a/src/native/windows/wgl.rs b/src/native/windows/wgl.rs index 923f07777..5e0a23f3b 100644 --- a/src/native/windows/wgl.rs +++ b/src/native/windows/wgl.rs @@ -422,7 +422,7 @@ impl Wgl { ]; let mut gl_ctx = self.CreateContextAttribsARB.unwrap()( display.dc, - std::ptr::null_mut(), + core::ptr::null_mut(), attrs.as_ptr() as *const _, ); @@ -441,7 +441,7 @@ impl Wgl { ]; gl_ctx = self.CreateContextAttribsARB.unwrap()( display.dc, - std::ptr::null_mut(), + core::ptr::null_mut(), attrs.as_ptr() as *const _, ); } From 0abc3261939324e68c885b98a3120262fef98039 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 11:53:54 +0200 Subject: [PATCH 02/11] `std::ffi::CStr` -> `core`, `std::ffi::CString` -> `alloc` --- src/fs.rs | 4 ++-- src/graphics/gl.rs | 4 ++-- src/lib.rs | 3 +++ src/log.rs | 4 ++-- src/native/android.rs | 8 ++++---- src/native/android/ndk_utils.rs | 10 +++++----- src/native/gl.rs | 2 +- src/native/ios.rs | 2 +- src/native/linux_wayland.rs | 6 +++--- src/native/linux_wayland/clipboard.rs | 4 ++-- src/native/linux_wayland/decorations.rs | 2 +- src/native/linux_wayland/drag_n_drop.rs | 4 ++-- src/native/linux_wayland/libxkbcommon.rs | 8 ++++---- src/native/linux_wayland/shm.rs | 2 +- src/native/linux_x11.rs | 2 +- src/native/linux_x11/glx.rs | 6 +++--- src/native/linux_x11/libx11.rs | 2 +- src/native/linux_x11/libx11_ex.rs | 4 ++-- src/native/macos.rs | 2 +- src/native/module.rs | 4 ++-- src/native/wasm.rs | 4 ++-- src/native/windows.rs | 2 +- src/native/windows/wgl.rs | 6 +++--- 23 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 2212b042a..df04c2367 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -54,7 +54,7 @@ fn load_file_android(path: &str, on_loaded: F) { fn load_file_sync(path: &str) -> Response { use crate::native; - let filename = std::ffi::CString::new(path).unwrap(); + let filename = alloc::ffi::CString::new(path).unwrap(); let mut data: native::android_asset = unsafe { std::mem::zeroed() }; @@ -111,7 +111,7 @@ mod wasm { pub fn load_file(path: &str, on_loaded: F) { use native::wasm::fs; - use std::ffi::CString; + use alloc::ffi::CString; let url = CString::new(path).unwrap(); let file_id = unsafe { fs::fs_load_file(url.as_ptr(), url.as_bytes().len() as u32) }; diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 8f62b9d52..b6c047991 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -1,4 +1,4 @@ -use std::ffi::CString; +use alloc::ffi::CString; use crate::{window, ResourceManager}; @@ -819,7 +819,7 @@ impl GlContext { #[allow(clippy::field_reassign_with_default)] fn gl_info() -> ContextInfo { let version_string = unsafe { glGetString(super::gl::GL_VERSION) }; - let gl_version_string = unsafe { std::ffi::CStr::from_ptr(version_string as _) } + let gl_version_string = unsafe { core::ffi::CStr::from_ptr(version_string as _) } .to_str() .unwrap() .to_string(); diff --git a/src/lib.rs b/src/lib.rs index 7f396c821..aafaff9b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,9 @@ clippy::missing_safety_doc )] +extern crate alloc; + + pub mod conf; mod event; pub mod fs; diff --git a/src/log.rs b/src/log.rs index 429df2995..d54eb0a91 100644 --- a/src/log.rs +++ b/src/log.rs @@ -194,7 +194,7 @@ pub fn __private_api_log_lit( &(_target, _module_path, _file, _line): &(&str, &'static str, &'static str, u32), ) { use crate::native::wasm; - use std::ffi::CString; + use alloc::ffi::CString; let log_fn = match level { Level::Debug => wasm::console_debug, @@ -214,7 +214,7 @@ pub fn __private_api_log_lit( level: Level, &(_target, _module_path, _file, _line): &(&str, &'static str, &'static str, u32), ) { - use std::ffi::CString; + use alloc::ffi::CString; let log_fn = match level { Level::Debug => crate::native::android::console_debug, diff --git a/src/native/android.rs b/src/native/android.rs index a2e4b8ed4..777d47bb3 100644 --- a/src/native/android.rs +++ b/src/native/android.rs @@ -119,7 +119,7 @@ pub unsafe fn console_error(msg: *const ::core::ffi::c_char) { } // fn log_info(message: &str) { -// use std::ffi::CString; +// use core::ptr::nulltring; // let msg = CString::new(message).unwrap_or_else(|_| panic!()); @@ -350,7 +350,7 @@ impl crate::native::Clipboard for AndroidClipboard { } fn set(&mut self, data: &str) { - let data = std::ffi::CString::new(data).unwrap(); + let data = alloc::ffi::CString::new(data).unwrap(); unsafe { let env = attach_jni_env(); @@ -373,7 +373,7 @@ where F: 'static + FnOnce() -> Box, { { - use std::ffi::CString; + use alloc::ffi::CString; use std::panic; panic::set_hook(Box::new(|info| { @@ -432,7 +432,7 @@ where assert!(!egl_config.is_null()); crate::native::gl::load_gl_funcs(|proc| { - let name = std::ffi::CString::new(proc).unwrap(); + let name = alloc::ffi::CString::new(proc).unwrap(); (libegl.eglGetProcAddress)(name.as_ptr() as _) }); diff --git a/src/native/android/ndk_utils.rs b/src/native/android/ndk_utils.rs index c50e6512c..ea8044fd1 100644 --- a/src/native/android/ndk_utils.rs +++ b/src/native/android/ndk_utils.rs @@ -12,8 +12,8 @@ macro_rules! new_object { let get_method_id = (**$env).GetMethodID.unwrap(); let new_object = (**$env).NewObject.unwrap(); - let class = std::ffi::CString::new($class).unwrap(); - let sig = std::ffi::CString::new($sig).unwrap(); + let class = alloc::ffi::CString::new($class).unwrap(); + let sig = alloc::ffi::CString::new($sig).unwrap(); let class = find_class($env, class.as_ptr() as _); let constructor = get_method_id($env, class, b"\0".as_ptr() as _, sig.as_ptr() as _); @@ -29,8 +29,8 @@ macro_rules! call_method { let get_method_id = (**$env).GetMethodID.unwrap(); let call_object_method = (**$env).$fn.unwrap(); - let method = std::ffi::CString::new($method).unwrap(); - let sig = std::ffi::CString::new($sig).unwrap(); + let method = alloc::ffi::CString::new($method).unwrap(); + let sig = alloc::ffi::CString::new($sig).unwrap(); let class = get_object_class($env, $obj); assert!(!class.is_null()); @@ -74,7 +74,7 @@ macro_rules! call_bool_method { macro_rules! get_utf_str { ($env:expr, $obj:expr) => {{ let cstr_dat = (**$env).GetStringUTFChars.unwrap()($env, $obj, core::ptr::null_mut()); - let string = std::ffi::CStr::from_ptr(cstr_dat) + let string = alloc::ffi::CStr::from_ptr(cstr_dat) .to_str() .unwrap() .to_string(); diff --git a/src/native/gl.rs b/src/native/gl.rs index 145b74034..4ecfc4e87 100644 --- a/src/native/gl.rs +++ b/src/native/gl.rs @@ -655,7 +655,7 @@ gl_loader!( // not just after context creation pub unsafe fn is_gl2() -> bool { let version_string = glGetString(super::gl::GL_VERSION); - let version_string = std::ffi::CStr::from_ptr(version_string as _) + let version_string = core::ffi::CStr::from_ptr(version_string as _) .to_str() .unwrap(); diff --git a/src/native/ios.rs b/src/native/ios.rs index eedb92fdb..e2560ab47 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -62,7 +62,7 @@ impl IosDisplay { if self.gfx_api == AppleGfxApi::OpenGl { crate::native::gl::load_gl_funcs(|proc| { - let name = std::ffi::CString::new(proc).unwrap(); + let name = alloc::ffi::CString::new(proc).unwrap(); unsafe { get_proc_address(name.as_ptr() as _) } }); diff --git a/src/native/linux_wayland.rs b/src/native/linux_wayland.rs index df9d879f5..f7ce7a8f0 100644 --- a/src/native/linux_wayland.rs +++ b/src/native/linux_wayland.rs @@ -882,7 +882,7 @@ unsafe extern "C" fn registry_add_object( ) { let display: &mut WaylandPayload = &mut *(data as *mut _); - let interface = std::ffi::CStr::from_ptr(interface).to_str().unwrap(); + let interface = core::ffi::CStr::from_ptr(interface).to_str().unwrap(); match interface { "wl_output" => { let wl_output: *mut wl_output = display.client.wl_registry_bind( @@ -1173,7 +1173,7 @@ where } crate::native::gl::load_gl_funcs(|proc| { - let name = std::ffi::CString::new(proc).unwrap(); + let name = alloc::ffi::CString::new(proc).unwrap(); (libegl.eglGetProcAddress)(name.as_ptr() as _) }); @@ -1187,7 +1187,7 @@ where conf.window_title.as_str(), ); - let wm_class = std::ffi::CString::new(conf.platform.linux_wm_class).unwrap(); + let wm_class = alloc::ffi::CString::new(conf.platform.linux_wm_class).unwrap(); wl_request!( display.client, display.xdg_toplevel, diff --git a/src/native/linux_wayland/clipboard.rs b/src/native/linux_wayland/clipboard.rs index f49c9a973..6e41be52d 100644 --- a/src/native/linux_wayland/clipboard.rs +++ b/src/native/linux_wayland/clipboard.rs @@ -33,7 +33,7 @@ impl ClipboardContext { unsafe fn get_clipboard(&mut self, mime_type: &str) -> Option> { self.data_offer.map(|data_offer| { let display: &mut WaylandPayload = &mut *self.display; - let mime_type = std::ffi::CString::new(mime_type).unwrap(); + let mime_type = alloc::ffi::CString::new(mime_type).unwrap(); display .client .data_offer_receive(display.display, data_offer, mime_type.as_ptr()) @@ -48,7 +48,7 @@ impl ClipboardContext { if let Some(serial) = display.keyboard_context.enter_serial { let data_source = self.new_data_source(); // only support copying utf8 strings - let mime_type = std::ffi::CString::new("UTF8_STRING").unwrap(); + let mime_type = alloc::ffi::CString::new("UTF8_STRING").unwrap(); wl_request!( display.client, data_source, diff --git a/src/native/linux_wayland/decorations.rs b/src/native/linux_wayland/decorations.rs index a6680ca68..a6b960cb1 100644 --- a/src/native/linux_wayland/decorations.rs +++ b/src/native/linux_wayland/decorations.rs @@ -84,7 +84,7 @@ impl Decorations { xdg_toplevel: *mut xdg_toplevel, title: &str, ) { - let title = std::ffi::CString::new(title).unwrap(); + let title = alloc::ffi::CString::new(title).unwrap(); match self { Decorations::None | Decorations::Server | Decorations::Fallback(..) => { wl_request!( diff --git a/src/native/linux_wayland/drag_n_drop.rs b/src/native/linux_wayland/drag_n_drop.rs index 42975720d..dc7fee87a 100644 --- a/src/native/linux_wayland/drag_n_drop.rs +++ b/src/native/linux_wayland/drag_n_drop.rs @@ -38,7 +38,7 @@ pub(super) unsafe extern "C" fn data_device_handle_enter( display.drag_n_drop.enter_serial = Some(serial); display.drag_n_drop.data_offer = Some(data_offer); // only accept utf8 strings - let mime_type = std::ffi::CString::new("UTF8_STRING").unwrap(); + let mime_type = alloc::ffi::CString::new("UTF8_STRING").unwrap(); wl_request!( display.client, data_offer, @@ -65,7 +65,7 @@ pub(super) unsafe extern "C" fn data_device_handle_drop( let display: &mut WaylandPayload = &mut *(data as *mut _); assert_eq!(data_device, display.data_device); if let Some(data_offer) = display.drag_n_drop.data_offer { - let mime_type = std::ffi::CString::new("UTF8_STRING").unwrap(); + let mime_type = alloc::ffi::CString::new("UTF8_STRING").unwrap(); if let Some(bytes) = display .client diff --git a/src/native/linux_wayland/libxkbcommon.rs b/src/native/linux_wayland/libxkbcommon.rs index 135eed974..8f52da812 100644 --- a/src/native/linux_wayland/libxkbcommon.rs +++ b/src/native/linux_wayland/libxkbcommon.rs @@ -93,13 +93,13 @@ pub mod libxkbcommon_ex { impl XkbKeymap { pub unsafe fn cache_mod_indices(&mut self, libxkb: &mut LibXkbCommon) { - let shift = std::ffi::CString::new(XKB_MOD_NAME_SHIFT).unwrap(); + let shift = alloc::ffi::CString::new(XKB_MOD_NAME_SHIFT).unwrap(); self.shift = (libxkb.xkb_keymap_mod_get_index)(self.xkb_keymap, shift.as_ptr()); - let ctrl = std::ffi::CString::new(XKB_MOD_NAME_CTRL).unwrap(); + let ctrl = alloc::ffi::CString::new(XKB_MOD_NAME_CTRL).unwrap(); self.ctrl = (libxkb.xkb_keymap_mod_get_index)(self.xkb_keymap, ctrl.as_ptr()); - let alt = std::ffi::CString::new(XKB_MOD_NAME_ALT).unwrap(); + let alt = alloc::ffi::CString::new(XKB_MOD_NAME_ALT).unwrap(); self.alt = (libxkb.xkb_keymap_mod_get_index)(self.xkb_keymap, alt.as_ptr()); - let logo = std::ffi::CString::new(XKB_MOD_NAME_LOGO).unwrap(); + let logo = alloc::ffi::CString::new(XKB_MOD_NAME_LOGO).unwrap(); self.logo = (libxkb.xkb_keymap_mod_get_index)(self.xkb_keymap, logo.as_ptr()); } pub unsafe fn get_keymods( diff --git a/src/native/linux_wayland/shm.rs b/src/native/linux_wayland/shm.rs index 5019ece7d..42f70ce73 100644 --- a/src/native/linux_wayland/shm.rs +++ b/src/native/linux_wayland/shm.rs @@ -20,7 +20,7 @@ unsafe extern "C" fn create_tmpfile_cloexec(tmpname: *mut libc::c_char) -> libc: unsafe extern "C" fn create_anonymous_file(size: usize) -> libc::c_int { let xdg_folder_path = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR not set"); let filepath = format!("{}/miniquad-shared-XXXXXX", xdg_folder_path); - let c_filepath = std::ffi::CString::new(filepath).unwrap(); + let c_filepath = alloc::ffi::CString::new(filepath).unwrap(); let fd = create_tmpfile_cloexec(c_filepath.as_ptr() as _); if fd < 0 { diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index 53d376da5..a558e393a 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -563,7 +563,7 @@ where } crate::native::gl::load_gl_funcs(|proc| { - let name = std::ffi::CString::new(proc).unwrap(); + let name = alloc::ffi::CString::new(proc).unwrap(); (egl_lib.eglGetProcAddress)(name.as_ptr() as _) }); diff --git a/src/native/linux_x11/glx.rs b/src/native/linux_x11/glx.rs index 03f05595a..e8cc09fa4 100644 --- a/src/native/linux_x11/glx.rs +++ b/src/native/linux_x11/glx.rs @@ -153,10 +153,10 @@ impl LibGlx { pub unsafe fn get_procaddr(&self, procname: &str) -> Option ()> { if self.glxGetProcAddress.is_some() { - let name = std::ffi::CString::new(procname).unwrap(); + let name = alloc::ffi::CString::new(procname).unwrap(); self.glxGetProcAddress.expect("non-null function pointer")(name.as_ptr() as _) } else if self.glxGetProcAddressARB.is_some() { - let name = std::ffi::CString::new(procname).unwrap(); + let name = alloc::ffi::CString::new(procname).unwrap(); self.glxGetProcAddressARB .expect("non-null function pointer")(name.as_ptr() as _) } else { @@ -241,7 +241,7 @@ impl Glx { } let exts = (libgl.glxQueryExtensionsString.unwrap())(display, screen); - let extensions = std::ffi::CStr::from_ptr(exts).to_str().unwrap().to_owned(); + let extensions = core::ffi::CStr::from_ptr(exts).to_str().unwrap().to_owned(); let multisample = extensions.contains("GLX_ARB_multisample"); // let glx_ARB_framebuffer_sRGB = diff --git a/src/native/linux_x11/libx11.rs b/src/native/linux_x11/libx11.rs index d0c49621d..7ea7966fe 100644 --- a/src/native/linux_x11/libx11.rs +++ b/src/native/linux_x11/libx11.rs @@ -837,7 +837,7 @@ macro_rules! declare_atoms { pub unsafe fn load(libx11: &mut LibX11, display: *mut Display) -> Self { Self { $($name: { - let atom = std::ffi::CString::new($atom).unwrap(); + let atom = alloc::ffi::CString::new($atom).unwrap(); (libx11.XInternAtom)(display, atom.as_ptr(), false as _) },)* } diff --git a/src/native/linux_x11/libx11_ex.rs b/src/native/linux_x11/libx11_ex.rs index b4a152c58..b60aa6abd 100644 --- a/src/native/linux_x11/libx11_ex.rs +++ b/src/native/linux_x11/libx11_ex.rs @@ -67,7 +67,7 @@ impl LibX11 { window: Window, title: &str, ) { - let c_title = std::ffi::CString::new(title).unwrap(); + let c_title = alloc::ffi::CString::new(title).unwrap(); (self.Xutf8SetWMProperties)( display, @@ -235,7 +235,7 @@ impl LibX11 { (self.XFree)(hints as *mut libc::c_void); let class_hint = (self.XAllocClassHint)(); - let wm_class = std::ffi::CString::new(conf.platform.linux_wm_class).unwrap(); + let wm_class = alloc::ffi::CString::new(conf.platform.linux_wm_class).unwrap(); (*class_hint).res_name = wm_class.as_ptr() as _; (*class_hint).res_class = wm_class.as_ptr() as _; (self.XSetClassHint)(display, window, class_hint); diff --git a/src/native/macos.rs b/src/native/macos.rs index 2b1c77433..2d9770a45 100644 --- a/src/native/macos.rs +++ b/src/native/macos.rs @@ -1124,7 +1124,7 @@ where msg_send_![display.gl_context, makeCurrentContext]; gl::load_gl_funcs(|proc| { - let name = std::ffi::CString::new(proc).unwrap(); + let name = alloc::ffi::CString::new(proc).unwrap(); get_proc_address(name.as_ptr() as _) }); diff --git a/src/native/module.rs b/src/native/module.rs index 0b8a36003..10420ecad 100644 --- a/src/native/module.rs +++ b/src/native/module.rs @@ -64,7 +64,7 @@ mod windows { impl Module { pub fn load(path: &str) -> Result { - let cpath = std::ffi::CString::new(path).unwrap(); + let cpath = alloc::ffi::CString::new(path).unwrap(); let library = unsafe { LoadLibraryA(cpath.as_ptr()) }; if library.is_null() { return Err(Error::DlOpenError(path.to_string())); @@ -72,7 +72,7 @@ mod windows { Ok(Self(library)) } pub fn get_symbol(&self, name: &str) -> Result { - let cname = std::ffi::CString::new(name).unwrap(); + let cname = alloc::ffi::CString::new(name).unwrap(); let proc = unsafe { GetProcAddress(self.0, cname.as_ptr() as *const _) }; if proc.is_null() { return Err(Error::DlSymError(name.to_string())); diff --git a/src/native/wasm.rs b/src/native/wasm.rs index 6ac297e53..c669fc30c 100644 --- a/src/native/wasm.rs +++ b/src/native/wasm.rs @@ -54,7 +54,7 @@ where F: 'static + FnOnce() -> Box, { { - use std::ffi::CString; + use alloc::ffi::CString; use std::panic; panic::set_hook(Box::new(|info| { @@ -206,7 +206,7 @@ impl crate::native::Clipboard for Clipboard { fn set(&mut self, data: &str) { let len = data.len(); - let data = std::ffi::CString::new(data).unwrap(); + let data = alloc::ffi::CString::new(data).unwrap(); unsafe { sapp_set_clipboard(data.as_ptr(), len) }; } } diff --git a/src/native/windows.rs b/src/native/windows.rs index 4a675dd04..d0df67257 100644 --- a/src/native/windows.rs +++ b/src/native/windows.rs @@ -762,7 +762,7 @@ unsafe fn create_msg_window() -> (HWND, HDC) { impl WindowsDisplay { unsafe fn get_proc_address(&mut self, proc: &str) -> Option ()> { - let proc = std::ffi::CString::new(proc).unwrap(); + let proc = alloc::ffi::CString::new(proc).unwrap(); let mut proc_ptr = (self.libopengl32.wglGetProcAddress)(proc.as_ptr()); if proc_ptr.is_null() { proc_ptr = GetProcAddress(self.libopengl32.module.0, proc.as_ptr()); diff --git a/src/native/windows/wgl.rs b/src/native/windows/wgl.rs index 5e0a23f3b..12e28b682 100644 --- a/src/native/windows/wgl.rs +++ b/src/native/windows/wgl.rs @@ -202,7 +202,7 @@ pub struct Wgl { } unsafe fn get_wgl_proc_address(libopengl32: &mut LibOpengl32, proc: &str) -> Option { - let proc = std::ffi::CString::new(proc).unwrap(); + let proc = alloc::ffi::CString::new(proc).unwrap(); let proc = (libopengl32.wglGetProcAddress)(proc.as_ptr() as *const _); if proc.is_null() { @@ -251,7 +251,7 @@ impl Wgl { let extensions = getExtensionsStringEXT(); if !extensions.is_null() { - let extensions_string = std::ffi::CStr::from_ptr(extensions).to_string_lossy(); + let extensions_string = alloc::ffi::CStr::from_ptr(extensions).to_string_lossy(); if extensions_string.contains(ext) { return true; } @@ -261,7 +261,7 @@ impl Wgl { if let Some(getExtensionsStringARB) = GetExtensionsStringARB { let extensions = getExtensionsStringARB((display.libopengl32.wglGetCurrentDC)()); if !extensions.is_null() { - let extensions_string = std::ffi::CStr::from_ptr(extensions).to_string_lossy(); + let extensions_string = alloc::ffi::CStr::from_ptr(extensions).to_string_lossy(); if extensions_string.contains(ext) { return true; From 9e62f19c374da889ea1f775d02ea6f1d3b230dce Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 11:57:48 +0200 Subject: [PATCH 03/11] `std::ffi::NulError` -> `alloc`, `std::ffi` -> `core` --- src/graphics.rs | 8 ++++---- src/graphics/metal.rs | 4 ++-- src/native/android.rs | 4 ++-- src/native/egl.rs | 2 +- src/native/ios.rs | 6 +++--- src/native/linux_wayland.rs | 20 +++++++++---------- src/native/linux_wayland/decorations.rs | 8 ++++---- src/native/linux_wayland/libwayland_client.rs | 2 +- src/native/macos.rs | 4 ++-- src/native/windows.rs | 2 +- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index dbdfffc65..03f856129 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -290,11 +290,11 @@ pub enum ShaderError { }, LinkError(String), /// Shader strings should never contains \00 in the middle - FFINulError(std::ffi::NulError), + FFINulError(alloc::ffi::NulError), } -impl From for ShaderError { - fn from(e: std::ffi::NulError) -> ShaderError { +impl From for ShaderError { + fn from(e: alloc::ffi::NulError) -> ShaderError { ShaderError::FFINulError(e) } } @@ -969,7 +969,7 @@ impl ElapsedQuery { /// Basically, the same thing as `fn f(a: &U)`, but /// trait-object friendly. pub struct Arg<'a> { - ptr: *const std::ffi::c_void, + ptr: *const core::ffi::c_void, element_size: usize, size: usize, is_slice: bool, diff --git a/src/graphics/metal.rs b/src/graphics/metal.rs index 39004579c..18d251e17 100644 --- a/src/graphics/metal.rs +++ b/src/graphics/metal.rs @@ -643,7 +643,7 @@ impl RenderingBackend for MetalContext { assert!(data.size <= buffer.size); unsafe { - let dest: *mut std::ffi::c_void = msg_send![buffer.raw[buffer.next_value], contents]; + let dest: *mut core::ffi::c_void = msg_send![buffer.raw[buffer.next_value], contents]; std::ptr::copy(data.ptr, dest, data.size); #[cfg(target_os = "macos")] @@ -1126,7 +1126,7 @@ impl RenderingBackend for MetalContext { let buffer = self.uniform_buffers[self.current_frame_index]; unsafe { - let dest: *mut std::ffi::c_void = msg_send![buffer, contents]; + let dest: *mut core::ffi::c_void = msg_send![buffer, contents]; std::ptr::copy( uniform_ptr as _, dest.add(self.current_ub_offset as usize), diff --git a/src/native/android.rs b/src/native/android.rs index 777d47bb3..90aeff5a7 100644 --- a/src/native/android.rs +++ b/src/native/android.rs @@ -19,7 +19,7 @@ pub mod ndk_utils; #[no_mangle] pub unsafe extern "C" fn JNI_OnLoad( vm: *mut ndk_sys::JavaVM, - _: std::ffi::c_void, + _: core::ffi::c_void, ) -> ndk_sys::jint { VM = vm as *mut _ as _; @@ -515,7 +515,7 @@ where } #[no_mangle] -extern "C" fn jni_on_load(vm: *mut std::ffi::c_void) { +extern "C" fn jni_on_load(vm: *mut core::ffi::c_void) { unsafe { VM = vm as _; } diff --git a/src/native/egl.rs b/src/native/egl.rs index c9e35624e..3846bc85a 100644 --- a/src/native/egl.rs +++ b/src/native/egl.rs @@ -168,7 +168,7 @@ pub struct Egl {} pub unsafe fn create_egl_context( egl: &mut LibEgl, - display: *mut std::ffi::c_void, + display: *mut core::ffi::c_void, alpha: bool, sample_count: i32, ) -> Result<(EGLContext, EGLConfig, EGLDisplay), EglError> { diff --git a/src/native/ios.rs b/src/native/ios.rs index e2560ab47..502ff8f21 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -277,7 +277,7 @@ pub fn define_glk_or_mtk_view(superclass: &Class) -> *const Class { unsafe fn get_proc_address(name: *const u8) -> Option { mod libc { - use std::ffi::{c_char, c_int, c_void}; + use core::ffi::{c_char, c_int, c_void}; pub const RTLD_LAZY: c_int = 1; extern "C" { @@ -285,7 +285,7 @@ unsafe fn get_proc_address(name: *const u8) -> Option { pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; } } - static mut OPENGL: *mut std::ffi::c_void = core::ptr::null_mut(); + static mut OPENGL: *mut core::ffi::c_void = core::ptr::null_mut(); if OPENGL.is_null() { OPENGL = libc::dlopen( @@ -576,7 +576,7 @@ pub fn define_app_delegate() -> *const Class { _gles2: view._gles2, state: state_original.clone(), }); - let payload_ptr = Box::into_raw(payload) as *mut std::ffi::c_void; + let payload_ptr = Box::into_raw(payload) as *mut core::ffi::c_void; (*view.view).set_ivar("display_ptr", payload_ptr); (*view.view_dlg).set_ivar("display_ptr", payload_ptr); diff --git a/src/native/linux_wayland.rs b/src/native/linux_wayland.rs index f7ce7a8f0..464a3e42f 100644 --- a/src/native/linux_wayland.rs +++ b/src/native/linux_wayland.rs @@ -392,7 +392,7 @@ impl PointerContext { self.queued_cursor_icon = Some(icon); } } - unsafe fn set_grab(&mut self, data: *mut std::ffi::c_void, grab: bool) { + unsafe fn set_grab(&mut self, data: *mut core::ffi::c_void, grab: bool) { let display: &mut WaylandPayload = &mut *(data as *mut _); if grab { if self.locked_pointer.is_null() { @@ -462,7 +462,7 @@ static mut RELATIVE_POINTER_LISTENER: extensions::cursor::zwp_relative_pointer_v extensions::cursor::zwp_relative_pointer_v1_listener::dummy(); unsafe extern "C" fn seat_handle_capabilities( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, seat: *mut wl_seat, caps: wl_seat_capability, ) { @@ -553,7 +553,7 @@ unsafe extern "C" fn keyboard_handle_keymap( ) { let display: &mut WaylandPayload = &mut *(data as *mut _); let map_shm = libc::mmap( - core::ptr::null_mut::(), + core::ptr::null_mut::(), size as usize, libc::PROT_READ, libc::MAP_PRIVATE, @@ -785,7 +785,7 @@ unsafe extern "C" fn relative_pointer_handle_relative_motion( } unsafe extern "C" fn output_handle_scale( - _data: *mut std::ffi::c_void, + _data: *mut core::ffi::c_void, _output: *mut wl_output, factor: core::ffi::c_int, ) { @@ -799,7 +799,7 @@ unsafe extern "C" fn output_handle_scale( } unsafe extern "C" fn touch_handle_down( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, _touch: *mut wl_touch, _serial: core::ffi::c_uint, _time: core::ffi::c_uint, @@ -825,7 +825,7 @@ unsafe extern "C" fn touch_handle_down( } unsafe extern "C" fn touch_handle_motion( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, _touch: *mut wl_touch, _time: core::ffi::c_uint, id: core::ffi::c_int, @@ -845,7 +845,7 @@ unsafe extern "C" fn touch_handle_motion( } unsafe extern "C" fn touch_handle_up( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, _touch: *mut wl_touch, _serial: core::ffi::c_uint, _time: core::ffi::c_uint, @@ -861,7 +861,7 @@ unsafe extern "C" fn touch_handle_up( } } -unsafe extern "C" fn touch_handle_cancel(data: *mut std::ffi::c_void, _touch: *mut wl_touch) { +unsafe extern "C" fn touch_handle_cancel(data: *mut core::ffi::c_void, _touch: *mut wl_touch) { let display: &mut WaylandPayload = &mut *(data as *mut _); for (id, (x, y)) in display.touch_positions.drain() { display.events.push(WaylandEvent::Touch( @@ -874,7 +874,7 @@ unsafe extern "C" fn touch_handle_cancel(data: *mut std::ffi::c_void, _touch: *m } unsafe extern "C" fn registry_add_object( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, registry: *mut wl_registry, name: u32, interface: *const ::core::ffi::c_char, @@ -1017,7 +1017,7 @@ unsafe extern "C" fn registry_add_object( } unsafe extern "C" fn xdg_wm_base_handle_ping( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, toplevel: *mut extensions::xdg_shell::xdg_wm_base, serial: u32, ) { diff --git a/src/native/linux_wayland/decorations.rs b/src/native/linux_wayland/decorations.rs index a6b960cb1..c93a26914 100644 --- a/src/native/linux_wayland/decorations.rs +++ b/src/native/linux_wayland/decorations.rs @@ -171,7 +171,7 @@ impl Decorations { } unsafe extern "C" fn xdg_surface_handle_configure( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, xdg_surface: *mut extensions::xdg_shell::xdg_surface, serial: u32, ) { @@ -187,7 +187,7 @@ unsafe extern "C" fn xdg_surface_handle_configure( wl_request!(payload.client, payload.surface, WL_SURFACE_COMMIT) } -unsafe extern "C" fn handle_configure(data: *mut std::ffi::c_void, width: i32, height: i32) { +unsafe extern "C" fn handle_configure(data: *mut core::ffi::c_void, width: i32, height: i32) { assert!(!data.is_null()); let payload: &mut WaylandPayload = &mut *(data as *mut _); @@ -237,7 +237,7 @@ unsafe extern "C" fn handle_configure(data: *mut std::ffi::c_void, width: i32, h } unsafe extern "C" fn xdg_toplevel_handle_configure( - data: *mut std::ffi::c_void, + data: *mut core::ffi::c_void, _toplevel: *mut extensions::xdg_shell::xdg_toplevel, width: i32, height: i32, @@ -277,7 +277,7 @@ unsafe extern "C" fn libdecor_frame_handle_configure( } unsafe extern "C" fn xdg_toplevel_handle_close( - _data: *mut std::ffi::c_void, + _data: *mut core::ffi::c_void, _xdg_toplevel: *mut extensions::xdg_shell::xdg_toplevel, ) { crate::native_display().try_lock().unwrap().quit_requested = true; diff --git a/src/native/linux_wayland/libwayland_client.rs b/src/native/linux_wayland/libwayland_client.rs index 980276a0e..ff1e561d6 100644 --- a/src/native/linux_wayland/libwayland_client.rs +++ b/src/native/linux_wayland/libwayland_client.rs @@ -681,7 +681,7 @@ macro_rules! wl_request_constructor { $instance as _, $request_name, $interface as _, - core::ptr::null_mut::(), + core::ptr::null_mut::(), $($arg,)* ); diff --git a/src/native/macos.rs b/src/native/macos.rs index 2d9770a45..8b0565a12 100644 --- a/src/native/macos.rs +++ b/src/native/macos.rs @@ -399,7 +399,7 @@ pub fn define_cocoa_window_delegate() -> *const Class { unsafe fn get_proc_address(name: *const u8) -> Option { mod libc { - use std::ffi::{c_char, c_int, c_void}; + use core::ffi::{c_char, c_int, c_void}; pub const RTLD_LAZY: c_int = 1; extern "C" { @@ -407,7 +407,7 @@ unsafe fn get_proc_address(name: *const u8) -> Option { pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; } } - static mut OPENGL: *mut std::ffi::c_void = core::ptr::null_mut(); + static mut OPENGL: *mut core::ffi::c_void = core::ptr::null_mut(); if OPENGL.is_null() { OPENGL = libc::dlopen( diff --git a/src/native/windows.rs b/src/native/windows.rs index d0df67257..fc2a7a2c3 100644 --- a/src/native/windows.rs +++ b/src/native/windows.rs @@ -644,7 +644,7 @@ unsafe fn create_window( wndclassw.hbrBackground = GetStockObject(BLACK_BRUSH as i32) as HBRUSH; let class_name = "MINIQUADAPP\0".encode_utf16().collect::>(); wndclassw.lpszClassName = class_name.as_ptr() as _; - wndclassw.cbWndExtra = std::mem::size_of::<*mut std::ffi::c_void>() as i32; + wndclassw.cbWndExtra = std::mem::size_of::<*mut core::ffi::c_void>() as i32; RegisterClassW(&wndclassw); let win_style: DWORD; From 3a8cae5631293749e6c701406eee9d16dc37af3b Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 11:58:41 +0200 Subject: [PATCH 04/11] `std::fmt` -> `core` --- src/conf.rs | 4 ++-- src/fs.rs | 4 ++-- src/graphics.rs | 4 ++-- src/native/egl.rs | 4 ++-- src/native/linux_x11.rs | 4 ++-- src/native/module.rs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 09a4244a1..db8725c9f 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -251,8 +251,8 @@ impl Icon { } // Printing 64x64 array with a default formatter is not meaningfull, // so debug will skip the data fields of an Icon -impl std::fmt::Debug for Icon { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Icon { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Icon").finish() } } diff --git a/src/fs.rs b/src/fs.rs index df04c2367..f1a1a5b06 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -18,8 +18,8 @@ impl From for Error { } } -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { Self::IOError(e) => write!(f, "I/O error: {e}"), Self::DownloadFailed => write!(f, "Download failed"), diff --git a/src/graphics.rs b/src/graphics.rs index 03f856129..b1ef1f2a8 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -274,7 +274,7 @@ pub enum ShaderType { } impl Display for ShaderType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Vertex => write!(f, "Vertex"), Self::Fragment => write!(f, "Fragment"), @@ -300,7 +300,7 @@ impl From for ShaderError { } impl Display for ShaderError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::CompilationError { shader_type, diff --git a/src/native/egl.rs b/src/native/egl.rs index 3846bc85a..90b60ca61 100644 --- a/src/native/egl.rs +++ b/src/native/egl.rs @@ -15,7 +15,7 @@ pub type EGLNativePixmapType = ::core::ffi::c_ulong; pub type EGLNativeWindowType = ::core::ffi::c_ulong; pub use core::ptr::null_mut; -use std::fmt::Display; +use core::fmt::Display; pub const EGL_SUCCESS: u32 = 12288; @@ -153,7 +153,7 @@ pub enum EglError { } impl Display for EglError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::NoDisplay => write!(f, "No display"), Self::InitializeFailed => write!(f, "Failed to initialize context"), diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index a558e393a..cfaaaf871 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -24,8 +24,8 @@ pub enum X11Error { LibraryNotFound(module::Error), GLXError(String), } -impl std::fmt::Display for X11Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for X11Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::LibraryNotFound(e) => write!(f, "Library not found error: {e}"), Self::GLXError(msg) => write!(f, "GLX error:\n{msg}"), diff --git a/src/native/module.rs b/src/native/module.rs index 10420ecad..5ec8710d8 100644 --- a/src/native/module.rs +++ b/src/native/module.rs @@ -5,7 +5,7 @@ pub enum Error { } impl Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::DlOpenError(msg) => write!(f, "Shared library open error:\n{msg}"), Self::DlSymError(msg) => write!(f, "Shared library symlink error:\n{msg}"), @@ -88,7 +88,7 @@ mod windows { } } -use std::fmt::Display; +use core::fmt::Display; #[cfg(any(target_os = "linux", target_os = "android"))] pub use linux::*; From ce307a80a1acfa45800d110cf329a928cb10b2ca Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 12:00:36 +0200 Subject: [PATCH 05/11] `std::mem` -> `core` and smaller modules --- examples/instancing.rs | 2 +- src/fs.rs | 2 +- src/graphics.rs | 12 +++++----- src/lib.rs | 2 +- src/native/gl.rs | 2 +- src/native/ios.rs | 2 +- src/native/linux_x11.rs | 2 +- src/native/linux_x11/clipboard.rs | 6 ++--- src/native/linux_x11/glx.rs | 6 ++--- src/native/linux_x11/libx11_ex.rs | 4 ++-- src/native/linux_x11/xi_input.rs | 2 +- src/native/macos.rs | 2 +- src/native/module.rs | 6 ++--- src/native/windows.rs | 40 +++++++++++++++---------------- src/native/windows/wgl.rs | 10 ++++---- 15 files changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/instancing.rs b/examples/instancing.rs index 4084aad3f..bc8cb379a 100644 --- a/examples/instancing.rs +++ b/examples/instancing.rs @@ -137,7 +137,7 @@ impl EventHandler for Stage { fn draw(&mut self) { // by default glam-rs can vec3 as u128 or #[reprc(C)](f32, f32, f32). need to ensure that the second option was used - assert_eq!(std::mem::size_of::(), 12); + assert_eq!(core::mem::size_of::(), 12); self.ctx.buffer_update( self.bindings.vertex_buffers[1], diff --git a/src/fs.rs b/src/fs.rs index f1a1a5b06..cfdd6c610 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -56,7 +56,7 @@ fn load_file_android(path: &str, on_loaded: F) { let filename = alloc::ffi::CString::new(path).unwrap(); - let mut data: native::android_asset = unsafe { std::mem::zeroed() }; + let mut data: native::android_asset = unsafe { core::mem::zeroed() }; unsafe { native::android::load_asset(filename.as_ptr(), &mut data as _) }; diff --git a/src/graphics.rs b/src/graphics.rs index b1ef1f2a8..9871375ac 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -997,9 +997,9 @@ impl<'a> BufferSource<'a> { /// /// For vertex buffers it is OK to use `empty::(byte_size);` pub fn empty(size: usize) -> BufferSource<'a> { - let element_size = std::mem::size_of::(); + let element_size = core::mem::size_of::(); BufferSource::Empty { - size: size * std::mem::size_of::(), + size: size * core::mem::size_of::(), element_size, } } @@ -1007,8 +1007,8 @@ impl<'a> BufferSource<'a> { pub fn slice(data: &'a [T]) -> BufferSource<'a> { BufferSource::Slice(Arg { ptr: data.as_ptr() as _, - size: std::mem::size_of_val(data), - element_size: std::mem::size_of::(), + size: core::mem::size_of_val(data), + element_size: core::mem::size_of::(), is_slice: true, _phantom: std::marker::PhantomData, }) @@ -1030,8 +1030,8 @@ impl<'a> UniformsSource<'a> { pub fn table(data: &'a T) -> UniformsSource<'a> { Self(Arg { ptr: data as *const T as _, - size: std::mem::size_of_val(data), - element_size: std::mem::size_of::(), + size: core::mem::size_of_val(data), + element_size: core::mem::size_of::(), is_slice: false, _phantom: std::marker::PhantomData, }) diff --git a/src/lib.rs b/src/lib.rs index aafaff9b4..3d185a034 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub mod fs; pub mod graphics; pub mod native; use std::collections::HashMap; -use std::ops::{Index, IndexMut}; +use core::ops::{Index, IndexMut}; #[cfg(feature = "log-impl")] pub mod log; diff --git a/src/native/gl.rs b/src/native/gl.rs index 4ecfc4e87..126088a96 100644 --- a/src/native/gl.rs +++ b/src/native/gl.rs @@ -329,7 +329,7 @@ macro_rules! gl_loader { $( unsafe { let fn_name = stringify!($fn); - __pfns::$fn = ::std::mem::transmute_copy(&getprocaddr(fn_name)); + __pfns::$fn = ::core::mem::transmute_copy(&getprocaddr(fn_name)); } )* } diff --git a/src/native/ios.rs b/src/native/ios.rs index 502ff8f21..330dfc242 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -300,7 +300,7 @@ unsafe fn get_proc_address(name: *const u8) -> Option { if symbol.is_null() { return None; } - Some(unsafe { std::mem::transmute_copy(&symbol) }) + Some(unsafe { core::mem::transmute_copy(&symbol) }) } pub fn define_glk_or_mtk_view_dlg(superclass: &Class) -> *const Class { diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index cfaaaf871..f8c370aeb 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -306,7 +306,7 @@ impl X11Display { display: self.display, format: 32, data: ClientMessageData { - l: std::mem::transmute(data), + l: core::mem::transmute(data), }, }; (self.libx11.XSendEvent)( diff --git a/src/native/linux_x11/clipboard.rs b/src/native/linux_x11/clipboard.rs index bac2f5d1f..94d18be61 100644 --- a/src/native/linux_x11/clipboard.rs +++ b/src/native/linux_x11/clipboard.rs @@ -96,9 +96,9 @@ pub(crate) unsafe fn get_property_bytes( return bytes; } else { let n_bits = match actual_format { - 8 => std::mem::size_of::(), - 16 => std::mem::size_of::(), - 32 => std::mem::size_of::(), + 8 => core::mem::size_of::(), + 16 => core::mem::size_of::(), + 32 => core::mem::size_of::(), _ => unreachable!(), }; bytes.extend(std::slice::from_raw_parts( diff --git a/src/native/linux_x11/glx.rs b/src/native/linux_x11/glx.rs index e8cc09fa4..9fccb63ba 100644 --- a/src/native/linux_x11/glx.rs +++ b/src/native/linux_x11/glx.rs @@ -289,18 +289,18 @@ impl Glx { }; if extensions_string.contains("GLX_EXT_swap_control") { extensions.glxSwapIntervalExt = - std::mem::transmute_copy(&libgl.get_procaddr("glXSwapIntervalEXT")); + core::mem::transmute_copy(&libgl.get_procaddr("glXSwapIntervalEXT")); } if extensions_string.contains("GLX_MESA_swap_control") { extensions.glxSwapIntervalMesa = - std::mem::transmute_copy(&libgl.get_procaddr("glXSwapIntervalMESA")); + core::mem::transmute_copy(&libgl.get_procaddr("glXSwapIntervalMESA")); } if extensions_string.contains("GLX_ARB_create_context") && extensions_string.contains("GLX_ARB_create_context_profile") { extensions.glxCreateContextAttribsARB = - std::mem::transmute_copy(&libgl.get_procaddr("glXCreateContextAttribsARB")) + core::mem::transmute_copy(&libgl.get_procaddr("glXCreateContextAttribsARB")) }; Ok(Glx { diff --git a/src/native/linux_x11/libx11_ex.rs b/src/native/linux_x11/libx11_ex.rs index b60aa6abd..9f0bead66 100644 --- a/src/native/linux_x11/libx11_ex.rs +++ b/src/native/linux_x11/libx11_ex.rs @@ -56,7 +56,7 @@ impl LibX11 { display: *mut Display, window: Window, ) -> (i32, i32) { - let mut attribs: XWindowAttributes = std::mem::zeroed(); + let mut attribs: XWindowAttributes = core::mem::zeroed(); (self.XGetWindowAttributes)(display, window, &mut attribs); (attribs.width, attribs.height) } @@ -179,7 +179,7 @@ impl LibX11 { libc::memset( &mut wa as *mut XSetWindowAttributes as *mut libc::c_void, 0 as libc::c_int, - ::std::mem::size_of::() as _, + ::core::mem::size_of::() as _, ); let wamask = (CWBorderPixel | CWColormap | CWEventMask) as u32; diff --git a/src/native/linux_x11/xi_input.rs b/src/native/linux_x11/xi_input.rs index a5e620566..b5c403542 100644 --- a/src/native/linux_x11/xi_input.rs +++ b/src/native/linux_x11/xi_input.rs @@ -94,7 +94,7 @@ impl LibXi { let mut mask = XI_RawMotionMask; let mut masks = XIEventMask { deviceid: XIAllDevices, - mask_len: ::std::mem::size_of::() as _, + mask_len: ::core::mem::size_of::() as _, mask: &mut mask as *mut _ as *mut _, }; diff --git a/src/native/macos.rs b/src/native/macos.rs index 8b0565a12..85475d840 100644 --- a/src/native/macos.rs +++ b/src/native/macos.rs @@ -422,7 +422,7 @@ unsafe fn get_proc_address(name: *const u8) -> Option { if symbol.is_null() { return None; } - Some(unsafe { std::mem::transmute_copy(&symbol) }) + Some(unsafe { core::mem::transmute_copy(&symbol) }) } // methods for both metal or OPENGL view diff --git a/src/native/module.rs b/src/native/module.rs index 5ec8710d8..e3fc61874 100644 --- a/src/native/module.rs +++ b/src/native/module.rs @@ -41,7 +41,7 @@ pub mod linux { if symbol.is_null() { return Err(Error::DlSymError(name.to_string())); } - Ok(unsafe { std::mem::transmute_copy::<_, F>(&symbol) }) + Ok(unsafe { core::mem::transmute_copy::<_, F>(&symbol) }) } } @@ -77,7 +77,7 @@ mod windows { if proc.is_null() { return Err(Error::DlSymError(name.to_string())); } - Ok(unsafe { std::mem::transmute_copy(&proc) }) + Ok(unsafe { core::mem::transmute_copy(&proc) }) } } @@ -115,7 +115,7 @@ macro_rules! declare_module { $($vis:vis $field:ident: $field_ty:ty,)*) => { #[derive(Clone)] pub struct $name { - _module: std::rc::Rc<$crate::native::module::Module>, + _module: alloc::rc::Rc<$crate::native::module::Module>, $($s_vis $s_name: $s_type,)* $($f_vis $f_name: unsafe extern "C" fn ($($f_arg),*)$( -> $f_ret)?,)* $($v_vis $v_name: unsafe extern "C" fn ($($v_arg),*, ...)$( -> $v_ret)?,)* diff --git a/src/native/windows.rs b/src/native/windows.rs index fc2a7a2c3..c31c91ebe 100644 --- a/src/native/windows.rs +++ b/src/native/windows.rs @@ -98,7 +98,7 @@ impl WindowsDisplay { let mut final_new_width = new_width; let mut final_new_height = new_height; - let mut rect: RECT = unsafe { std::mem::zeroed() }; + let mut rect: RECT = unsafe { core::mem::zeroed() }; if unsafe { GetClientRect(self.wnd, &mut rect as *mut _ as _) } != 0 { x = rect.left; y = rect.bottom; @@ -136,7 +136,7 @@ impl WindowsDisplay { } /// Set the window position in screen coordinates. fn set_window_position(&mut self, new_x: u32, new_y: u32) { - let mut rect: RECT = unsafe { std::mem::zeroed() }; + let mut rect: RECT = unsafe { core::mem::zeroed() }; if unsafe { GetClientRect(self.wnd, &mut rect as *mut _ as _) } != 0 { let mut new_rect = rect; new_rect.right = new_rect.right - new_rect.left + new_x as i32; @@ -217,7 +217,7 @@ fn get_win_style(is_fullscreen: bool, is_resizable: bool) -> DWORD { unsafe fn update_clip_rect(hwnd: HWND) { // Retrieve the screen coordinates of the client area, // and convert them into client coordinates. - let mut rect: RECT = std::mem::zeroed(); + let mut rect: RECT = core::mem::zeroed(); GetClientRect(hwnd, &mut rect as *mut _ as _); let mut upper_left = POINT { @@ -391,9 +391,9 @@ unsafe extern "system" fn win32_wndproc( // if !_sapp.win32_mouse_tracked { // _sapp.win32_mouse_tracked = true; - // let mut tme: TRACKMOUSEEVENT = std::mem::zeroed(); + // let mut tme: TRACKMOUSEEVENT = core::mem::zeroed(); - // tme.cbSize = std::mem::size_of_val(&tme) as _; + // tme.cbSize = core::mem::size_of_val(&tme) as _; // tme.dwFlags = TME_LEAVE; // tme.hwndTrack = wnd; // TrackMouseEvent(&mut tme as *mut _); @@ -414,14 +414,14 @@ unsafe extern "system" fn win32_wndproc( } WM_INPUT => { - let mut data: RAWINPUT = std::mem::zeroed(); - let mut size = std::mem::size_of::(); + let mut data: RAWINPUT = core::mem::zeroed(); + let mut size = core::mem::size_of::(); let get_succeed = GetRawInputData( lparam as _, RID_INPUT, &mut data as *mut _ as _, &mut size as *mut _ as _, - std::mem::size_of::() as _, + core::mem::size_of::() as _, ); if get_succeed as i32 == -1 { panic!("failed to retrieve raw input data"); @@ -542,9 +542,9 @@ unsafe extern "system" fn win32_wndproc( } unsafe fn create_win_icon_from_image(width: u32, height: u32, colors: &[u8]) -> Option { - let mut bi: BITMAPV5HEADER = std::mem::zeroed(); + let mut bi: BITMAPV5HEADER = core::mem::zeroed(); - bi.bV5Size = std::mem::size_of::() as _; + bi.bV5Size = core::mem::size_of::() as _; bi.bV5Width = width as i32; bi.bV5Height = -(height as i32); // NOTE the '-' here to indicate that origin is top-left bi.bV5Planes = 1; @@ -586,7 +586,7 @@ unsafe fn create_win_icon_from_image(width: u32, height: u32, colors: &[u8]) -> *(target as *mut u8).offset(i as isize * 4 + 3) = colors[i * 4 + 3]; } - let mut icon_info: ICONINFO = std::mem::zeroed(); + let mut icon_info: ICONINFO = core::mem::zeroed(); icon_info.fIcon = 1; icon_info.xHotspot = 0; icon_info.yHotspot = 0; @@ -634,7 +634,7 @@ unsafe fn create_window( width: i32, height: i32, ) -> (HWND, HDC) { - let mut wndclassw: WNDCLASSW = std::mem::zeroed(); + let mut wndclassw: WNDCLASSW = core::mem::zeroed(); wndclassw.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wndclassw.lpfnWndProc = Some(win32_wndproc); @@ -644,7 +644,7 @@ unsafe fn create_window( wndclassw.hbrBackground = GetStockObject(BLACK_BRUSH as i32) as HBRUSH; let class_name = "MINIQUADAPP\0".encode_utf16().collect::>(); wndclassw.lpszClassName = class_name.as_ptr() as _; - wndclassw.cbWndExtra = std::mem::size_of::<*mut core::ffi::c_void>() as i32; + wndclassw.cbWndExtra = core::mem::size_of::<*mut core::ffi::c_void>() as i32; RegisterClassW(&wndclassw); let win_style: DWORD; @@ -699,14 +699,14 @@ unsafe fn create_window( ); assert!(!hwnd.is_null()); - let mut rawinputdevice: RAWINPUTDEVICE = std::mem::zeroed(); + let mut rawinputdevice: RAWINPUTDEVICE = core::mem::zeroed(); rawinputdevice.usUsagePage = HID_USAGE_PAGE_GENERIC; rawinputdevice.usUsage = HID_USAGE_GENERIC_MOUSE; rawinputdevice.hwndTarget = NULL as _; let register_succeed = RegisterRawInputDevices( &rawinputdevice as *const _, 1, - std::mem::size_of::() as _, + core::mem::size_of::() as _, ); assert!( register_succeed == 1, @@ -746,7 +746,7 @@ unsafe fn create_msg_window() -> (HWND, HDC) { "Win32: failed to create helper window!" ); ShowWindow(msg_hwnd, SW_HIDE); - let mut msg = std::mem::zeroed(); + let mut msg = core::mem::zeroed(); while PeekMessageW(&mut msg as _, msg_hwnd, 0, 0, PM_REMOVE) != 0 { TranslateMessage(&msg); DispatchMessageW(&msg); @@ -771,7 +771,7 @@ impl WindowsDisplay { eprintln!("Load GL func {:?} failed.", proc); return None; } - Some(std::mem::transmute::< + Some(core::mem::transmute::< *mut winapi::shared::minwindef::__some_function, unsafe extern "C" fn(), >(proc_ptr)) @@ -782,12 +782,12 @@ impl WindowsDisplay { /// returns true if size or position has changed unsafe fn update_dimensions(&mut self, hwnd: HWND) -> bool { let mut d = crate::native_display().lock().unwrap(); - let mut rect: RECT = std::mem::zeroed(); + let mut rect: RECT = core::mem::zeroed(); // Get the outer rectangle of the window in screen coordinates if GetWindowRect(hwnd, &mut rect as *mut _ as _) != 0 { // Get the client area rectangle in client coordinates - let mut client_rect: RECT = std::mem::zeroed(); + let mut client_rect: RECT = core::mem::zeroed(); if GetClientRect(hwnd, &mut client_rect as *mut _ as _) != 0 { // Calculate window width and height based on the client area let window_width = @@ -961,7 +961,7 @@ where DispatchMessageW(&mut msg as *mut _ as _); } }; - let mut msg: MSG = std::mem::zeroed(); + let mut msg: MSG = core::mem::zeroed(); let block_on_wait = conf.platform.blocking_event_loop && !display.update_requested; if block_on_wait { GetMessageW(&mut msg as *mut _ as _, NULL as _, 0, 0); diff --git a/src/native/windows/wgl.rs b/src/native/windows/wgl.rs index 12e28b682..0d27814fb 100644 --- a/src/native/windows/wgl.rs +++ b/src/native/windows/wgl.rs @@ -208,13 +208,13 @@ unsafe fn get_wgl_proc_address(libopengl32: &mut LibOpengl32, proc: &str) -> if proc.is_null() { return None; } - Some(std::mem::transmute_copy(&proc)) + Some(core::mem::transmute_copy(&proc)) } impl Wgl { pub(crate) unsafe fn new(display: &mut WindowsDisplay) -> Wgl { - let mut pfd: PIXELFORMATDESCRIPTOR = std::mem::zeroed(); - pfd.nSize = std::mem::size_of_val(&pfd) as _; + let mut pfd: PIXELFORMATDESCRIPTOR = core::mem::zeroed(); + pfd.nSize = core::mem::size_of_val(&pfd) as _; pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; @@ -384,11 +384,11 @@ impl Wgl { if 0 == pixel_format { panic!("WGL: Didn't find matching pixel format."); } - let mut pfd: PIXELFORMATDESCRIPTOR = std::mem::zeroed(); + let mut pfd: PIXELFORMATDESCRIPTOR = core::mem::zeroed(); if DescribePixelFormat( display.dc, pixel_format as _, - std::mem::size_of_val(&pfd) as _, + core::mem::size_of_val(&pfd) as _, &mut pfd as *mut _ as _, ) == 0 { From daecb0f1c34e17ce3e251001c17ed0977be58cac Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 12:02:57 +0200 Subject: [PATCH 06/11] `std::str` -> `core`, `std::string` -> `alloc` --- src/graphics/gl.rs | 4 ++-- src/native/apple/apple_util.rs | 2 +- src/native/linux_wayland/clipboard.rs | 2 +- src/native/linux_x11.rs | 2 +- src/native/linux_x11/clipboard.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index b6c047991..5a8759bba 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -613,7 +613,7 @@ fn load_shader_internal( ); assert!(max_length >= 1); let error_message = - std::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1]); + alloc::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1]); return Err(ShaderError::LinkError(error_message.to_string())); } @@ -669,7 +669,7 @@ pub fn load_shader(shader_type: GLenum, source: &str) -> Result= 1); let mut error_message = - std::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1]) + alloc::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1]) .into_owned(); // On Wasm + Chrome, for unknown reason, string with zero-terminator is returned. On Firefox there is no zero-terminators in JavaScript string. diff --git a/src/native/apple/apple_util.rs b/src/native/apple/apple_util.rs index 576cb5b97..c63c61c6e 100644 --- a/src/native/apple/apple_util.rs +++ b/src/native/apple/apple_util.rs @@ -15,7 +15,7 @@ pub fn nsstring_to_string(string: ObjcId) -> String { let utf8_string: *const core::ffi::c_uchar = msg_send![string, UTF8String]; let utf8_len: usize = msg_send![string, lengthOfBytesUsingEncoding: UTF8_ENCODING]; let slice = std::slice::from_raw_parts(utf8_string, utf8_len); - std::str::from_utf8_unchecked(slice).to_owned() + core::str::from_utf8_unchecked(slice).to_owned() } } diff --git a/src/native/linux_wayland/clipboard.rs b/src/native/linux_wayland/clipboard.rs index 6e41be52d..a2c410088 100644 --- a/src/native/linux_wayland/clipboard.rs +++ b/src/native/linux_wayland/clipboard.rs @@ -157,7 +157,7 @@ impl WaylandClipboard { impl crate::native::Clipboard for WaylandClipboard { fn get(&mut self) -> Option { let bytes = unsafe { CLIPBOARD.get_mut().unwrap().get_clipboard("UTF8_STRING")? }; - Some(std::str::from_utf8(&bytes).ok()?.to_string()) + Some(core::str::from_utf8(&bytes).ok()?.to_string()) } fn set(&mut self, data: &str) { unsafe { diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index f8c370aeb..42311ca64 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -197,7 +197,7 @@ impl X11Display { self.window, p, ); - if let Ok(filenames) = std::str::from_utf8(&bytes) { + if let Ok(filenames) = core::str::from_utf8(&bytes) { let mut d = crate::native_display().try_lock().unwrap(); d.dropped_files = Default::default(); for filename in filenames.lines() { diff --git a/src/native/linux_x11/clipboard.rs b/src/native/linux_x11/clipboard.rs index 94d18be61..a7352a9fa 100644 --- a/src/native/linux_x11/clipboard.rs +++ b/src/native/linux_x11/clipboard.rs @@ -231,7 +231,7 @@ impl crate::native::Clipboard for X11Clipboard { let utf8_string = self.libx11.extensions.utf8_string; let bytes = unsafe { get_clipboard(&mut self.libx11, self.display, self.window, utf8_string)? }; - Some(std::str::from_utf8(&bytes).ok()?.to_string()) + Some(core::str::from_utf8(&bytes).ok()?.to_string()) } fn set(&mut self, data: &str) { From e3861372fa71c01113975d4696b00b0aee8d97c4 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 12:05:41 +0200 Subject: [PATCH 07/11] all smaller remaining substitutions --- src/fs.rs | 2 +- src/graphics.rs | 10 +++++----- src/native/apple/apple_util.rs | 2 +- src/native/egl.rs | 2 +- src/native/ios.rs | 2 +- src/native/linux_x11/clipboard.rs | 2 +- src/native/module.rs | 6 ++---- src/native/windows/clipboard.rs | 2 +- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index cfdd6c610..f2360c8c4 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -62,7 +62,7 @@ fn load_file_android(path: &str, on_loaded: F) { if data.content.is_null() == false { let slice = - unsafe { std::slice::from_raw_parts(data.content, data.content_length as _) }; + unsafe { core::slice::from_raw_parts(data.content, data.content_length as _) }; let response = slice.iter().map(|c| *c as _).collect::>(); Ok(response) } else { diff --git a/src/graphics.rs b/src/graphics.rs index 9871375ac..ec77c5c6e 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -2,7 +2,7 @@ use crate::native::gl::*; -use std::{error::Error, fmt::Display}; +use core::{error::Error, fmt::Display}; //pub use texture::{FilterMode, TextureAccess, TextureFormat, TextureParams, TextureWrap}; @@ -973,7 +973,7 @@ pub struct Arg<'a> { element_size: usize, size: usize, is_slice: bool, - _phantom: std::marker::PhantomData<&'a ()>, + _phantom: core::marker::PhantomData<&'a ()>, } pub enum TextureSource<'a> { @@ -1010,7 +1010,7 @@ impl<'a> BufferSource<'a> { size: core::mem::size_of_val(data), element_size: core::mem::size_of::(), is_slice: true, - _phantom: std::marker::PhantomData, + _phantom: core::marker::PhantomData, }) } @@ -1020,7 +1020,7 @@ impl<'a> BufferSource<'a> { size, element_size, is_slice: true, - _phantom: std::marker::PhantomData, + _phantom: core::marker::PhantomData, }) } } @@ -1033,7 +1033,7 @@ impl<'a> UniformsSource<'a> { size: core::mem::size_of_val(data), element_size: core::mem::size_of::(), is_slice: false, - _phantom: std::marker::PhantomData, + _phantom: core::marker::PhantomData, }) } } diff --git a/src/native/apple/apple_util.rs b/src/native/apple/apple_util.rs index c63c61c6e..38286e624 100644 --- a/src/native/apple/apple_util.rs +++ b/src/native/apple/apple_util.rs @@ -14,7 +14,7 @@ pub fn nsstring_to_string(string: ObjcId) -> String { unsafe { let utf8_string: *const core::ffi::c_uchar = msg_send![string, UTF8String]; let utf8_len: usize = msg_send![string, lengthOfBytesUsingEncoding: UTF8_ENCODING]; - let slice = std::slice::from_raw_parts(utf8_string, utf8_len); + let slice = core::slice::from_raw_parts(utf8_string, utf8_len); core::str::from_utf8_unchecked(slice).to_owned() } } diff --git a/src/native/egl.rs b/src/native/egl.rs index 90b60ca61..da7525ea7 100644 --- a/src/native/egl.rs +++ b/src/native/egl.rs @@ -44,7 +44,7 @@ pub type EGLDisplay = *mut ::core::ffi::c_void; pub type EGLConfig = *mut ::core::ffi::c_void; pub type EGLSurface = *mut ::core::ffi::c_void; pub type EGLContext = *mut ::core::ffi::c_void; -pub type __eglMustCastToProperFunctionPointerType = ::std::option::Option; +pub type __eglMustCastToProperFunctionPointerType = ::core::option::Option; crate::declare_module! { LibEgl, diff --git a/src/native/ios.rs b/src/native/ios.rs index 330dfc242..e2549acf7 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -814,7 +814,7 @@ pub fn load_file(path: &str, on_loaded: F) return; } let length: usize = msg_send![file_data, length]; - let slice = std::slice::from_raw_parts(bytes, length); + let slice = core::slice::from_raw_parts(bytes, length); on_loaded(Ok(slice.to_vec())) } } diff --git a/src/native/linux_x11/clipboard.rs b/src/native/linux_x11/clipboard.rs index a7352a9fa..bd958582d 100644 --- a/src/native/linux_x11/clipboard.rs +++ b/src/native/linux_x11/clipboard.rs @@ -101,7 +101,7 @@ pub(crate) unsafe fn get_property_bytes( 32 => core::mem::size_of::(), _ => unreachable!(), }; - bytes.extend(std::slice::from_raw_parts( + bytes.extend(core::slice::from_raw_parts( buf as *const _, n_bits * size as usize, )); diff --git a/src/native/module.rs b/src/native/module.rs index e3fc61874..f4286440b 100644 --- a/src/native/module.rs +++ b/src/native/module.rs @@ -16,11 +16,9 @@ impl Display for Error { #[cfg(any(target_os = "linux", target_os = "android"))] pub mod linux { use super::Error; + use alloc::ffi::CString; + use core::{ffi::c_void, ptr::NonNull}; use libc::{dlclose, dlopen, dlsym, RTLD_LAZY, RTLD_LOCAL}; - use std::{ - ffi::{c_void, CString}, - ptr::NonNull, - }; pub struct Module(NonNull); diff --git a/src/native/windows/clipboard.rs b/src/native/windows/clipboard.rs index 630ac7dca..20579114e 100644 --- a/src/native/windows/clipboard.rs +++ b/src/native/windows/clipboard.rs @@ -47,7 +47,7 @@ unsafe fn get_raw_clipboard() -> Option> { } let data_size = GlobalSize(clipboard_data) as usize; - let slice = std::slice::from_raw_parts(data_ptr, data_size); + let slice = core::slice::from_raw_parts(data_ptr, data_size); let len = slice.iter().position(|b| *b == 0).unwrap_or(data_size); // search for the first null byte to see where the string ends. From 11a6d4def9981e2552c9c99873da4663ae571c50 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 12:09:32 +0200 Subject: [PATCH 08/11] fix mistake --- src/native/android/ndk_utils.rs | 2 +- src/native/windows/wgl.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/native/android/ndk_utils.rs b/src/native/android/ndk_utils.rs index ea8044fd1..1bc444a08 100644 --- a/src/native/android/ndk_utils.rs +++ b/src/native/android/ndk_utils.rs @@ -74,7 +74,7 @@ macro_rules! call_bool_method { macro_rules! get_utf_str { ($env:expr, $obj:expr) => {{ let cstr_dat = (**$env).GetStringUTFChars.unwrap()($env, $obj, core::ptr::null_mut()); - let string = alloc::ffi::CStr::from_ptr(cstr_dat) + let string = core::ffi::CStr::from_ptr(cstr_dat) .to_str() .unwrap() .to_string(); diff --git a/src/native/windows/wgl.rs b/src/native/windows/wgl.rs index 0d27814fb..ad8ee9dbf 100644 --- a/src/native/windows/wgl.rs +++ b/src/native/windows/wgl.rs @@ -251,7 +251,7 @@ impl Wgl { let extensions = getExtensionsStringEXT(); if !extensions.is_null() { - let extensions_string = alloc::ffi::CStr::from_ptr(extensions).to_string_lossy(); + let extensions_string = core::ffi::CStr::from_ptr(extensions).to_string_lossy(); if extensions_string.contains(ext) { return true; } @@ -261,7 +261,7 @@ impl Wgl { if let Some(getExtensionsStringARB) = GetExtensionsStringARB { let extensions = getExtensionsStringARB((display.libopengl32.wglGetCurrentDC)()); if !extensions.is_null() { - let extensions_string = alloc::ffi::CStr::from_ptr(extensions).to_string_lossy(); + let extensions_string = core::ffi::CStr::from_ptr(extensions).to_string_lossy(); if extensions_string.contains(ext) { return true; From 6a3c513cf04d9c201ef2a06c2b92fb843aaec93a Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 12:56:25 +0200 Subject: [PATCH 09/11] cargo fmt, swap `core::error::Error` back to `std` for MSRV --- src/fs.rs | 2 +- src/graphics.rs | 3 ++- src/graphics/gl.rs | 7 ++++++- src/lib.rs | 3 +-- src/native/egl.rs | 2 +- src/native/linux_x11.rs | 19 +++++++++++++------ 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index f2360c8c4..bf9bda1ec 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -110,8 +110,8 @@ mod wasm { } pub fn load_file(path: &str, on_loaded: F) { - use native::wasm::fs; use alloc::ffi::CString; + use native::wasm::fs; let url = CString::new(path).unwrap(); let file_id = unsafe { fs::fs_load_file(url.as_ptr(), url.as_bytes().len() as u32) }; diff --git a/src/graphics.rs b/src/graphics.rs index ec77c5c6e..b69b7aa47 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -2,7 +2,8 @@ use crate::native::gl::*; -use core::{error::Error, fmt::Display}; +use core::fmt::Display; +use std::error::Error; //pub use texture::{FilterMode, TextureAccess, TextureFormat, TextureParams, TextureWrap}; diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 5a8759bba..b53f2efc6 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -1365,7 +1365,12 @@ impl RenderingBackend for GlContext { self.cache.store_buffer_binding(gl_target); self.cache.bind_buffer(gl_target, gl_buf, index_type); - glBufferData(gl_target, size as _, core::ptr::null() as *const _, gl_usage); + glBufferData( + gl_target, + size as _, + core::ptr::null() as *const _, + gl_usage, + ); if let BufferSource::Slice(data) = data { debug_assert!(data.is_slice); glBufferSubData(gl_target, 0, size as _, data.ptr as _); diff --git a/src/lib.rs b/src/lib.rs index 3d185a034..beb96fe5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,14 +9,13 @@ extern crate alloc; - pub mod conf; mod event; pub mod fs; pub mod graphics; pub mod native; -use std::collections::HashMap; use core::ops::{Index, IndexMut}; +use std::collections::HashMap; #[cfg(feature = "log-impl")] pub mod log; diff --git a/src/native/egl.rs b/src/native/egl.rs index da7525ea7..99e6716e8 100644 --- a/src/native/egl.rs +++ b/src/native/egl.rs @@ -14,8 +14,8 @@ pub type EGLNativePixmapType = ::core::ffi::c_ulong; #[cfg(target_os = "android")] pub type EGLNativeWindowType = ::core::ffi::c_ulong; -pub use core::ptr::null_mut; use core::fmt::Display; +pub use core::ptr::null_mut; pub const EGL_SUCCESS: u32 = 12288; diff --git a/src/native/linux_x11.rs b/src/native/linux_x11.rs index 42311ca64..4dc0580b2 100644 --- a/src/native/linux_x11.rs +++ b/src/native/linux_x11.rs @@ -534,10 +534,13 @@ where _ => return Err(display), }; - display.window = - display - .libx11 - .create_window(display.root, display.display, core::ptr::null_mut(), 0, conf); + display.window = display.libx11.create_window( + display.root, + display.display, + core::ptr::null_mut(), + 0, + conf, + ); let (context, config, egl_display) = egl::create_egl_context( &mut egl_lib, @@ -547,8 +550,12 @@ where ) .unwrap(); - let egl_surface = - (egl_lib.eglCreateWindowSurface)(egl_display, config, display.window, core::ptr::null_mut()); + let egl_surface = (egl_lib.eglCreateWindowSurface)( + egl_display, + config, + display.window, + core::ptr::null_mut(), + ); if egl_surface.is_null() { // == EGL_NO_SURFACE From 7e1f2521392c366e1bcbb74087424a9f91994563 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 21:34:20 +0200 Subject: [PATCH 10/11] `std::ptr` -> `core` --- src/graphics/metal.rs | 4 ++-- src/native/windows/clipboard.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graphics/metal.rs b/src/graphics/metal.rs index 18d251e17..55f5fa611 100644 --- a/src/graphics/metal.rs +++ b/src/graphics/metal.rs @@ -644,7 +644,7 @@ impl RenderingBackend for MetalContext { unsafe { let dest: *mut core::ffi::c_void = msg_send![buffer.raw[buffer.next_value], contents]; - std::ptr::copy(data.ptr, dest, data.size); + core::ptr::copy(data.ptr, dest, data.size); #[cfg(target_os = "macos")] msg_send_![buffer.raw[buffer.next_value], didModifyRange:NSRange::new(0, data.size as u64)]; @@ -1127,7 +1127,7 @@ impl RenderingBackend for MetalContext { let buffer = self.uniform_buffers[self.current_frame_index]; unsafe { let dest: *mut core::ffi::c_void = msg_send![buffer, contents]; - std::ptr::copy( + core::ptr::copy( uniform_ptr as _, dest.add(self.current_ub_offset as usize), size, diff --git a/src/native/windows/clipboard.rs b/src/native/windows/clipboard.rs index 20579114e..e84cf468f 100644 --- a/src/native/windows/clipboard.rs +++ b/src/native/windows/clipboard.rs @@ -4,7 +4,7 @@ use winapi::um::winuser::{ CloseClipboard, EmptyClipboard, GetClipboardData, OpenClipboard, SetClipboardData, }; -use std::ptr; +use core::ptr; struct ClipboardGuard; impl ClipboardGuard { From 167c939a2168aa53d50572e264028db3d5eeafb5 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Apr 2025 21:36:22 +0200 Subject: [PATCH 11/11] two more ones that clippy missed --- src/log.rs | 2 +- src/native/apple/frameworks.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/log.rs b/src/log.rs index d54eb0a91..66708aed6 100644 --- a/src/log.rs +++ b/src/log.rs @@ -5,7 +5,7 @@ /// Will send log calls like debug!(), warn!() and error!() to appropriate console_* call on wasm /// and just println! on PC. /// If you need better control of log messages - just dont use "log-impl" feature and use appropriate loggers from log-rs -use std::cmp; +use core::cmp; #[repr(usize)] #[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] diff --git a/src/native/apple/frameworks.rs b/src/native/apple/frameworks.rs index f92b05511..468bc9a47 100644 --- a/src/native/apple/frameworks.rs +++ b/src/native/apple/frameworks.rs @@ -10,6 +10,7 @@ #![allow(dead_code)] pub use { + core::{ffi::c_void, ptr::NonNull}, objc::{ class, declare::ClassDecl, @@ -17,7 +18,6 @@ pub use { runtime::{Class, Object, Sel, BOOL, NO, YES}, sel, sel_impl, Encode, Encoding, }, - std::{ffi::c_void, ptr::NonNull}, }; //use bitflags::bitflags;