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: Set gnu.gcj.progname safely


Andrew,

I'm satisfied enough with this to release this. Like I said,
stack traces hang on my machine, but this happens
with the unadulterated 3.3 branch too. I haven't tested
the MingW build but am doing this now and am pretty
confident of the outcome. I wanted to release this already
because people seem in a hurry to have it.

I've also attached my test, which consists of two programs:
a JNI-invoked one which failed prior to this patch and a
vanilla one. If you don't specify a command line argument to
progJ on my machine, it will hang due to the stack trace triggered
by the ArrayIndexOutOfBoundsException, so be sure to use
./progJ xxx, for example.

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/

ChangeLog
2003-03-29  Mohan Embar  <gnustuff at thisiscool dot com>

	* include/jvm.h: (_Jv_GetNbArgs) added
	(_Jv_GetSafeArg) added
	(_Jv_SetArgs) added
	* prims.cc: (_Jv_GetNbArgs) implemented
	(_Jv_GetSafeArg) implemented
	(_Jv_SetArgs) implemented
	(_Jv_RunMain) use _Jv_SetArgs() instead of explicitly
	setting _Jv_argc and _Jv_argv
	* posix.cc: (_Jv_ThisExecutable) use _Jv_GetSafeArg()
	instead of _Jv_argv
	* java/lang/natRuntime.cc: (insertSystemProperties) use
	_Jv_GetSafeArg() instead of _Jv_argv

Index: include/jvm.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.52.8.1
diff -u -2 -r1.52.8.1 jvm.h
--- include/jvm.h	10 Mar 2003 19:34:30 -0000	1.52.8.1
+++ include/jvm.h	29 Mar 2003 15:38:16 -0000
@@ -353,4 +353,17 @@
 }
 
+/* Get the number of arguments (cf. argc) or 0 if our argument
+   list was never initialized. */
+extern int _Jv_GetNbArgs (void);
+
+/* Get the specified argument (cf. argv[index]) or "" if either
+   our argument list was never initialized or the specified index
+   is out of bounds. */
+extern const char * _Jv_GetSafeArg (int index);
+
+/* Sets our argument list. Can be used by programs with non-standard
+   entry points. */
+extern void _Jv_SetArgs (int argc, const char **argv);
+
 /* Get the name of the running executable. */
 extern const char *_Jv_ThisExecutable (void);
Index: prims.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.76.2.1
diff -u -2 -r1.76.2.1 prims.cc
--- prims.cc	10 Mar 2003 19:34:30 -0000	1.76.2.1
+++ prims.cc	29 Mar 2003 15:38:13 -0000
@@ -91,4 +91,28 @@
 int _Jv_argc;
 
+// Argument support.
+int
+_Jv_GetNbArgs (void)
+{
+	// _Jv_argc is 0 if not explicitly initialized.
+	return _Jv_argc;
+}
+
+const char *
+_Jv_GetSafeArg (int index)
+{
+	if (index >=0 && index < _Jv_GetNbArgs ())
+		return _Jv_argv[index];
+	else
+		return "";
+}
+
+void
+_Jv_SetArgs (int argc, const char **argv)
+{
+	_Jv_argc = argc;
+	_Jv_argv = argv;
+}
+
 #ifdef ENABLE_JVMPI
 // Pointer to JVMPI notification functions.
@@ -937,6 +961,5 @@
 	     bool is_jar)
 {
-  _Jv_argv = argv;
-  _Jv_argc = argc;
+  _Jv_SetArgs (argc, argv);
 
   java::lang::Runtime *runtime = NULL;
Index: posix.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/posix.cc,v
retrieving revision 1.7.20.1
diff -u -2 -r1.7.20.1 posix.cc
--- posix.cc	10 Mar 2003 19:34:30 -0000	1.7.20.1
+++ posix.cc	29 Mar 2003 15:38:11 -0000
@@ -26,7 +26,4 @@
 #endif
 
-// platform-specific executable name
-extern const char **_Jv_argv;
-
 #if defined(HAVE_PROC_SELF_EXE)
 static char exec_name[20];
@@ -42,5 +39,5 @@
     // initialized in _Jv_platform_initialize()
 #else
-  return _Jv_argv[0];
+  return _Jv_GetSafeArg (0);
 #endif
 }
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.29.2.4
diff -u -2 -r1.29.2.4 natRuntime.cc
--- java/lang/natRuntime.cc	10 Mar 2003 19:34:30 -0000	1.29.2.4
+++ java/lang/natRuntime.cc	29 Mar 2003 15:38:19 -0000
@@ -129,8 +129,4 @@
 

 
-extern int _Jv_argc;
-extern const char **_Jv_argv;
-  // our process' command line arguments
-
 void
 java::lang::Runtime::exitInternal (jint status)
@@ -612,5 +608,5 @@
 
   // The name used to invoke this process (argv[0] in C).
-  SET ("gnu.gcj.progname", _Jv_argv[0]);
+  SET ("gnu.gcj.progname", _Jv_GetSafeArg (0));
 
   // Allow platform specific settings and overrides.





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