Use netty-jni-util 0.0.3.Final (#11115)

netty-jni-util 0.0.2.Final is incompatible with static linking. Before
the netty-jni-util dependency was introduced netty-tcnative supported
static linking via NETTY_BUILD_STATIC. 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 restored static linking
compatibility.
This commit is contained in:
Norman Maurer 2021-03-25 11:40:22 +01:00 committed by GitHub
parent 72d7ec9d8c
commit 7ed840e62a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 14 deletions

View File

@ -456,7 +456,7 @@
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-jni-util</artifactId> <artifactId>netty-jni-util</artifactId>
<version>0.0.2.Final</version> <version>0.0.3.Final</version>
<classifier>sources</classifier> <classifier>sources</classifier>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>

View File

@ -36,6 +36,7 @@ static jclass dnsResolverClass = NULL;
static jclass byteArrayClass = NULL; static jclass byteArrayClass = NULL;
static jclass stringClass = NULL; static jclass stringClass = NULL;
static jmethodID dnsResolverMethodId = NULL; static jmethodID dnsResolverMethodId = NULL;
static char* staticPackagePrefix = NULL;
// JNI Registered Methods Begin // JNI Registered Methods Begin
@ -150,10 +151,15 @@ static JNINativeMethod* createDynamicMethodsTable(const char* packagePrefix) {
// JNI Method Registration Table End // JNI Method Registration Table End
static void netty_resolver_dns_native_macos_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { static void netty_resolver_dns_native_macos_JNI_OnUnLoad(JNIEnv* env) {
NETTY_JNI_UTIL_UNLOAD_CLASS(env, byteArrayClass); NETTY_JNI_UTIL_UNLOAD_CLASS(env, byteArrayClass);
NETTY_JNI_UTIL_UNLOAD_CLASS(env, stringClass); NETTY_JNI_UTIL_UNLOAD_CLASS(env, stringClass);
netty_jni_util_unregister_natives(env, packagePrefix, STREAM_CLASSNAME); netty_jni_util_unregister_natives(env, staticPackagePrefix, STREAM_CLASSNAME);
if (staticPackagePrefix != NULL) {
free((void *) staticPackagePrefix);
staticPackagePrefix = NULL;
}
} }
static jint netty_resolver_dns_native_macos_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { static jint netty_resolver_dns_native_macos_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
@ -183,6 +189,10 @@ static jint netty_resolver_dns_native_macos_JNI_OnLoad(JNIEnv* env, const char*
NETTY_JNI_UTIL_LOAD_CLASS(env, byteArrayClass, "[B", done); NETTY_JNI_UTIL_LOAD_CLASS(env, byteArrayClass, "[B", done);
NETTY_JNI_UTIL_LOAD_CLASS(env, stringClass, "java/lang/String", done); NETTY_JNI_UTIL_LOAD_CLASS(env, stringClass, "java/lang/String", done);
if (packagePrefix != NULL) {
staticPackagePrefix = strdup(packagePrefix);
}
ret = NETTY_JNI_UTIL_JNI_VERSION; ret = NETTY_JNI_UTIL_JNI_VERSION;
done: done:
if (ret == JNI_ERR) { if (ret == JNI_ERR) {

View File

@ -722,13 +722,17 @@ done:
return ret; return ret;
} }
static void netty_epoll_native_JNI_OnUnload(JNIEnv* env, const char* packagePrefix) { static void netty_epoll_native_JNI_OnUnload(JNIEnv* env) {
netty_epoll_linuxsocket_JNI_OnUnLoad(env, packagePrefix); netty_epoll_linuxsocket_JNI_OnUnLoad(env, staticPackagePrefix);
if (register_unix_called == 1) { if (register_unix_called == 1) {
register_unix_called = 0; register_unix_called = 0;
netty_unix_unregister(env, staticPackagePrefix); netty_unix_unregister(env, staticPackagePrefix);
} }
netty_jni_util_unregister_natives(env, staticPackagePrefix, STATICALLY_CLASSNAME);
netty_jni_util_unregister_natives(env, staticPackagePrefix, NATIVE_CLASSNAME);
if (staticPackagePrefix != NULL) { if (staticPackagePrefix != NULL) {
free((void *) staticPackagePrefix); free((void *) staticPackagePrefix);
staticPackagePrefix = NULL; staticPackagePrefix = NULL;
@ -741,9 +745,6 @@ static void netty_epoll_native_JNI_OnUnload(JNIEnv* env, const char* packagePref
packetPortFieldId = NULL; packetPortFieldId = NULL;
packetMemoryAddressFieldId = NULL; packetMemoryAddressFieldId = NULL;
packetCountFieldId = NULL; packetCountFieldId = NULL;
netty_jni_util_unregister_natives(env, packagePrefix, STATICALLY_CLASSNAME);
netty_jni_util_unregister_natives(env, packagePrefix, NATIVE_CLASSNAME);
} }
// Invoked by the JVM when statically linked // Invoked by the JVM when statically linked

View File

@ -341,21 +341,22 @@ error:
return JNI_ERR; return JNI_ERR;
} }
static void netty_kqueue_native_JNI_OnUnload(JNIEnv* env, const char* packagePrefix) { static void netty_kqueue_native_JNI_OnUnload(JNIEnv* env) {
netty_kqueue_bsdsocket_JNI_OnUnLoad(env, packagePrefix); netty_kqueue_bsdsocket_JNI_OnUnLoad(env, staticPackagePrefix);
netty_kqueue_eventarray_JNI_OnUnLoad(env, packagePrefix); netty_kqueue_eventarray_JNI_OnUnLoad(env, staticPackagePrefix);
if (register_unix_called == 1) { if (register_unix_called == 1) {
register_unix_called = 0; register_unix_called = 0;
netty_unix_unregister(env, staticPackagePrefix); netty_unix_unregister(env, staticPackagePrefix);
} }
netty_jni_util_unregister_natives(env, staticPackagePrefix, STATICALLY_CLASSNAME);
netty_jni_util_unregister_natives(env, staticPackagePrefix, NATIVE_CLASSNAME);
if (staticPackagePrefix != NULL) { if (staticPackagePrefix != NULL) {
free((void *) staticPackagePrefix); free((void *) staticPackagePrefix);
staticPackagePrefix = NULL; staticPackagePrefix = NULL;
} }
netty_jni_util_unregister_natives(env, packagePrefix, STATICALLY_CLASSNAME);
netty_jni_util_unregister_natives(env, packagePrefix, NATIVE_CLASSNAME);
} }
// We build with -fvisibility=hidden so ensure we mark everything that needs to be visible with JNIEXPORT // We build with -fvisibility=hidden so ensure we mark everything that needs to be visible with JNIEXPORT