Patch: runtime part of gcj -D

Tom Tromey tromey@cygnus.com
Fri Oct 15 09:51:00 GMT 1999


I'm committing the appended patch.

I recently changed the compiler to handle `-D' options.  These are
compiled into the executable as a list of strings.  This patch changes
the runtime to put these strings into the system properties.

You'll need the new compiler for this patch to work at all; without it
you'll get link errors.

1999-10-15  Tom Tromey  <tromey@cygnus.com>

	* gij.cc (main): Formatting fixes.
	(_Jv_Compiler_Properties): Define.
	* java/lang/natSystem.cc (_Jv_Environment_Properties): Don't
	declare.
	(init_properties): Set properites from _Jv_Compiler_Properties.
	* include/java-props.h (_Jv_Compiler_Properties,
	_Jv_Environment_Properties): Declare.

Tom

Index: gij.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/gij.cc,v
retrieving revision 1.3
diff -u -r1.3 gij.cc
--- gij.cc	1999/09/10 22:03:05	1.3
+++ gij.cc	1999/10/15 16:48:02
@@ -15,13 +15,20 @@
 #include <java/lang/System.h>
 #include <java/util/Properties.h>
 
-int main (int argc, const char **argv)
+// This is used to initialize the compiled-in system properties.
+const char *_Jv_Compiler_Properties[] =
 {
+  NULL
+};
+
+int
+main (int argc, const char **argv)
+{
   if (argc < 2)
     {
-      printf ("usage: %s <class name> args\n", argv[0]);
+      printf ("usage: %s CLASS [ARGS]...\n", argv[0]);
       exit (1);
     }
 
-  _Jv_RunMain (argv[1], argc-1, argv+1);
+  _Jv_RunMain (argv[1], argc - 1, argv + 1);
 }
Index: java/lang/natSystem.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natSystem.cc,v
retrieving revision 1.12
diff -u -r1.12 natSystem.cc
--- natSystem.cc	1999/10/15 06:07:41	1.12
+++ natSystem.cc	1999/10/15 16:48:02
@@ -53,7 +53,6 @@
 #define SystemClass _CL_Q34java4lang6System
 extern java::lang::Class SystemClass;
 
-extern property_pair *_Jv_Environment_Properties;
 
 
 #if defined (ECOS)
@@ -336,8 +335,8 @@
 
   while (buf_r != NULL)
     {
-      int r = getpwuid_adaptor
-	(getpwuid_r, user_id, &pwd_r, buf_r, len_r, &pwd_entry);
+      int r = getpwuid_adaptor (getpwuid_r, user_id, &pwd_r,
+				buf_r, len_r, &pwd_entry);
       if (r == 0)
 	break;
       else if (r != ERANGE)
@@ -378,6 +377,19 @@
   if (buffer != NULL)
     free (buffer);
 #endif
+
+  // Set some properties according to whatever was compiled in with
+  // `-D'.
+  for (int i = 0; _Jv_Compiler_Properties[i]; ++i)
+    {
+      const char *s, *p;
+      // Find the `='.
+      for (s = p = _Jv_Compiler_Properties[i]; *s && *s != '='; ++s)
+	;
+      jstring name = JvNewStringLatin1 (p, s - p);
+      jstring val = JvNewStringLatin1 (*s == '=' ? s + 1 : s);
+      properties->put (name, val);
+    }
 
   // Set the system properties from the user's environment.
   if (_Jv_Environment_Properties)
Index: include/java-props.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/java-props.h,v
retrieving revision 1.2
diff -u -r1.2 java-props.h
--- java-props.h	1999/10/15 15:42:26	1.2
+++ java-props.h	1999/10/15 16:48:04
@@ -19,5 +19,11 @@
   size_t      value_length;
 } property_pair;
 
+// The compiler generates this declaration.
+extern char *_Jv_Compiler_Properties[];
+
+// Properties taken from the user's environment.
+extern property_pair *_Jv_Environment_Properties;
+
 #endif
 


More information about the Java-patches mailing list