This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 1.2.x
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git


The following commit(s) were added to refs/heads/1.2.x by this push:
     new b07b48b16 Refactor for Tomcat 10.1.x compatability
b07b48b16 is described below

commit b07b48b1690c91bc575f2a31cb5be8cb7a6c53f3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon May 30 20:41:03 2022 +0100

    Refactor for Tomcat 10.1.x compatability
    
    FileInfo and Sockaddr have been removed in 10.1.x
---
 native/include/tcn.h              |  9 ++++++---
 native/src/jnilib.c               | 20 +++++++++++++-------
 xdocs/miscellaneous/changelog.xml |  4 ++++
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/native/include/tcn.h b/native/include/tcn.h
index 168549fae..4eb2c9730 100644
--- a/native/include/tcn.h
+++ b/native/include/tcn.h
@@ -227,10 +227,13 @@ unsigned long   tcn_get_thread_id(void);
         jclass _##C = (*(E))->FindClass((E), N);    \
         if (_##C == NULL) {                         \
             (*(E))->ExceptionClear((E));            \
-            return R;                               \
+            if (R != JNI_OK) {                      \
+                return R;                           \
+            }                                       \
+        } else {                                    \
+            C = (*(E))->NewGlobalRef((E), _##C);    \
+            (*(E))->DeleteLocalRef((E), _##C);      \
         }                                           \
-        C = (*(E))->NewGlobalRef((E), _##C);        \
-        (*(E))->DeleteLocalRef((E), _##C);          \
     TCN_END_MACRO
 
 #define TCN_UNLOAD_CLASS(E, C)                      \
diff --git a/native/src/jnilib.c b/native/src/jnilib.c
index 32f5151dd..300fe8caa 100644
--- a/native/src/jnilib.c
+++ b/native/src/jnilib.c
@@ -82,18 +82,24 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void 
*reserved)
 
     /* Initialize global java.lang.String class */
     TCN_LOAD_CLASS(env, jString_class, "java/lang/String", JNI_ERR);
-    TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_ERR);
-    TCN_LOAD_CLASS(env, jAinfo_class, TCN_AINFO_CLASS, JNI_ERR);
-
     TCN_GET_METHOD(env, jString_class, jString_init,
                    "<init>", "([B)V", JNI_ERR);
     TCN_GET_METHOD(env, jString_class, jString_getBytes,
                    "getBytes", "()[B", JNI_ERR);
 
-    if(tcn_load_finfo_class(env, jFinfo_class) != APR_SUCCESS)
-        return JNI_ERR;
-    if(tcn_load_ainfo_class(env, jAinfo_class) != APR_SUCCESS)
-        return JNI_ERR;
+    TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_OK);
+    if (jFinfo_class) {
+        if (tcn_load_finfo_class(env, jFinfo_class) != APR_SUCCESS) {
+            return JNI_ERR;
+        }
+    }
+
+    TCN_LOAD_CLASS(env, jAinfo_class, TCN_AINFO_CLASS, JNI_OK);
+    if (jAinfo_class) {
+        if (tcn_load_ainfo_class(env, jAinfo_class) != APR_SUCCESS) {
+            return JNI_ERR;
+        }
+    }
 #ifdef WIN32
     {
         char *ppid = getenv(TCN_PARENT_IDE);
diff --git a/xdocs/miscellaneous/changelog.xml 
b/xdocs/miscellaneous/changelog.xml
index f07cbb494..59ab613bc 100644
--- a/xdocs/miscellaneous/changelog.xml
+++ b/xdocs/miscellaneous/changelog.xml
@@ -36,6 +36,10 @@
 </section>
 <section name="Changes in 1.2.34">
   <changelog>
+    <scode>
+      Refactor library initialization so it is compatible with Tomcat 10.1.x
+      onwards where a number of Java classes have been removed. (markt)
+    </scode>
   </changelog>
 </section>
 <section name="Changes in 1.2.33">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to