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]

Patch: FYI: Remove some ifdefs


I'm checking this in on the trunk.

This removes a few platform-specific ifdefs from some of the core and
instead moves them into the platform header.  I think our goal should
be to have no platform-specific (as opposed to feature-specific)
defines in the main code.

There are still some in java.net (Michael Koch may be working on this
though) and a few in jni.cc.  The latter may require some minor code
restructuring.

Tom

Index: libjava/ChangeLog
from  Tom Tromey  <tromey at redhat dot com>

	* resolve.cc (ncode): Use _Jv_platform_ffi_abi.
	Include platform.h.
	* java/lang/natRuntime.cc (insertSystemProperties): Use
	_Jv_platform_path_separator.
	(nativeGetLibname): Use _Jv_platform_file_separator.
	(_load): Use _Jv_platform_onload_names.
	(onload_names): New global.
	* include/win32.h (_Jv_platform_file_separator): New define.
	(_Jv_platform_path_separator): Likewise.
	(_Jv_platform_onload_names): Likewise.
	(_Jv_platform_ffi_abi): Likewise.
	* include/posix.h (_Jv_platform_file_separator): New define.
	(_Jv_platform_path_separator): Likewise.
	(_Jv_platform_onload_names): Likewise.
	(_Jv_platform_ffi_abi): Likewise.

Index: libjava/resolve.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/resolve.cc,v
retrieving revision 1.37
diff -u -r1.37 resolve.cc
--- libjava/resolve.cc 3 Feb 2003 21:07:22 -0000 1.37
+++ libjava/resolve.cc 17 Mar 2003 00:25:41 -0000
@@ -11,6 +11,7 @@
 /* Author: Kresten Krab Thorup <krab at gnu dot org>  */
 
 #include <config.h>
+#include <platform.h>
 
 #include <java-interp.h>
 
@@ -1003,14 +1004,7 @@
   memcpy (&jni_arg_types[offset], &closure->arg_types[0],
 	  arg_count * sizeof (ffi_type *));
 
-  // NOTE: This must agree with the JNICALL definition in jni.h
-#ifdef WIN32
-#define FFI_JNI_ABI FFI_STDCALL
-#else
-#define FFI_JNI_ABI FFI_DEFAULT_ABI
-#endif
-
-  if (ffi_prep_cif (&jni_cif, FFI_JNI_ABI,
+  if (ffi_prep_cif (&jni_cif, _Jv_platform_ffi_abi,
 		    extra_args + arg_count, rtype,
 		    jni_arg_types) != FFI_OK)
     throw_internal_error ("ffi_prep_cif failed for JNI function");
Index: libjava/include/posix.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/posix.h,v
retrieving revision 1.16
diff -u -r1.16 posix.h
--- libjava/include/posix.h 19 Feb 2003 16:28:37 -0000 1.16
+++ libjava/include/posix.h 17 Mar 2003 00:25:41 -0000
@@ -44,6 +44,18 @@
 #define _Jv_platform_solib_prefix "lib"
 #define _Jv_platform_solib_suffix ".so"
 
+// Separator for file name components.
+#define _Jv_platform_file_separator ((jchar) '/')
+// Separator for path components.
+#define _Jv_platform_path_separator ((jchar) ':')
+
+// List of names for `JNI_OnLoad'.
+#define _Jv_platform_onload_names { "JNI_OnLoad", NULL }
+
+// Type of libffi ABI used by JNICALL methods.  NOTE: This must agree
+// with the JNICALL definition in jni.h
+#define _Jv_platform_ffi_abi FFI_DEFAULT_ABI
+
 #ifndef DISABLE_JAVA_NET
 #include <java/net/InetAddress.h>
 #endif
Index: libjava/include/win32.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/win32.h,v
retrieving revision 1.20
diff -u -r1.20 win32.h
--- libjava/include/win32.h 13 Feb 2003 00:07:37 -0000 1.20
+++ libjava/include/win32.h 17 Mar 2003 00:25:41 -0000
@@ -24,6 +24,22 @@
 #define _Jv_platform_solib_prefix ""
 #define _Jv_platform_solib_suffix ".dll"
 
+// Separator for file name components.
+#define _Jv_platform_file_separator ((jchar) '\\')
+// Separator for path components.
+#define _Jv_platform_path_separator ((jchar) ';')
+
+// List of names for `JNI_OnLoad'.  On Win32, JNI_OnLoad is an
+// "stdcall" function taking two pointers (8 bytes) as arguments.  It
+// could also have been exported as "JNI_OnLoad at 8" (MinGW) or
+// "_JNI_OnLoad at 8" (MSVC).
+#define _Jv_platform_onload_names \
+    { "JNI_OnLoad", "JNI_OnLoad at 8", "_JNI_OnLoad at 8", NULL }
+
+// Type of libffi ABI used by JNICALL methods.  NOTE: This must agree
+// with the JNICALL definition in jni.h
+#define _Jv_platform_ffi_abi FFI_STDCALL
+
 #ifndef DISABLE_JAVA_NET
 
 // these errors cannot occur on Win32
Index: libjava/java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.34
diff -u -r1.34 natRuntime.cc
--- libjava/java/lang/natRuntime.cc 10 Mar 2003 19:45:30 -0000 1.34
+++ libjava/java/lang/natRuntime.cc 17 Mar 2003 00:25:42 -0000
@@ -140,6 +140,11 @@
   _Jv_RunGC ();
 }
 
+#ifdef USE_LTDL
+// List of names for JNI_OnLoad.
+static const char *onload_names[] = _Jv_platform_onload_names;
+#endif
+
 void
 java::lang::Runtime::_load (jstring path, jboolean do_search)
 {
@@ -221,19 +226,16 @@
       throw new UnsatisfiedLinkError (str);
     }
 
-  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 at 8" (MinGW) or "_JNI_OnLoad at 8" (MSVC).
-  if (onload == NULL)
-    {
-      onload = lt_dlsym (h, "JNI_OnLoad at 8");
-      if (onload == NULL)
-	onload = lt_dlsym (h, "_JNI_OnLoad at 8");
+  // Search for JNI_OnLoad function.
+  void *onload = NULL;
+  const char **name = onload_names;
+  while (*name != NULL)
+    {
+      onload = lt_dlsym (h, *name);
+      if (onload != NULL)
+	break;
+      ++name;
     }
-#endif /* WIN32 */
 
   if (onload != NULL)
     {
@@ -570,11 +572,7 @@
       if (classpath)
 	{
 	  sb->append (JvNewStringLatin1 (classpath));
-#ifdef WIN32
-	  sb->append ((jchar) ';');
-#else
-	  sb->append ((jchar) ':');
-#endif
+	  sb->append (_Jv_platform_path_separator);
 	}
       if (cp != NULL)
 	sb->append (cp);
@@ -632,14 +630,7 @@
   java::lang::StringBuffer *sb = new java::lang::StringBuffer ();
   sb->append(pathname);
   if (pathname->length() > 0)
-    {
-      // FIXME: use platform function here.
-#ifdef WIN32
-      sb->append ((jchar) '\\');
-#else
-      sb->append ((jchar) '/');
-#endif
-    }
+    sb->append (_Jv_platform_file_separator);
 
   sb->append (JvNewStringLatin1 (_Jv_platform_solib_prefix));
   sb->append(libname);


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