Modern Apps git

← Modern-Apps.git

astronomy: convert JNI surface to shared jni_fn! macro

Commit
6cb327732728bdeb843a94ab3c074cdb8b220dba
Author
Vayun Mathur <[email protected]>
When
2026-12-01 19:50 UTC (4 days ago)
Parents
ad6d3f7
LOC Phase 5 rollout. Both astronomy_engine JNI functions
repeated the EnvUnowned / with_env / LogErrorAndDefault
scaffold and convert to jni_bridge::jni_fn!. Bodies are
verbatim (verified token-for-token, including the inner
catch_unwind wrappers); handles and null checks stay in
the bodies, and the now-unused EnvUnowned import is
dropped.

Lines: lib.rs 241 -> 212 (-29, -12.0%); structure_check
astronomy module counted after (structure: OK).
Cargo.lock gains only the jni_bridge edge for
astronomy_engine.

Verified: nm -D on libastronomy_engine.so before/after -
exported symbol set identical (2/2 Java_ AstronomyNative
symbols); cargo test -p astronomy_engine: 7 passed; JVM
bridge tests :astronomy:testDevUnitTestNative
ProjectionEdgeCasesTest: 6/6 passed (run excludes the
pre-existing rustFileLength ratchet); cargo fmt --check
-p astronomy_engine clean.

Diff

Cargo.lock
diff --git a/Cargo.lock b/Cargo.lockindex 0dfcaa0afc..ad7f9bc73d 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -371,6 +371,7 @@ name = "astronomy_engine" version = "0.1.0" dependencies = [  "jni",+ "jni_bridge", ]  [[package]]
astronomy/src/main/rust/Cargo.toml
diff --git a/astronomy/src/main/rust/Cargo.toml b/astronomy/src/main/rust/Cargo.tomlindex 0be44695f2..15c0e811e2 100644--- a/astronomy/src/main/rust/Cargo.toml+++ b/astronomy/src/main/rust/Cargo.toml@@ -11,3 +11,4 @@ crate-type = ["cdylib", "rlib"]  [dependencies] jni.workspace = true+jni_bridge = { path = "../../../../library/jni-bridge/src/main/rust" }
astronomy/src/main/rust/src/lib.rs
diff --git a/astronomy/src/main/rust/src/lib.rs b/astronomy/src/main/rust/src/lib.rsindex d02b80b416..63ec249752 100644--- a/astronomy/src/main/rust/src/lib.rs+++ b/astronomy/src/main/rust/src/lib.rs@@ -142,22 +142,12 @@ mod jni_bindings {     use super::*;     use jni::objects::{JClass, JDoubleArray};     use jni::sys::{jdouble, jdoubleArray, jfloatArray};-    use jni::EnvUnowned;--    /// `batchRaDecToAltAz(radec, lstRad, latRad)`. `radec` interleaved-    /// `[ra0,dec0,...]` radians; returns interleaved `[az0,alt0,...]` radians,-    /// or null on error.-    #[no_mangle]-    pub extern "system" fn Java_com_vayunmathur_astronomy_domain_AstronomyNative_batchRaDecToAltAz<-        'l,-    >(-        mut env: EnvUnowned<'l>,-        _class: JClass<'l>,-        radec: JDoubleArray<'l>,-        lst_rad: jdouble,-        lat_rad: jdouble,-    ) -> jdoubleArray {-        env.with_env(|env| -> jni::errors::Result<jdoubleArray> {+    use jni_bridge::jni_fn;++    // `batchRaDecToAltAz(radec, lstRad, latRad)`. `radec` interleaved+    // `[ra0,dec0,...]` radians; returns interleaved `[az0,alt0,...]` radians,+    // or null on error.+    jni_fn! { Java_com_vayunmathur_astronomy_domain_AstronomyNative_batchRaDecToAltAz -> jdoubleArray; (_class: JClass<'l>, radec: JDoubleArray<'l>, lst_rad: jdouble, lat_rad: jdouble) |env| {             let null = std::ptr::null_mut();             let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {                 let len = env.get_array_length(&radec).unwrap_or(0) as usize;@@ -181,29 +171,12 @@ mod jni_bindings {                 return Ok(null);             }             Ok(out.into_raw())-        })-        .resolve::<jni::errors::LogErrorAndDefault>()-    }+    } } -    /// `batchProject(altaz, centerAzRad, centerAltRad, fovDeg, screenW, screenH,-    /// rotationRad)`. `altaz` interleaved `[az0,alt0,...]`; returns interleaved-    /// `[x0,y0,...]` pixels (NaN,NaN for culled points), or null on error.-    #[no_mangle]-    #[allow(clippy::too_many_arguments)]-    pub extern "system" fn Java_com_vayunmathur_astronomy_domain_AstronomyNative_batchProject<-        'l,-    >(-        mut env: EnvUnowned<'l>,-        _class: JClass<'l>,-        altaz: JDoubleArray<'l>,-        center_az_rad: jdouble,-        center_alt_rad: jdouble,-        fov_deg: jdouble,-        screen_w: jdouble,-        screen_h: jdouble,-        rotation_rad: jdouble,-    ) -> jfloatArray {-        env.with_env(|env| -> jni::errors::Result<jfloatArray> {+    // `batchProject(altaz, centerAzRad, centerAltRad, fovDeg, screenW, screenH,+    // rotationRad)`. `altaz` interleaved `[az0,alt0,...]`; returns interleaved+    // `[x0,y0,...]` pixels (NaN,NaN for culled points), or null on error.+    jni_fn! { #[allow(clippy::too_many_arguments)] Java_com_vayunmathur_astronomy_domain_AstronomyNative_batchProject -> jfloatArray; (_class: JClass<'l>, altaz: JDoubleArray<'l>, center_az_rad: jdouble, center_alt_rad: jdouble, fov_deg: jdouble, screen_w: jdouble, screen_h: jdouble, rotation_rad: jdouble) |env| {             let null = std::ptr::null_mut();             let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {                 let len = env.get_array_length(&altaz).unwrap_or(0) as usize;@@ -235,7 +208,5 @@ mod jni_bindings {                 return Ok(null);             }             Ok(out.into_raw())-        })-        .resolve::<jni::errors::LogErrorAndDefault>()-    }+    } } }