[runtime] Mark mono_runtime_run_main external only.
authorAleksey Kliger <aleksey@xamarin.com>
Wed, 1 Jun 2016 22:01:43 +0000 (18:01 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Thu, 2 Jun 2016 14:42:46 +0000 (10:42 -0400)
Runtime should use mono_runtime_run_main_checked or mono_runtime_try_run_main

mono/metadata/coree.c
mono/metadata/object-internals.h
mono/metadata/object.c
mono/metadata/object.h
mono/mini/driver.c

index 326251cc140c53a575ff7e227abcdeea92bc2782..f0e2f0d58c8fcbf1fdc89d337f116e67a0376762 100644 (file)
@@ -197,7 +197,8 @@ __int32 STDMETHODCALLTYPE _CorExeMain(void)
                argv [i] = g_utf16_to_utf8 (argvw [i], -1, NULL, NULL, NULL);
        LocalFree (argvw);
 
-       mono_runtime_run_main (method, argc, argv, NULL);
+       mono_runtime_run_main_checked (method, argc, argv, &error);
+       mono_error_raise_exception (&error); /* FIXME don't raise here */
        mono_thread_manage ();
 
        mono_runtime_quit ();
index 9accbe3a410b721c35888d8917f3e5aff18e726a..fc3cb822d1694643b5a89f02eee87bfffd9f728e 100644 (file)
@@ -1738,6 +1738,14 @@ mono_runtime_delegate_invoke_checked (MonoObject *delegate, void **params,
 MonoArray*
 mono_runtime_get_main_args_checked (MonoError *error);
 
+int
+mono_runtime_run_main_checked (MonoMethod *method, int argc, char* argv[],
+                              MonoError *error);
+
+int
+mono_runtime_try_run_main (MonoMethod *method, int argc, char* argv[],
+                          MonoObject **exc, MonoError *error);
+
 int
 mono_runtime_exec_main_checked (MonoMethod *method, MonoArray *args, MonoError *error);
 
index 6cd27da36661e5e06cfc76ed4a4fb876a6f4a1fe..98172647db732eedf19e46f5dbbbcb348cdb9a02 100644 (file)
@@ -4168,22 +4168,14 @@ mono_runtime_set_main_args (int argc, char* argv[])
        return 0;
 }
 
-/**
- * mono_runtime_run_main:
- * @method: the method to start the application with (usually Main)
- * @argc: number of arguments from the command line
- * @argv: array of strings from the command line
- * @exc: excetption results
- *
- * Execute a standard Main() method (argc/argv contains the
- * executable name). This method also sets the command line argument value
- * needed by System.Environment.
- *
+/*
+ * Prepare an array of arguments in order to execute a standard Main()
+ * method (argc/argv contains the executable name). This method also
+ * sets the command line argument value needed by System.Environment.
  * 
  */
-int
-mono_runtime_run_main (MonoMethod *method, int argc, char* argv[],
-                      MonoObject **exc)
+static MonoArray*
+prepare_run_main (MonoMethod *method, int argc, char *argv[])
 {
        MONO_REQ_GC_UNSAFE_MODE;
 
@@ -4274,15 +4266,92 @@ mono_runtime_run_main (MonoMethod *method, int argc, char* argv[],
        
        mono_assembly_set_main (method->klass->image->assembly);
 
+       return args;
+}
+
+/**
+ * mono_runtime_run_main:
+ * @method: the method to start the application with (usually Main)
+ * @argc: number of arguments from the command line
+ * @argv: array of strings from the command line
+ * @exc: excetption results
+ *
+ * Execute a standard Main() method (argc/argv contains the
+ * executable name). This method also sets the command line argument value
+ * needed by System.Environment.
+ *
+ * 
+ */
+int
+mono_runtime_run_main (MonoMethod *method, int argc, char* argv[],
+                      MonoObject **exc)
+{
+       MONO_REQ_GC_UNSAFE_MODE;
+
+       MonoError error;
+       MonoArray *args = prepare_run_main (method, argc, argv);
        int res;
-       if (exc)
+       if (exc) {
                res = mono_runtime_try_exec_main (method, args, exc, &error);
-       else
+               if (*exc == NULL && !is_ok (&error))
+                       *exc = (MonoObject*) mono_error_convert_to_exception (&error);
+               else
+                       mono_error_cleanup (&error);
+       } else {
                res = mono_runtime_exec_main_checked (method, args, &error);
-       mono_error_raise_exception (&error); /* FIXME don't raise here */
+               mono_error_raise_exception (&error); /* OK to throw, external only without a better alternative */
+       }
        return res;
 }
 
+/**
+ * mono_runtime_run_main_checked:
+ * @method: the method to start the application with (usually Main)
+ * @argc: number of arguments from the command line
+ * @argv: array of strings from the command line
+ * @error: set on error
+ *
+ * Execute a standard Main() method (argc/argv contains the
+ * executable name). This method also sets the command line argument value
+ * needed by System.Environment.  On failure sets @error.
+ *
+ * 
+ */
+int
+mono_runtime_run_main_checked (MonoMethod *method, int argc, char* argv[],
+                              MonoError *error)
+{
+       mono_error_init (error);
+       MonoArray *args = prepare_run_main (method, argc, argv);
+       return mono_runtime_exec_main_checked (method, args, error);
+}
+
+/**
+ * mono_runtime_try_run_main:
+ * @method: the method to start the application with (usually Main)
+ * @argc: number of arguments from the command line
+ * @argv: array of strings from the command line
+ * @exc: set if Main throws an exception
+ * @error: set if Main can't be executed
+ *
+ * Execute a standard Main() method (argc/argv contains the executable
+ * name). This method also sets the command line argument value needed
+ * by System.Environment.  On failure sets @error if Main can't be
+ * executed or @exc if it threw and exception.
+ *
+ * 
+ */
+int
+mono_runtime_try_run_main (MonoMethod *method, int argc, char* argv[],
+                          MonoObject **exc, MonoError *error)
+{
+       g_assert (exc);
+       mono_error_init (error);
+       MonoArray *args = prepare_run_main (method, argc, argv);
+       return mono_runtime_try_exec_main (method, args, exc, error);
+}
+
+
 static MonoObject*
 serialize_object (MonoObject *obj, gboolean *failure, MonoObject **exc)
 {
index a1551e4eddfd35498b53b316b36be4663e1d42bb..24f7284e8e29fe365e3933622a98983951e09830 100644 (file)
@@ -279,6 +279,7 @@ mono_runtime_exec_managed_code (MonoDomain *domain,
                                MonoMainThreadFunc main_func,
                                void* main_args);
 
+MONO_RT_EXTERNAL_ONLY
 MONO_API int
 mono_runtime_run_main      (MonoMethod *method, int argc, char* argv[], 
                             MonoObject **exc);
index 1a7b15b6f55ad75f301e44531a82e8714d3c280d..9835ccc6f08b2245239554a00de8408dd45c412f 100644 (file)
@@ -1026,10 +1026,14 @@ mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[
        }
        
        if (mono_llvm_only) {
-               MonoObject *exc;
+               MonoObject *exc = NULL;
                int res;
 
-               res = mono_runtime_run_main (method, argc, argv, &exc);
+               res = mono_runtime_try_run_main (method, argc, argv, &exc, &error);
+               if (exc == NULL && !is_ok (&error))
+                       exc = (MonoObject*) mono_error_convert_to_exception (&error);
+               else
+                       mono_error_cleanup (&error);
                if (exc) {
                        mono_unhandled_exception (exc);
                        mono_invoke_unhandled_exception_hook (exc);
@@ -1037,7 +1041,9 @@ mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[
                }
                return res;
        } else {
-               return mono_runtime_run_main (method, argc, argv, NULL);
+               int res = mono_runtime_run_main_checked (method, argc, argv, &error);
+               mono_error_raise_exception (&error); /* FIXME don't raise here */
+               return res;
        }
 }