Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace usage of the std::os::raw module with core::ffi #491

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/native/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ fn send_message(message: Message) {
static mut ACTIVITY: ndk_sys::jobject = std::ptr::null_mut();
static mut VM: *mut ndk_sys::JavaVM = std::ptr::null_mut();

pub unsafe fn console_debug(msg: *const ::std::os::raw::c_char) {
pub unsafe fn console_debug(msg: *const ::core::ffi::c_char) {
ndk_sys::__android_log_write(
ndk_sys::android_LogPriority_ANDROID_LOG_DEBUG as _,
b"SAPP\0".as_ptr() as _,
msg,
);
}

pub unsafe fn console_info(msg: *const ::std::os::raw::c_char) {
pub unsafe fn console_info(msg: *const ::core::ffi::c_char) {
ndk_sys::__android_log_write(
ndk_sys::android_LogPriority_ANDROID_LOG_INFO as _,
b"SAPP\0".as_ptr() as _,
msg,
);
}

pub unsafe fn console_warn(msg: *const ::std::os::raw::c_char) {
pub unsafe fn console_warn(msg: *const ::core::ffi::c_char) {
ndk_sys::__android_log_write(
ndk_sys::android_LogPriority_ANDROID_LOG_WARN as _,
b"SAPP\0".as_ptr() as _,
msg,
);
}

pub unsafe fn console_error(msg: *const ::std::os::raw::c_char) {
pub unsafe fn console_error(msg: *const ::core::ffi::c_char) {
ndk_sys::__android_log_write(
ndk_sys::android_LogPriority_ANDROID_LOG_ERROR as _,
b"SAPP\0".as_ptr() as _,
Expand Down Expand Up @@ -631,8 +631,8 @@ unsafe fn set_full_screen(env: *mut ndk_sys::JNIEnv, fullscreen: bool) {
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct android_asset {
pub content: *mut ::std::os::raw::c_char,
pub content_length: ::std::os::raw::c_int,
pub content: *mut ::core::ffi::c_char,
pub content_length: ::core::ffi::c_int,
}

// According to documentation, AAssetManager_fromJava is as available as an
Expand All @@ -645,7 +645,7 @@ extern "C" {
) -> *mut ndk_sys::AAssetManager;
}

pub(crate) unsafe fn load_asset(filepath: *const ::std::os::raw::c_char, out: *mut android_asset) {
pub(crate) unsafe fn load_asset(filepath: *const ::core::ffi::c_char, out: *mut android_asset) {
let env = attach_jni_env();

let get_method_id = (**env).GetMethodID.unwrap();
Expand Down
34 changes: 17 additions & 17 deletions src/native/apple/apple_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{

pub fn nsstring_to_string(string: ObjcId) -> String {
unsafe {
let utf8_string: *const std::os::raw::c_uchar = msg_send![string, UTF8String];
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()
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn load_undocumented_cursor(cursor_name: &str) -> ObjcId {

pub unsafe fn ccfstr_from_str(inp: &str) -> CFStringRef {
let null = format!("{}\0", inp);
__CFStringMakeConstantString(null.as_ptr() as *const ::std::os::raw::c_char)
__CFStringMakeConstantString(null.as_ptr() as *const ::core::ffi::c_char)
}

pub unsafe fn cfstring_ref_to_string(cfstring: CFStringRef) -> String {
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn get_event_key_modifier(event: ObjcId) -> KeyMods {
}

pub fn get_event_keycode(event: ObjcId) -> Option<KeyCode> {
let scan_code: std::os::raw::c_ushort = unsafe { msg_send![event, keyCode] };
let scan_code: core::ffi::c_ushort = unsafe { msg_send![event, keyCode] };

Some(match scan_code {
0x00 => KeyCode::A,
Expand Down Expand Up @@ -468,21 +468,21 @@ pub fn load_mouse_cursor(cursor: CursorIcon) -> ObjcId {
// {
// #[repr(C)]
// struct BlockDescriptor {
// reserved: std::os::raw::c_ulong,
// size: std::os::raw::c_ulong,
// copy_helper: extern "C" fn(*mut std::os::raw::c_void, *const std::os::raw::c_void),
// dispose_helper: extern "C" fn(*mut std::os::raw::c_void),
// reserved: core::ffi::c_ulong,
// size: core::ffi::c_ulong,
// copy_helper: extern "C" fn(*mut core::ffi::c_void, *const core::ffi::c_void),
// dispose_helper: extern "C" fn(*mut core::ffi::c_void),
// }

// static DESCRIPTOR: BlockDescriptor = BlockDescriptor {
// reserved: 0,
// size: mem::size_of::<BlockLiteral>() as std::os::raw::c_ulong,
// size: mem::size_of::<BlockLiteral>() as core::ffi::c_ulong,
// copy_helper,
// dispose_helper,
// };

// #[allow(unused_unsafe)]
// extern "C" fn copy_helper(dst: *mut std::os::raw::c_void, src: *const std::os::raw::c_void) {
// extern "C" fn copy_helper(dst: *mut core::ffi::c_void, src: *const core::ffi::c_void) {
// unsafe {
// ptr::write(
// &mut (*(dst as *mut BlockLiteral)).inner as *mut _,
Expand All @@ -492,7 +492,7 @@ pub fn load_mouse_cursor(cursor: CursorIcon) -> ObjcId {
// }

// #[allow(unused_unsafe)]
// extern "C" fn dispose_helper(src: *mut std::os::raw::c_void) {
// extern "C" fn dispose_helper(src: *mut core::ffi::c_void) {
// unsafe {
// ptr::drop_in_place(src as *mut BlockLiteral);
// }
Expand All @@ -506,17 +506,17 @@ pub fn load_mouse_cursor(cursor: CursorIcon) -> ObjcId {

// #[repr(C)]
// struct BlockLiteral {
// isa: *const std::os::raw::c_void,
// flags: std::os::raw::c_int,
// reserved: std::os::raw::c_int,
// isa: *const core::ffi::c_void,
// flags: core::ffi::c_int,
// reserved: core::ffi::c_int,
// invoke: extern "C" fn(*mut BlockLiteral, $ ( $ arg_ty), *) $ ( -> $ return_ty) ?,
// descriptor: *const BlockDescriptor,
// inner: ::std::sync::Arc<::std::sync::Mutex<dyn Fn( $ ( $ arg_ty), *) $ ( -> $ return_ty) ? >>,
// }

// #[allow(unused_unsafe)]
// BlockLiteral {
// isa: unsafe {_NSConcreteStackBlock.as_ptr() as *const std::os::raw::c_void},
// isa: unsafe {_NSConcreteStackBlock.as_ptr() as *const core::ffi::c_void},
// flags: 1 << 25,
// reserved: 0,
// invoke,
Expand All @@ -534,9 +534,9 @@ pub fn load_mouse_cursor(cursor: CursorIcon) -> ObjcId {
// {
// #[repr(C)]
// struct BlockLiteral {
// isa: *const std::os::raw::c_void,
// flags: std::os::raw::c_int,
// reserved: std::os::raw::c_int,
// isa: *const core::ffi::c_void,
// flags: core::ffi::c_int,
// reserved: core::ffi::c_int,
// invoke: extern "C" fn(*mut BlockLiteral, $ ( $ arg_ty), *) $ ( -> $ return_ty) ?,
// }

Expand Down
4 changes: 2 additions & 2 deletions src/native/apple/frameworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extern "C" {
pub static NSProcessInfo: ObjcId;
pub fn NSStringFromClass(class: ObjcId) -> ObjcId;

pub fn __CFStringMakeConstantString(cStr: *const ::std::os::raw::c_char) -> CFStringRef;
pub fn __CFStringMakeConstantString(cStr: *const ::core::ffi::c_char) -> CFStringRef;

pub fn CFStringGetLength(theString: CFStringRef) -> u64;
pub fn CFStringGetBytes(
Expand Down Expand Up @@ -1039,7 +1039,7 @@ pub struct SMPTETime {
pub struct _AudioBuffer {
pub mNumberChannels: u32,
pub mDataByteSize: u32,
pub mData: *mut ::std::os::raw::c_void,
pub mData: *mut ::core::ffi::c_void,
}

pub const MAX_AUDIO_BUFFERS: usize = 8;
Expand Down
18 changes: 9 additions & 9 deletions src/native/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub type EGLNativeWindowType = crate::native::linux_x11::libx11::Window;
#[cfg(target_os = "android")]
pub type EGLNativeDisplayType = *mut ();
#[cfg(target_os = "android")]
pub type EGLNativePixmapType = ::std::os::raw::c_ulong;
pub type EGLNativePixmapType = ::core::ffi::c_ulong;
#[cfg(target_os = "android")]
pub type EGLNativeWindowType = ::std::os::raw::c_ulong;
pub type EGLNativeWindowType = ::core::ffi::c_ulong;

pub use core::ptr::null_mut;

Expand All @@ -40,11 +40,11 @@ pub type NativeDisplayType = EGLNativeDisplayType;
pub type NativePixmapType = EGLNativePixmapType;
pub type NativeWindowType = EGLNativeWindowType;
pub type EGLint = i32;
pub type EGLBoolean = ::std::os::raw::c_uint;
pub type EGLDisplay = *mut ::std::os::raw::c_void;
pub type EGLConfig = *mut ::std::os::raw::c_void;
pub type EGLSurface = *mut ::std::os::raw::c_void;
pub type EGLContext = *mut ::std::os::raw::c_void;
pub type EGLBoolean = ::core::ffi::c_uint;
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<unsafe extern "C" fn()>;
pub type PFNEGLCHOOSECONFIGPROC = ::std::option::Option<
unsafe extern "C" fn(
Expand Down Expand Up @@ -121,7 +121,7 @@ pub type PFNEGLGETDISPLAYPROC =
pub type PFNEGLGETERRORPROC = ::std::option::Option<unsafe extern "C" fn() -> EGLint>;
pub type PFNEGLGETPROCADDRESSPROC = ::std::option::Option<
unsafe extern "C" fn(
procname: *const ::std::os::raw::c_char,
procname: *const ::core::ffi::c_char,
) -> __eglMustCastToProperFunctionPointerType,
>;
pub type PFNEGLINITIALIZEPROC = ::std::option::Option<
Expand All @@ -144,7 +144,7 @@ pub type PFNEGLQUERYCONTEXTPROC = ::std::option::Option<
) -> EGLBoolean,
>;
pub type PFNEGLQUERYSTRINGPROC = ::std::option::Option<
unsafe extern "C" fn(dpy: EGLDisplay, name: EGLint) -> *const ::std::os::raw::c_char,
unsafe extern "C" fn(dpy: EGLDisplay, name: EGLint) -> *const ::core::ffi::c_char,
>;
pub type PFNEGLQUERYSURFACEPROC = ::std::option::Option<
unsafe extern "C" fn(
Expand Down
42 changes: 21 additions & 21 deletions src/native/gl.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]

pub type GLenum = ::std::os::raw::c_uint;
pub type GLboolean = ::std::os::raw::c_uchar;
pub type GLbitfield = ::std::os::raw::c_uint;
pub type GLvoid = ::std::os::raw::c_void;
pub type GLbyte = ::std::os::raw::c_schar;
pub type GLshort = ::std::os::raw::c_short;
pub type GLint = ::std::os::raw::c_int;
pub type GLubyte = ::std::os::raw::c_uchar;
pub type GLushort = ::std::os::raw::c_ushort;
pub type GLuint = ::std::os::raw::c_uint;
pub type GLuint64 = ::std::os::raw::c_ulonglong;
pub type GLsizei = ::std::os::raw::c_int;
pub type GLchar = ::std::os::raw::c_char;
pub type GLenum = ::core::ffi::c_uint;
pub type GLboolean = ::core::ffi::c_uchar;
pub type GLbitfield = ::core::ffi::c_uint;
pub type GLvoid = ::core::ffi::c_void;
pub type GLbyte = ::core::ffi::c_schar;
pub type GLshort = ::core::ffi::c_short;
pub type GLint = ::core::ffi::c_int;
pub type GLubyte = ::core::ffi::c_uchar;
pub type GLushort = ::core::ffi::c_ushort;
pub type GLuint = ::core::ffi::c_uint;
pub type GLuint64 = ::core::ffi::c_ulonglong;
pub type GLsizei = ::core::ffi::c_int;
pub type GLchar = ::core::ffi::c_char;

pub type khronos_ssize_t = ::std::os::raw::c_long;
pub type khronos_usize_t = ::std::os::raw::c_ulong;
pub type khronos_intptr_t = ::std::os::raw::c_long;
pub type khronos_ssize_t = ::core::ffi::c_long;
pub type khronos_usize_t = ::core::ffi::c_ulong;
pub type khronos_intptr_t = ::core::ffi::c_long;

pub type GLsizeiptr = khronos_ssize_t;
pub type GLintptr = khronos_intptr_t;
Expand Down Expand Up @@ -405,7 +405,7 @@ gl_loader!(
target: GLenum,
offset: GLintptr,
size: GLsizeiptr,
data: *const ::std::os::raw::c_void
data: *const ::core::ffi::c_void
) -> (),
fn glGenBuffers(n: GLsizei, buffers: *mut GLuint) -> (),
fn glCheckFramebufferStatus(target: GLenum) -> GLenum,
Expand Down Expand Up @@ -532,7 +532,7 @@ gl_loader!(
mode: GLenum,
count: GLsizei,
type_: GLenum,
indices: *const ::std::os::raw::c_void,
indices: *const ::core::ffi::c_void,
instancecount: GLsizei
) -> (),
fn glVertexAttribPointer(
Expand All @@ -541,14 +541,14 @@ gl_loader!(
type_: GLenum,
normalized: GLboolean,
stride: GLsizei,
pointer: *const ::std::os::raw::c_void
pointer: *const ::core::ffi::c_void
) -> (),
fn glVertexAttribIPointer(
index: GLuint,
size: GLint,
type_: GLenum,
stride: GLsizei,
pointer: *const ::std::os::raw::c_void
pointer: *const ::core::ffi::c_void
) -> (),
fn glDisable(cap: GLenum) -> (),
fn glColorMask(red: GLboolean, green: GLboolean, blue: GLboolean, alpha: GLboolean) -> (),
Expand All @@ -568,7 +568,7 @@ gl_loader!(
fn glBufferData(
target: GLenum,
size: GLsizeiptr,
data: *const ::std::os::raw::c_void,
data: *const ::core::ffi::c_void,
usage: GLenum
) -> (),
fn glBlendFuncSeparate(
Expand Down
Loading
Loading