This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: PR 5103 patch
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 16 Dec 2001 15:39:15 -0700
- Subject: Patch: FYI: PR 5103 patch
- Reply-to: tromey at redhat dot com
I'm checking this in.
This fixes PR 5103. Now our <jni.h> is suitable for inclusion by
ordinary C++ code. We no longer pull in a lot of libgcj-specific
stuff, that is except when <jni.h> included by files in our own
implementation.
This is a bit ugly due to the influence of jvmpi in jvm.h.
I've already checked in the test case for this code.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
For PR libgcj/5103:
* include/jvm.h (__GCJ_JNI_IMPL__): Define.
* include/config.h.in: Rebuilt.
* configure: Rebuilt.
* configure.in: Define JV_HAVE_INTTYPES_H if inttypes.h found.
Added comment for HAVE_DLOPEN to avoid autoheader error.
* gcj/libgcj-config.h.in (JV_HAVE_INTTYPES_H): Added.
* include/jni.h: Include <gcj/libgcj-config.h>. Don't include
CNI-specific headers if we are compiling ordinary JNI code with a
C++ compiler. Include <inttypes.h> and JNIWeakRef.h when
appropriate.
* jni.cc: Don't include JNIWeakRef.h.
(__GCJ_JNI_IMPL__): Don't define.
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.in,v
retrieving revision 1.102
diff -u -r1.102 configure.in
--- configure.in 2001/11/30 03:04:01 1.102
+++ configure.in 2001/12/16 22:29:10
@@ -567,7 +567,8 @@
AC_MSG_ERROR([memcpy is required])
fi
- AC_CHECK_LIB(dl, dlopen, [AC_DEFINE(HAVE_DLOPEN)])
+ AC_CHECK_LIB(dl, dlopen, [
+ AC_DEFINE(HAVE_DLOPEN, 1, [Define if dlopen is available])])
# Some library-finding code we stole from Tcl.
#--------------------------------------------------------------------
@@ -727,10 +728,14 @@
dnl We check for sys/filio.h because Solaris 2.5 defines FIONREAD there.
dnl On that system, sys/ioctl.h will not include sys/filio.h unless
dnl BSD_COMP is defined; just including sys/filio.h is simpler.
-AC_CHECK_HEADERS(unistd.h bstring.h sys/time.h sys/types.h fcntl.h sys/ioctl.h sys/filio.h sys/stat.h sys/select.h sys/socket.h netinet/in.h arpa/inet.h netdb.h pwd.h sys/config.h inttypes.h stdint.h langinfo.h locale.h)
+AC_CHECK_HEADERS(unistd.h bstring.h sys/time.h sys/types.h fcntl.h sys/ioctl.h sys/filio.h sys/stat.h sys/select.h sys/socket.h netinet/in.h arpa/inet.h netdb.h pwd.h sys/config.h stdint.h langinfo.h locale.h)
dnl We avoid AC_HEADER_DIRENT since we really only care about dirent.h
dnl for now. If you change this, you also must update natFile.cc.
AC_CHECK_HEADERS(dirent.h)
+AC_CHECK_HEADERS(inttypes.h, [
+ AC_DEFINE(HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
+ AC_DEFINE(JV_HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
+])
AC_CHECK_TYPE([ssize_t], [int])
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.57
diff -u -r1.57 jni.cc
--- jni.cc 2001/12/12 20:58:41 1.57
+++ jni.cc 2001/12/16 22:29:11
@@ -13,9 +13,6 @@
#include <stddef.h>
#include <string.h>
-// Define this before including jni.h.
-#define __GCJ_JNI_IMPL__
-
#include <gcj/cni.h>
#include <jvm.h>
#include <java-assert.h>
@@ -41,7 +38,6 @@
#include <java/lang/Integer.h>
#include <java/lang/ThreadGroup.h>
#include <java/lang/Thread.h>
-#include <gnu/gcj/runtime/JNIWeakRef.h>
#include <gcj/method.h>
#include <gcj/field.h>
Index: gcj/libgcj-config.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gcj/libgcj-config.h.in,v
retrieving revision 1.1
diff -u -r1.1 libgcj-config.h.in
--- gcj/libgcj-config.h.in 2001/05/24 05:40:36 1.1
+++ gcj/libgcj-config.h.in 2001/12/16 22:29:12
@@ -3,3 +3,6 @@
/* Define if hash synchronization is in use. */
#undef JV_HASH_SYNCHRONIZATION
+
+/* Define if <inttypes.h> is available. */
+#undef JV_HAVE_INTTYPES_H
Index: include/config.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/config.h.in,v
retrieving revision 1.33
diff -u -r1.33 config.h.in
--- include/config.h.in 2001/09/29 19:16:27 1.33
+++ include/config.h.in 2001/12/16 22:29:13
@@ -148,8 +148,6 @@
/* Define if you have dladdr() */
#undef HAVE_DLADDR
-/* Define if yo have dlopen(). */
-#undef HAVE_DLOPEN
/* Define if getuid() and friends are missing. */
#undef NO_GETUID
@@ -393,4 +391,13 @@
/* Define if struct hostent_data is defined in netdb.h */
#undef HAVE_STRUCT_HOSTENT_DATA
+
+/* Define if dlopen is available */
+#undef HAVE_DLOPEN
+
+/* Define if <inttypes.h> is available */
+#undef HAVE_INTTYPES_H
+
+/* Define if <inttypes.h> is available */
+#undef JV_HAVE_INTTYPES_H
Index: include/jni.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jni.h,v
retrieving revision 1.15
diff -u -r1.15 jni.h
--- include/jni.h 2001/10/27 18:24:51 1.15
+++ include/jni.h 2001/12/16 22:29:13
@@ -14,14 +14,21 @@
#ifndef __GCJ_JNI_H__
#define __GCJ_JNI_H__
+#include <gcj/libgcj-config.h>
+
#include <stdarg.h>
#define _Jv_va_list va_list
-#ifdef __cplusplus
+#ifdef __GCJ_JNI_IMPL__
-/* This is wrong, because it pollutes the name-space too much! */
+/* If __GCJ_JNI_IMPL__ is defined, then we assume that we're building
+ libgcj itself, and we include headers which taint the namespace
+ more than is acceptable for the ordinary JNI user. */
#include <gcj/javaprims.h>
#include <gcj/array.h>
+#include <gnu/gcj/runtime/JNIWeakRef.h>
+
+typedef gnu::gcj::runtime::JNIWeakRef *jweak;
typedef struct _Jv_JNIEnv JNIEnv;
typedef struct _Jv_JavaVM JavaVM;
@@ -29,8 +36,12 @@
#define JNI_TRUE true
#define JNI_FALSE false
-#else /* __cplusplus */
+#else /* __GCJ_JNI_IMPL__ */
+# ifdef __GNUC__
+
+/* If we're using gcc, we can use a platform-independent scheme to get
+ the right integer types. */
typedef int jbyte __attribute__((__mode__(__QI__)));
typedef int jshort __attribute__((__mode__(__HI__)));
typedef int jint __attribute__((__mode__(__SI__)));
@@ -41,11 +52,85 @@
typedef double jdouble;
typedef jint jsize;
+# else /* __GNUC__ */
+
+# ifdef JV_HAVE_INTTYPES_H
+
+/* If <inttypes.h> is available, we use it. */
+
+# include <inttypes.h>
+
+typedef int8_t jbyte;
+typedef int16_t jshort;
+typedef int32_t jint;
+typedef int64_t jlong;
+typedef float jfloat;
+typedef double jdouble;
+typedef jint jsize;
+typedef int8_t jboolean;
+typedef uint16_t jchar;
+
+# else /* JV_HAVE_INTTYPES_H */
+
+/* For now, we require either gcc or <inttypes.h>. If we did more
+ work at configure time we could get around this, but right now it
+ doesn't seem worth it. */
+# error jni.h not ported to this platform
+
+# endif /* JV_HAVE_INTTYPES_H */
+
+# endif /* __GNUC__ */
+
+# ifdef __cplusplus
+
+/* Define dummy classes and then define the JNI types as pointers. */
+struct __jobject {};
+struct __jclass : __jobject {};
+struct __jstring : __jobject {};
+struct __jthrowable : __jobject {};
+struct __jweak : __jobject {};
+struct __jarray : __jobject {};
+struct __jobjectArray : __jarray {};
+struct __jbyteArray : __jarray {};
+struct __jshortArray : __jarray {};
+struct __jintArray : __jarray {};
+struct __jlongArray : __jarray {};
+struct __jbooleanArray : __jarray {};
+struct __jcharArray : __jarray {};
+struct __jfloatArray : __jarray {};
+struct __jdoubleArray : __jarray {};
+
+typedef __jobject *jobject;
+typedef __jclass *jclass;
+typedef __jstring *jstring;
+typedef __jthrowable *jthrowable;
+typedef __jweak *jweak;
+typedef __jarray *jarray;
+typedef __jobjectArray *jobjectArray;
+typedef __jbyteArray *jbyteArray;
+typedef __jshortArray *jshortArray;
+typedef __jintArray *jintArray;
+typedef __jlongArray *jlongArray;
+typedef __jbooleanArray *jbooleanArray;
+typedef __jcharArray *jcharArray;
+typedef __jfloatArray *jfloatArray;
+typedef __jdoubleArray *jdoubleArray;
+
+#define JNI_TRUE true
+#define JNI_FALSE false
+
+typedef struct _Jv_JNIEnv JNIEnv;
+typedef struct _Jv_JavaVM JavaVM;
+
+# else /* __cplusplus */
+
+/* For C, simply define the class types as generic pointers. */
typedef void *jobject;
typedef jobject jclass;
typedef jobject jstring;
-typedef jobject jarray;
typedef jobject jthrowable;
+typedef jobject jweak;
+typedef jobject jarray;
typedef jobject jobjectArray;
typedef jobject jbyteArray;
typedef jobject jshortArray;
@@ -56,20 +141,19 @@
typedef jobject jfloatArray;
typedef jobject jdoubleArray;
-/* Dummy defines. */
-typedef void *jfieldID;
-typedef void *jmethodID;
+#define JNI_TRUE 1
+#define JNI_FALSE 0
typedef const struct JNINativeInterface *JNIEnv;
typedef const struct JNIInvokeInterface *JavaVM;
-#define JNI_TRUE 1
-#define JNI_FALSE 0
+# endif /* __cplusplus */
-#endif /* __cplusplus */
+/* Dummy defines. */
+typedef void *jfieldID;
+typedef void *jmethodID;
-/* FIXME: this is wrong. */
-typedef jobject jweak;
+#endif /* __GCJ_JNI_IMPL__ */
/* Version numbers. */
#define JNI_VERSION_1_1 0x00010001
@@ -558,7 +642,7 @@
/* The method table. */
struct JNINativeInterface *p;
- /* FIXME: this is really ugly. */
+ /* This is ugly, but we must live with it. */
#ifndef __GCJ_JNI_IMPL__
private:
#endif
Index: include/jvm.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.48
diff -u -r1.48 jvm.h
--- include/jvm.h 2001/12/15 08:31:48 1.48
+++ include/jvm.h 2001/12/16 22:29:14
@@ -11,6 +11,12 @@
#ifndef __JAVA_JVM_H__
#define __JAVA_JVM_H__
+// Define this before including jni.h.
+// jni.h is included by jvmpi.h, which might be included. We define
+// this unconditionally because it is convenient and it lets other
+// files include jni.h without difficulty.
+#define __GCJ_JNI_IMPL__
+
#include <gcj/javaprims.h>
#include <java-assert.h>
@@ -358,6 +364,7 @@
bool _Jv_ClassNameSamePackage (_Jv_Utf8Const *name1, _Jv_Utf8Const *name2);
#ifdef ENABLE_JVMPI
+
#include "jvmpi.h"
extern void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);