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

Ranjit Mathew rmathew@hotmail.com
Sun Dec 8 23:06:00 GMT 2002


Tom Tromey wrote:
>>>>>> "Ranjit" == Ranjit Mathew <rmathew@hotmail.com> writes:
> 
> Ranjit> I'm sorry, but I overlooked the fact that the JNI_OnLoad
> Ranjit> function itself must be called using the "stdcall" convention.
> 
> These patches generally look fine to me.  I think we should wait for
> the paperwork to clear before putting them in, though.

I have already sent the electronic request - the form
might take quite a while to arrive via snail-mail here
in India and then a whole while again getting back to
the US after I sign them.

Assuming that the hapless FSF clerk has an instantaneous
turnaround time (not!), this could still take around
a month at the least. :-(

I had hoped to get these in before the 3.3 branch - in
any case, I'm merely modifying existing code with
obvious patches to make it work on Win32... I'd be quite
ashamed, honestly, to make any copyright claims on these
teeny-weeny modifications!


> Ranjit> +#ifdef WIN32
> Ranjit> +      jint vers = ((jint (__attribute__((stdcall)) *) (JavaVM *, void *))
> Ranjit> +                   onload) (vm, NULL);
> 
> Let's use `JNICALL' here and avoid the #ifdef.

Of course! I don't know why I didn't think of it.

Here's the revised patch (yet again, sorry for the noise
this is generating in the list):

ChangeLog:

2002-12-09  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	Mon Dec  9 12:17:39 2002
+++ java/lang/natRuntime.cc	Mon Dec  9 12:20:01 2002
@@ -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,5 @@
  	  return;
  	}
-      jint vers = ((jint (*) (JavaVM *, void *)) onload) (vm, NULL);
+      jint vers = ((jint (JNICALL *) (JavaVM *, void *)) onload) (vm, NULL);
        if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2
  	  && vers != JNI_VERSION_1_4)
--------------------------------- 8< --------------------------------

Sincerely Yours,
Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/





More information about the Java-patches mailing list