mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Android glue: don’t zero-init non-null function pointers
Fixes: ```rust error: the type `android_injected_glue::ffi::android_app` does not permit zero-initialization --> ports/libsimpleservo/jniapi/src/lib.rs:511:46 | 511 | let mut app: ffi::android_app = unsafe { std::mem::zeroed() }; | ^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit<T>` instead | = note: `-D invalid-value` implied by `-D warnings` note: Function pointers must be non-null (in this struct field) --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/android_injected_glue-0.2.3/src/ffi.rs:23:5 | 23 | pub onAppCmd: extern fn(*mut android_app, i32), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error ```
This commit is contained in:
parent
98e4a53b72
commit
2130e6966a
1 changed files with 41 additions and 8 deletions
|
@ -16,6 +16,7 @@ use log::Level;
|
||||||
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
||||||
use simpleservo::{Coordinates, EventLoopWaker, HostTrait, InitOptions, VRInitOptions};
|
use simpleservo::{Coordinates, EventLoopWaker, HostTrait, InitOptions, VRInitOptions};
|
||||||
use std::os::raw::{c_char, c_int, c_void};
|
use std::os::raw::{c_char, c_int, c_void};
|
||||||
|
use std::ptr::{null, null_mut};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
@ -508,19 +509,51 @@ fn initialize_android_glue(env: &JNIEnv, activity: JObject) {
|
||||||
|
|
||||||
// From jni-rs to android_injected_glue
|
// From jni-rs to android_injected_glue
|
||||||
|
|
||||||
let mut app: ffi::android_app = unsafe { std::mem::zeroed() };
|
let clazz = Box::leak(Box::new(env.new_global_ref(activity).unwrap()));
|
||||||
let mut native_activity: ffi::ANativeActivity = unsafe { std::mem::zeroed() };
|
|
||||||
|
|
||||||
let clazz = Box::into_raw(Box::new(env.new_global_ref(activity).unwrap()));
|
let activity = Box::into_raw(Box::new(ffi::ANativeActivity {
|
||||||
native_activity.clazz = unsafe { (*clazz).as_obj().into_inner() as *mut c_void };
|
clazz: clazz.as_obj().into_inner() as *mut c_void,
|
||||||
|
vm: env.get_java_vm().unwrap().get_java_vm_pointer() as *mut ffi::_JavaVM,
|
||||||
|
|
||||||
let vm = env.get_java_vm().unwrap().get_java_vm_pointer();
|
callbacks: null_mut(),
|
||||||
native_activity.vm = vm as *mut ffi::_JavaVM;
|
env: null_mut(),
|
||||||
|
internalDataPath: null(),
|
||||||
|
externalDataPath: null(),
|
||||||
|
sdkVersion: 0,
|
||||||
|
instance: null_mut(),
|
||||||
|
assetManager: null_mut(),
|
||||||
|
obbPath: null(),
|
||||||
|
}));
|
||||||
|
|
||||||
app.activity = Box::into_raw(Box::new(native_activity));
|
extern "C" fn on_app_cmd(_: *mut ffi::android_app, _: i32) {}
|
||||||
|
extern "C" fn on_input_event(_: *mut ffi::android_app, _: *const c_void) -> i32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
let app = Box::into_raw(Box::new(ffi::android_app {
|
||||||
|
activity,
|
||||||
|
onAppCmd: on_app_cmd,
|
||||||
|
onInputEvent: on_input_event,
|
||||||
|
|
||||||
|
userData: null_mut(),
|
||||||
|
config: null(),
|
||||||
|
savedState: null_mut(),
|
||||||
|
savedStateSize: 0,
|
||||||
|
looper: null_mut(),
|
||||||
|
inputQueue: null(),
|
||||||
|
window: null_mut(),
|
||||||
|
contentRect: ffi::ARect {
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
},
|
||||||
|
activityState: 0,
|
||||||
|
destroyRequested: 0,
|
||||||
|
}));
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ANDROID_APP = Box::into_raw(Box::new(app));
|
ANDROID_APP = app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue