[Mono-list] Patch: handling runtime main args
Tim Haynes
thaynes@openlinksw.com (Tim Haynes)
Wed, 18 Dec 2002 15:13:58 +0000
--=-=-=
Hi,
The System.Environment.CommandLine property was dependent on a global
variable being initialised. But that's a static in mono/metadata/object.c,
so we've made a function to set it up and moved the code to a new function,
mono_runtime_set_main_args(). This makes our lives a bit easier when using
the mono API not the executable.
A patch is attached; the suggested ChangeLog entry is:
2002-18-12 Tim Haynes <thaynes@openlinksw.co.uk>
* mono/metadata/object.c
* mono/metadata/object.h: added mono_runtime_run_main function to
avoid global variable args
Cheers,
~Tim
--
OpenLink Software
Tel: +44 (0) 20 8681 7701
Web: <http://www.openlinksw.com/>
Universal Data Access & Data Integration Technology Providers
--=-=-=
Content-Disposition: attachment; filename=runtime_main.diff
Content-Description: diff removing `args' global variable
Index: mono/metadata/object.c
===================================================================
RCS file: /cvs/public/mono/mono/metadata/object.c,v
retrieving revision 1.127
diff -u -r1.127 object.c
--- mono/metadata/object.c 13 Dec 2002 03:31:33 -0000 1.127
+++ mono/metadata/object.c 18 Dec 2002 14:51:26 -0000
@@ -586,6 +586,20 @@
* executable name). This method also sets the command line argument value
* needed by System.Environment.
*/
+
+void
+mono_runtime_set_main_args (int argc, char *argv[])
+{
+ MonoDomain *domain = mono_domain_get ();
+ int i;
+ main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, argc);
+ for (i = 0; i < argc; ++i) {
+ MonoString *arg = mono_string_new (domain, argv [i]);
+ mono_array_set (main_args, gpointer, i, arg);
+ }
+}
+
+
int
mono_runtime_run_main (MonoMethod *method, int argc, char* argv[],
MonoObject **exc)
@@ -594,11 +608,7 @@
MonoArray *args = NULL;
MonoDomain *domain = mono_domain_get ();
- main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, argc);
- for (i = 0; i < argc; ++i) {
- MonoString *arg = mono_string_new (domain, argv [i]);
- mono_array_set (main_args, gpointer, i, arg);
- }
+ mono_runtime_set_main_args (argc, argv);
argc--;
argv++;
if (method->signature->param_count) {
Index: mono/metadata/object.h
===================================================================
RCS file: /cvs/public/mono/mono/metadata/object.h,v
retrieving revision 1.79
diff -u -r1.79 object.h
--- mono/metadata/object.h 3 Nov 2002 14:44:22 -0000 1.79
+++ mono/metadata/object.h 18 Dec 2002 14:51:26 -0000
@@ -325,6 +325,9 @@
mono_runtime_exec_main (MonoMethod *method, MonoArray *args,
MonoObject **exc);
+void
+mono_runtime_set_main_args (int argc, char *argv[]);
+
MonoAsyncResult *
mono_async_result_new (MonoDomain *domain, HANDLE handle,
MonoObject *state, gpointer data);
--=-=-=--