diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 03e855f6aa7..6765b0e4cd4 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,18 @@ +2003-03-29 Mohan Embar + + * 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 + 2003-04-23 Tom Tromey * resolve.cc (_Jv_PrepareClass): Round size up to alignment diff --git a/libjava/include/jvm.h b/libjava/include/jvm.h index 38f675a1fef..9395feb09c4 100644 --- a/libjava/include/jvm.h +++ b/libjava/include/jvm.h @@ -352,7 +352,20 @@ extern "C" jlong _Jv_remJ (jlong, jlong); } -/* Get the name of the running executable. */ +/* 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); /* Return a pointer to a symbol in executable or loaded library. */ diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index 2cf312ea862..69f78f64491 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -108,10 +108,6 @@ _Jv_SetDLLSearchPath (const char *) -extern int _Jv_argc; -extern const char **_Jv_argv; - // our process' command line arguments - void java::lang::Runtime::exitInternal (jint status) { @@ -590,7 +586,7 @@ java::lang::Runtime::insertSystemProperties (java::util::Properties *newprops) } // 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. _Jv_platform_initProperties (newprops); diff --git a/libjava/posix.cc b/libjava/posix.cc index 2f808334d7c..de58ab025c0 100644 --- a/libjava/posix.cc +++ b/libjava/posix.cc @@ -25,9 +25,6 @@ details. */ extern "C" unsigned long long _clock (void); #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() @@ -41,7 +38,7 @@ const char *_Jv_ThisExecutable (void) return exec_name; // initialized in _Jv_platform_initialize() #else - return _Jv_argv[0]; + return _Jv_GetSafeArg (0); #endif } diff --git a/libjava/prims.cc b/libjava/prims.cc index dc05d4b96ff..9ddd1d2c2af 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -90,6 +90,30 @@ property_pair *_Jv_Environment_Properties; const char **_Jv_argv; 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. void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event); @@ -936,8 +960,7 @@ void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv, bool is_jar) { - _Jv_argv = argv; - _Jv_argc = argc; + _Jv_SetArgs (argc, argv); java::lang::Runtime *runtime = NULL;