int mini_debugger_main (MonoDomain *domain, MonoAssembly *assembly, int argc, char **argv) { MainThreadArgs main_args; MonoImage *image; MonoMethod *main_method; /* * Get and compile the main function. */ image = mono_assembly_get_image (assembly); main_method = mono_get_method (image, mono_image_get_entry_point (image), NULL); /* * Initialize managed code. */ mono_debugger_event (MONO_DEBUGGER_EVENT_INITIALIZE_MANAGED_CODE, (guint64) (gssize) main_method, 0); /* * Start the main thread and wait until it's ready. */ main_args.domain = domain; main_args.method = main_method; main_args.argc = argc; main_args.argv = argv; #if RUN_IN_SUBTHREAD mono_thread_create (domain, main_thread_handler, &main_args); #else main_thread_handler (&main_args); #endif mono_thread_manage (); /* * This will never return. */ mono_debugger_event (MONO_DEBUGGER_EVENT_WRAPPER_MAIN, 0, 0); return 0; }
// initialize Mono and PythonNet PyNet_Args* PyNet_Init(int ext) { PyNet_Args *pn_args; pn_args = (PyNet_Args *)malloc(sizeof(PyNet_Args)); pn_args->pr_file = PR_ASSEMBLY; pn_args->error = NULL; pn_args->shutdown = NULL; pn_args->module = NULL; if (ext == 0) { pn_args->init_name = "Python.Runtime:Initialize()"; } else { pn_args->init_name = "Python.Runtime:InitExt()"; } pn_args->shutdown_name = "Python.Runtime:Shutdown()"; pn_args->domain = mono_jit_init_version(MONO_DOMAIN, MONO_VERSION); /* * Load the default Mono configuration file, this is needed * if you are planning on using the dllmaps defined on the * system configuration */ mono_config_parse(NULL); /* I can't use this call to run the main_thread_handler. The function * runs it in another thread but *this* thread holds the Python * import lock -> DEAD LOCK. * * mono_runtime_exec_managed_code(pn_args->domain, main_thread_handler, * pn_args); */ main_thread_handler(pn_args); if (pn_args->error != NULL) { PyErr_SetString(PyExc_ImportError, pn_args->error); } return pn_args; }