This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: JNI/Win32 Patch #2: Fix lookup of "JNI_OnLoad" on loading a JNIDLL


Hi,

    I'm sorry, but I overlooked the fact that the JNI_OnLoad
function itself must be called using the "stdcall" convention.

Here's the revised patch taking care of that fact:

ChangeLog:

2002-12-07  Ranjit Mathew  <rmathew@hotmail.com>

    * java/lang/natRuntime.cc (java::lang::Runtime::_load)):
    Take care of the fact that on Win32, JNI_OnLoad is an
    "stdcall" function and could also have been exported
    as "JNI_OnLoad@8" (MinGW) or "_JNI_OnLoad@8" (MSVC).

--------------------------------- 8< --------------------------------
--- java/lang/natRuntime.cc       2002-12-08 12:48:12.000000000 +0530
+++ java/lang/natRuntime.cc       2002-12-08 12:51:32.000000000 +0530
@@ -194,4 +194,21 @@

   void *onload = lt_dlsym (h, "JNI_OnLoad");
+
+#ifdef WIN32
+  // On Win32, JNI_OnLoad is an "stdcall" function taking two
+  // pointers (8 bytes) as arguments.
+  //
+  // It could also have been exported as "JNI_OnLoad@8" (MinGW) or
+  // "_JNI_OnLoad@8" (MSVC).
+  if (onload == NULL)
+    {
+      onload = lt_dlsym (h, "JNI_OnLoad@8");
+      if (onload == NULL)
+        {
+          onload = lt_dlsym (h, "_JNI_OnLoad@8");
+        }
+    }
+#endif /* WIN32 */
+
   if (onload != NULL)
     {
@@ -202,5 +219,12 @@
 	  return;
 	}
+
+#ifdef WIN32
+      jint vers = ((jint (__attribute__((stdcall)) *) (JavaVM *, void *))
+                   onload) (vm, NULL);
+#else
       jint vers = ((jint (*) (JavaVM *, void *)) onload) (vm, NULL);
+#endif /* ! WIN32 */
+
       if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2
 	  && vers != JNI_VERSION_1_4)
--------------------------------- 8< --------------------------------

Sincerely Yours,
Ranjit.


Ranjit Mathew wrote:
Hi,

    This patch proposes to fix the lookup for "JNI_OnLoad"
when loading a JNI DLL on Win32, to take care of the differences
between BCC, MinGW and MSVC in exporting an "stdcall" function.

ChangeLog:

2002-12-07  Ranjit Mathew  <rmathew@hotmail.com>

    * java/lang/natRuntime.cc (java::lang::Runtime::_load)):
    Take care of the fact that on Win32, JNI_OnLoad could
    also have been exported as "JNI_OnLoad@8" (MinGW) or
    "_JNI_OnLoad@8" (MSVC).

------------------------------ 8< ------------------------------
--- natRuntime.cc    2002-11-13 00:07:28.000000000 +0530
+++ natRuntime.cc    2002-12-07 06:55:17.000000000 +0530
@@ -194,4 +194,21 @@

   void *onload = lt_dlsym (h, "JNI_OnLoad");
+
+#ifdef WIN32
+  // On Win32, JNI_OnLoad is an "stdcall" function taking two
+  // pointers (8 bytes) as arguments.
+  //
+  // It could also have been exported as "JNI_OnLoad@8" (MinGW) or
+  // "_JNI_OnLoad@8" (MSVC).
+  if (onload == NULL)
+    {
+      onload = lt_dlsym (h, "JNI_OnLoad@8");
+      if (onload == NULL)
+        {
+          onload = lt_dlsym (h, "_JNI_OnLoad@8");
+        }
+    }
+#endif /* WIN32 */
+
   if (onload != NULL)
     {
------------------------------ 8< ------------------------------

Sincerely Yours,
Ranjit.

--
Ranjit Mathew        Email: rmathew AT hotmail DOT com
Bangalore,
INDIA.               Web: http://ranjitmathew.tripod.com/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]