Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

53
vendor/jni/tests/util/example_proxy.rs vendored Normal file
View File

@@ -0,0 +1,53 @@
#![allow(dead_code)]
use jni::{
errors::*,
objects::{GlobalRef, JValue},
sys::jint,
Executor, JNIEnv,
};
/// A test example of a native-to-JNI proxy
#[derive(Clone)]
pub struct AtomicIntegerProxy {
exec: Executor,
obj: GlobalRef,
}
impl AtomicIntegerProxy {
/// Creates a new instance of `AtomicIntegerProxy`
pub fn new(exec: Executor, init_value: jint) -> Result<Self> {
let obj = exec.with_attached(|env: &mut JNIEnv| {
let i = env.new_object(
"java/util/concurrent/atomic/AtomicInteger",
"(I)V",
&[JValue::from(init_value)],
)?;
env.new_global_ref(i)
})?;
Ok(AtomicIntegerProxy { exec, obj })
}
/// Gets a current value from java object
pub fn get(&mut self) -> Result<jint> {
self.exec
.with_attached(|env| env.call_method(&self.obj, "get", "()I", &[])?.i())
}
/// Increments a value of java object and then gets it
pub fn increment_and_get(&mut self) -> Result<jint> {
self.exec.with_attached(|env| {
env.call_method(&self.obj, "incrementAndGet", "()I", &[])?
.i()
})
}
/// Adds some value to the value of java object and then gets a resulting value
pub fn add_and_get(&mut self, delta: jint) -> Result<jint> {
let delta = JValue::from(delta);
self.exec.with_attached(|env| {
env.call_method(&self.obj, "addAndGet", "(I)I", &[delta])?
.i()
})
}
}

85
vendor/jni/tests/util/mod.rs vendored Normal file
View File

@@ -0,0 +1,85 @@
use std::sync::{Arc, Once};
use jni::{
errors::Result, objects::JValue, sys::jint, AttachGuard, InitArgsBuilder, JNIEnv, JNIVersion,
JavaVM,
};
mod example_proxy;
pub use self::example_proxy::AtomicIntegerProxy;
pub fn jvm() -> &'static Arc<JavaVM> {
static mut JVM: Option<Arc<JavaVM>> = None;
static INIT: Once = Once::new();
INIT.call_once(|| {
let jvm_args = InitArgsBuilder::new()
.version(JNIVersion::V8)
.option("-Xcheck:jni")
.build()
.unwrap_or_else(|e| panic!("{:#?}", e));
let jvm = JavaVM::new(jvm_args).unwrap_or_else(|e| panic!("{:#?}", e));
unsafe {
JVM = Some(Arc::new(jvm));
}
});
unsafe { JVM.as_ref().unwrap() }
}
#[allow(dead_code)]
pub fn call_java_abs(env: &mut JNIEnv, value: i32) -> i32 {
env.call_static_method(
"java/lang/Math",
"abs",
"(I)I",
&[JValue::from(value as jint)],
)
.unwrap()
.i()
.unwrap()
}
#[allow(dead_code)]
pub fn attach_current_thread() -> AttachGuard<'static> {
jvm()
.attach_current_thread()
.expect("failed to attach jvm thread")
}
#[allow(dead_code)]
pub fn attach_current_thread_as_daemon() -> JNIEnv<'static> {
jvm()
.attach_current_thread_as_daemon()
.expect("failed to attach jvm daemon thread")
}
#[allow(dead_code)]
pub fn attach_current_thread_permanently() -> JNIEnv<'static> {
jvm()
.attach_current_thread_permanently()
.expect("failed to attach jvm thread permanently")
}
#[allow(dead_code)]
pub unsafe fn detach_current_thread() {
jvm().detach_current_thread()
}
pub fn print_exception(env: &JNIEnv) {
let exception_occurred = env.exception_check().unwrap_or_else(|e| panic!("{:?}", e));
if exception_occurred {
env.exception_describe()
.unwrap_or_else(|e| panic!("{:?}", e));
}
}
#[allow(dead_code)]
pub fn unwrap<T>(res: Result<T>, env: &JNIEnv) -> T {
res.unwrap_or_else(|e| {
print_exception(env);
panic!("{:#?}", e);
})
}