Releases: mapbox/jni.hpp
Releases · mapbox/jni.hpp
v4.0.0
This release contains many breaking changes in the high-level API, especially around ownership semantics.
- Replaced
UniqueObject
andUniqueWeakObject
withGlobal
andWeak
, and introducedLocal
. All high-level values must be one of these three types; high-level references (e.g.const jni::Object<>&
) must now be used whenever borrowing, rather than ownership, is desired. In particular, native method implementations should accept non-primitive inputs via reference, rather than by value. - High-level JNI local refs are now always wrapped with the
Local
ownership type, which callsDeleteLocalRef
when destroyed. You'll never need to worry about overflowing the local ref table. Object
,Class
, andArray
are no longer publicly constructible, destructible, movable, copyable, assignable, or implicitly convertible to raw pointers. UseGlobal
,Weak
, andLocal
for ownership. UseMakeGlobal
,MakeWeak
, andMakeLocal
for explicit ref duplication. Use C++ references when borrowing, rather than ownership, is desired. Avoid using raw pointers when possible; useget()
if you really need one.- If you tell jni.hpp about the Java inheritance tree, it'll build a parallel tree for
Object
, enabling convenient automatic conversions. To inform jni.hpp of Java inheritance, add aSuperTag
typedef to a tag type naming the tag type for the Java superclass, e.g.:struct StringTag { using SuperTag = ObjectTag; ... };
- As special cases of the above,
String
,Class
, andArray
now inherit fromObject<>
. - Introduced
ArrayTag<T>
, whereT
is a primitive or high-level type. This allows you to obtain array classes, e.g.Class<ArrayTag<jni::jlong>>::Singleton(env)
. - Swapped the argument order for
Cast
. - Removed an annoying parameter to Array::New.
Other new features:
- Introduced
Class<Tag>::Singleton()
, providing a convenient way to obtain a reference to aClass
instance. - Added wrappers for boxing and unboxing primitive types.
- Support for
Array<jbyte>
<->std::string
conversions. - More efficient
TypeSignature
implementation. - Added deleters for
Global
andWeak
that attach or get theJNIEnv
. These are useful when the deletion will happen on an auxiliary thread, such as the finalizer thread. - Added a wrapper for
java.lang.ref.WeakReference
. This should almost always be used instead of JNI weak global refs, which have unsafe promotion semantics.
Bugfixes:
- Cope with implementation inconsistencies in
AttachCurrentThread
- Improved compatibility with OpenJDK
- Improved compatibility with GCC
v3.0.0
v2.0.0
- The return type of
jni::PushLocalFrame
is now an ownership type. Accordingly,jni::PopLocalFrame
now accepts ownership.
v1.0.0
Initial release.