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 for Preview: _Jv_ThisExecutable (The Saga Continues)


Hi Patch People,

Here is a new cut at the _Jv_ThisExecutable() patch, based on this
post:

http://gcc.gnu.org/ml/java/2003-02/msg00517.html

Andrew's idea of moving _Jv_ThisExecutable() to the platform-dependent
files eliminated the need for the autoconf and autoheader insanity of my
previous patch. Also, this patch proposes the elimination of the
_Jv_ThisExecutable() setter. My reasoning is that no one should have any
business deciding this value other than the implementations, and no one
should ever subsequently tamper with it.

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

ChangeLog
2003-02-27  Mohan Embar  <gnustuff at thisiscool dot com>

	* include/jvm.h: removed declaration of _Jv_ThisExecutable()
	setter; made return value of getter const char* instead of char*
	* prims.cc: removed all references to _Jv_ThisExecutable().
	These are in the platform-specific sections now.
	* posix.cc: define platform-specific _Jv_ThisExecutable().
	Handle DISABLE_MAIN_ARGS and HAVE_PROC_SELF_EXE cases
	* win32.cc: define platform-specific _Jv_ThisExecutable()
	using GetModuleFilename()
	* java/lang/natRuntime.cc: set gnu.gcj.progname property
	to argv[0] instead of _Jv_ThisExecutable()

Index: posix.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/posix.cc,v
retrieving revision 1.7
diff -u -2 -r1.7 posix.cc
--- posix.cc	7 Apr 2002 11:26:58 -0000	1.7
+++ posix.cc	27 Feb 2003 15:11:45 -0000
@@ -26,4 +26,24 @@
 #endif
 
+// platform-specific executable name
+extern const char **_Jv_argv;
+
+#if defined(HAVE_PROC_SELF_EXE)
+static char exec_name[20];
+  // initialized in _Jv_platform_initialize()
+#endif
+
+const char *_Jv_ThisExecutable (void)
+{
+#if defined(DISABLE_MAIN_ARGS)
+  return "[Embedded App]";
+#elif defined(HAVE_PROC_SELF_EXE)
+  return exec_name;
+    // initialized in _Jv_platform_initialize()
+#else
+  return _Jv_argv[0];
+#endif
+}
+
 // gettimeofday implementation.
 jlong
@@ -62,4 +82,9 @@
 #else
   signal (SIGPIPE, SIG_IGN);
+#endif
+
+#if defined (HAVE_PROC_SELF_EXE)
+  // Compute our executable name
+  sprintf (exec_name, "/proc/%d/exe", getpid ());
 #endif
 }
Index: prims.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.76
diff -u -2 -r1.76 prims.cc
--- prims.cc	5 Dec 2002 00:49:29 -0000	1.76
+++ prims.cc	27 Feb 2003 15:11:47 -0000
@@ -87,7 +87,4 @@
 #endif
 
-// The name of this executable.
-static char *_Jv_execName;
-
 // Stash the argv pointer to benefit native libraries that need it.
 const char **_Jv_argv;
@@ -708,20 +705,4 @@
 static java::lang::Thread *main_thread;
 
-char *
-_Jv_ThisExecutable (void)
-{
-  return _Jv_execName;
-}
-
-void
-_Jv_ThisExecutable (const char *name)
-{
-  if (name)
-    {
-      _Jv_execName = (char *) _Jv_Malloc (strlen (name) + 1);
-      strcpy (_Jv_execName, name);
-    }
-}
-
 #ifndef DISABLE_GETENV_PROPERTIES
 
@@ -960,17 +941,4 @@
 
   java::lang::Runtime *runtime = NULL;
-
-
-#ifdef DISABLE_MAIN_ARGS
-  _Jv_ThisExecutable ("[Embedded App]");
-#else
-#ifdef HAVE_PROC_SELF_EXE
-  char exec_name[20];
-  sprintf (exec_name, "/proc/%d/exe", getpid ());
-  _Jv_ThisExecutable (exec_name);
-#else
-  _Jv_ThisExecutable (argv[0]);
-#endif /* HAVE_PROC_SELF_EXE */
-#endif /* DISABLE_MAIN_ARGS */
 
   try
Index: win32.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/win32.cc,v
retrieving revision 1.12.22.2
diff -u -2 -r1.12.22.2 win32.cc
--- win32.cc	19 Feb 2003 16:27:22 -0000	1.12.22.2
+++ win32.cc	27 Feb 2003 15:11:47 -0000
@@ -29,4 +29,13 @@
 }
 
+// Platform-specific executable name
+static char exec_name[MAX_PATH];
+  // initialized in _Jv_platform_initialize()
+
+const char *_Jv_ThisExecutable (void)
+{
+  return exec_name;
+}
+
 // Platform-specific VM initialization.
 void
@@ -38,6 +47,10 @@
     MessageBox (NULL, "Error initialising winsock library.", "Error",
 		MB_OK | MB_ICONEXCLAMATION);
+  
   // Install exception handler
   SetUnhandledExceptionFilter (win32_exception_handler);
+  
+  // Initialize our executable name
+  GetModuleFileName(NULL, exec_name, sizeof(exec_name));
 }
 
Index: include/jvm.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.52
diff -u -2 -r1.52 jvm.h
--- include/jvm.h	29 Aug 2002 17:53:28 -0000	1.52
+++ include/jvm.h	27 Feb 2003 15:11:51 -0000
@@ -353,7 +353,6 @@
 }
 
-/* get/set the name of the running executable. */
-extern char *_Jv_ThisExecutable (void);
-extern void _Jv_ThisExecutable (const char *);
+/* Get the name of the running executable. */
+extern const char *_Jv_ThisExecutable (void);
 
 /* Return a pointer to a symbol in executable or loaded library.  */
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.29.2.3
diff -u -2 -r1.29.2.3 natRuntime.cc
--- java/lang/natRuntime.cc	19 Feb 2003 16:18:03 -0000	1.29.2.3
+++ java/lang/natRuntime.cc	27 Feb 2003 15:11:54 -0000
@@ -129,4 +129,8 @@
 

 
+extern int _Jv_argc;
+extern const char **_Jv_argv;
+  // our process' command line arguments
+
 void
 java::lang::Runtime::exitInternal (jint status)
@@ -608,5 +612,5 @@
 
   // The name used to invoke this process (argv[0] in C).
-  SET ("gnu.gcj.progname", _Jv_ThisExecutable());
+  SET ("gnu.gcj.progname", _Jv_argv[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]