Patch: Add JNICALL/JNIEXPORT attributes to JNI functions in jni.h/

Ranjit Mathew
Wed Nov 13 21:10:00 GMT 2002


     The following patch proposes to add missing JNICALL and JNIEXPORT
attributes to the JNI function and function pointer declarations in
jni.h and function definitions in These changes affect only
the Win32 targets, as JNICALL and JNIEXPORT are empty #define-s on
other platforms.

(I'm sending a compressed patch as the uncompressed length was
somewhat big at 57KB. All the changes are rather dumb - the big
size of the patch is due to the sheer number of functions

I've tried to be consistent with Sun's JDK as much as possible, even
if, AFAICT, it is not quite right. For example, a declaration for an
exported function in a DLL should have a JNIIMPORT attribute while a
definition for the same should have the JNIEXPORT attribute - Sun's
jni.h uses JNIEXPORT everywhere *except* for
JNI_GetDefaultJavaVMInitArgs( ), JNI_CreateJavaVM( ) and
JNI_GetCreatedJavaVMs( ), where a _JNI_IMPORT_OR_EXPORT_ #define-kludge
is used that gets mapped to JNIIMPORT or JNIEXPORT depending on
whether _JNI_IMPLEMENTATION_ has been defined (presumably by the
JNI implementation sources just before including jni.h).

Most of the JNI functions like "static int _Jv_JNI_FooBar( ...)" in have been redefined as "static int JNICALL _Jv_JNI_FooBar( ...)"
*except* for those that return pointers - here I've had to define
them as "static JNICALL int * _Jv_JNI_FooBar( ...)" to avoid compiler
errors. For example, _Jv_JNI_GetStringChars( ),
_Jv_JNI_NewPrimitiveArray( ), etc. I'd be very happy and grateful
to get insights on this behaviour from people in the know here.

Or should I consistently use the latter form throughout? (FYI,
JNICALL maps to __stdcall on Win32, which maps to the GCC
__attribute__((stdcall)) function attribute.)

Finally, I must say that I could not reliably automate this conversion.
Almost all of these changes have been applied by hand, first to
GCJ 3.2 to verify their correctness and then migrated to GCJ 3.3.
During this process, it is possible that I might have inadvertently
missed out something, even though I've taken great care to verify each
change before applying. If that's the case, please accept my apologies
for the same.


2002-11-14  Ranjit Mathew <>

     * include/jni.h: Add missing JNICALL and JNIEXPORT attributes
     to function and function pointer declarations in accordance with
     Sun's JDKs.

     * Add missing JNICALL and JNIEXPORT attributes to
     JNI function definitions.

Sincerely Yours,

Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jnipatches.gz
Type: application/x-gzip
Size: 6960 bytes
Desc: not available
URL: <>

More information about the Java-patches mailing list