Comments (2)
Ah, tricky.
Yeah the implementation seems to try and mirror how the C API lets you redundantly call AttachCurrentThread
and it will be a NOP that just return the JNIEnv
in that case.
The implementation of attach_current_thread()
sees when the attach is redundant and in that case it returns a guard that won't do anything on Drop
. (so it's not exactly that there's any detailed consideration of lifo ordering except that the first guard that really does attach the thread will be the only guard that does anything on Drop
)
I'm not exactly sure why it was implemented this way but I guess it was the simplest approach that reflected how the C API works.
It looks like there needs to be a per-thread ref-count for these guards to work like this.
With needing to have a thread-local reference counter that also makes me wonder what hazards there could be if there are multiple versions of the jni
crate linked into one application - each with a private set of thread-local variables.
Similar to the current implementation I think there would need to be some kind of special case to recognize if the first attach increment for the thread was redundant (another version of the jni
crate or some other non-Rust code might have attached the thread) and we'd probably have to just assume something else will be responsible for detaching the thread in this case.
from jni-rs.
For reference also see this recent discussion around the soundness of APIs that return a JNIEnv
here: #436 (reply in thread)
from jni-rs.
Related Issues (20)
- how to cache JClass to avoid expensive lookups? HOT 3
- Make the JNI lib name configurable? HOT 4
- What does the correct class descriptor format looks like for `find_class`? HOT 2
- Implement `std::iter::Iter` on arrays? HOT 1
- Create a replacement for `ndk-context` just for sharing a `JavaVM` pointer between modular / orthogonal crates HOT 1
- Is it safe to have multiple versions of the `jni` crate in use within a single application? HOT 1
- Cross compiling for Android HOT 14
- Add Android target[s] to CI
- JNIEnv::get_object_array_element requires &mut self HOT 2
- Example request: `call_method` with non-primitive type as parameters. HOT 4
- TryFrom<char> for `char` primitive HOT 7
- 0.21 mutability requirements on `JNIEnv` methods break use of `catch_unwind` HOT 15
- Nested "critical sections" disallowed by borrow checker HOT 1
- Provide ways to use `CallNonvirtual*Method` in `JNIEnv` HOT 1
- Converting between types in JNI code HOT 2
- how to use call_static_method_unchecked with a GlobalRef to a class? HOT 2
- how to get java list on rust HOT 2
- CallNonvirtual<type>Method support request HOT 2
- Can i load native function on exec self ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jni-rs.