Skip to content

Commit

Permalink
Use netty-jni-util 0.0.3.Final (java-native-access#235)
Browse files Browse the repository at this point in the history
Motifivation:

netty-jni-util 0.0.2.Final is incompatible with static linking. netty-jni-util 0.0.3.Final adds static linking compatibility.

Modifications:

Bump netty-jni-util to version 0.0.3.Final and update to its new API
which requires the caller to manage packagePrefix.

Result:

Using latest version of netty-jni-util and support static linking
compatibility.
  • Loading branch information
normanmaurer authored Mar 25, 2021
1 parent 0e7a742 commit aa79c75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-jni-util</artifactId>
<version>0.0.2.Final</version>
<version>0.0.3.Final</version>
<classifier>sources</classifier>
<optional>true</optional>
</dependency>
Expand Down
25 changes: 17 additions & 8 deletions src/main/c/netty_quic_quiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "netty_quic_boringssl.h"
#include "netty_quic.h"

// Add define if NETTY_BUILD_STATIC is defined so it is picked up in netty_jni_util.c
#ifdef NETTY_BUILD_STATIC
// Add define if NETTY_QUIC_BUILD_STATIC is defined so it is picked up in netty_jni_util.c
#ifdef NETTY_QUIC_BUILD_STATIC
#define NETTY_JNI_UTIL_BUILD_STATIC
#endif

Expand All @@ -36,6 +36,10 @@ static jclass quiche_logger_class;
static jmethodID quiche_logger_class_log;
static jobject quiche_logger;
static JavaVM *global_vm = NULL;
static char* staticPackagePrefix = NULL;

// Add extern declaration to let it compile with -std=c99
extern char* strdup(const char*);

jint quic_get_java_env(JNIEnv **env)
{
Expand Down Expand Up @@ -596,6 +600,9 @@ static jint netty_quiche_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
}
boringsslLoaded = 1;

if (packagePrefix) {
staticPackagePrefix = strdup(packagePrefix);
}
ret = NETTY_JNI_UTIL_JNI_VERSION;
done:
if (ret == JNI_ERR) {
Expand All @@ -615,18 +622,20 @@ static jint netty_quiche_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
return ret;
}

static void netty_quiche_JNI_OnUnload(JNIEnv* env, const char* packagePrefix) {
netty_boringssl_JNI_OnUnload(env, packagePrefix);
static void netty_quiche_JNI_OnUnload(JNIEnv* env) {
netty_boringssl_JNI_OnUnload(env, staticPackagePrefix);

NETTY_JNI_UTIL_UNLOAD_CLASS(env, quiche_logger_class);

netty_jni_util_unregister_natives(env, packagePrefix, STATICALLY_CLASSNAME);
netty_jni_util_unregister_natives(env, packagePrefix, QUICHE_CLASSNAME);
netty_jni_util_unregister_natives(env, staticPackagePrefix, STATICALLY_CLASSNAME);
netty_jni_util_unregister_natives(env, staticPackagePrefix, QUICHE_CLASSNAME);

if (quiche_logger != NULL) {
(*env)->DeleteGlobalRef(env, quiche_logger);
quiche_logger = NULL;
}
free(staticPackagePrefix);
staticPackagePrefix = NULL;
}

// Invoked by the JVM when statically linked
Expand All @@ -646,7 +655,7 @@ JNIEXPORT void JNI_OnUnload_netty_quiche(JavaVM* vm, void* reserved) {
global_vm = NULL;
}

#ifndef NETTY_BUILD_STATIC
#ifndef NETTY_QUIC_BUILD_STATIC
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
global_vm = vm;
return netty_jni_util_JNI_OnLoad(vm, reserved, LIBRARYNAME, netty_quiche_JNI_OnLoad);
Expand All @@ -656,4 +665,4 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) {
netty_jni_util_JNI_OnUnload(vm, reserved, netty_quiche_JNI_OnUnload);
global_vm = NULL;
}
#endif /* NETTY_BUILD_STATIC */
#endif /* NETTY_QUIC_BUILD_STATIC */

0 comments on commit aa79c75

Please sign in to comment.