MaulingMonkey / jni-bindgen

Generate Rust JVM FFI wrappers around APIs defined by .jar or .class files, because maintaining your own hand-written bindings is an exercise in boredom, soundness bugs, and pain.
Apache License 2.0
79 stars 9 forks source link

Some `get X field` from objects may be broken #67

Closed MarcoPolo closed 4 years ago

MarcoPolo commented 4 years ago

I was trying to get .density from DisplayMetrics and ran into a JNI error. Looking at the generated code: https://docs.rs/jni-android-sys/0.0.9/src/jni_android_sys/generated/api-level-28/android/util/DisplayMetrics.rs.html#159 I don't see how it would work. It's not using the jobject to get the field.

Shouldn't the jobject be used somehow? This is an instance variable, not a static one.

MaulingMonkey commented 4 years ago

Ooof, yep, looks like codegen for all instance fields is currently broken.

MaulingMonkey commented 4 years ago

I'm going to try to publish 0.0.10 for https://github.com/MaulingMonkey/jni-bindgen/commit/7b8d3cd81ebf2c873cc09446d7b9ae63c4cde616.

I should note I'm seriously considering trying to eliminate the jni-android-sys crate completely in favor of procedural macros that generate only the necessary code, per-caller. The current approach scales very poorly.

(Also, I obviously need better testing coverage - still trying to figure out how to read AdoptOpenJDK 13 class information...)

MaulingMonkey commented 4 years ago

Good news: 0.0.10 is published, and might even work! It at least compiles. Bad news: docs.rs failed to build on account of sandbox limits. Tracking upstream at https://github.com/rust-lang/docs.rs/issues/566

Let me know if this works for you so I can close this 👍

MarcoPolo commented 4 years ago

Works for me! thanks!