Skip to content

Commit efabbc7

Browse files
Fix: extern djinni flags not being marshalled properly for JNI (#90)
In djinni, `flags` are declared as EnumSet in java. Djinni generates files named `jni/NativeXXX.hpp` which are responsible of resolving the library symbols by looking for function signatures and map them to Java functions. When a djinni type `flags` is declared in one module, and used in another one (via `@extern` and yaml files), a function `foo` taking an extern flags `my_flags` type as parameter would try to be resolved with: const jmethodID method_statusesChanged{ ::djinni::jniGetMethodID(clazz.get(), "foo", "(Lnz/co/abc/MyFlags;)V")}; This will thus fail to be resolved as the Java type for flags is `EnumSet`, not the actual underlying enum type. This commit fixes this by using an `EnumSet` properly for extern flags resulting in the following: const jmethodID method_statusesChanged{ ::djinni::jniGetMethodID(clazz.get(), "foo", "(Ljava/util/EnumSet;)V")};
1 parent ac9b1e4 commit efabbc7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/scala/djinni/JNIMarshal.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
7575
case MSet => "Ljava/util/HashSet;"
7676
case MMap => "Ljava/util/HashMap;"
7777
}
78-
case e: MExtern => e.jni.typeSignature.get
78+
case e: MExtern => e.body match {
79+
case e: Enum if e.flags => "Ljava/util/EnumSet;"
80+
case _ => e.jni.typeSignature.get
81+
}
7982
case MParam(_) => "Ljava/lang/Object;"
8083
case d: MDef => d.body match {
8184
case e: Enum if e.flags => "Ljava/util/EnumSet;"

0 commit comments

Comments
 (0)