/*perllib.c*/ EXTERN_C HANDLE w32_perldll_handle; EXTERN_C int PGC_Count; EXTERN_C DllExport int RunPerl(int argc, char **argv, char **env) { int exitstatus; PerlInterpreter *my_perl, *new_perl = NULL; OSVERSIONINFO osver; char szModuleName[MAX_PATH]; char *arg0 = argv[0]; char *ansi = NULL; bool use_environ = (env == environ); osver.dwOSVersionInfoSize = sizeof(osver); GetVersionEx(&osver); if (osver.dwMajorVersion > 4) { WCHAR widename[MAX_PATH]; GetModuleFileNameW(NULL, widename, sizeof(widename)/sizeof(WCHAR)); argv[0] = ansi = win32_ansipath(widename); } else { Win_GetModuleFileName(NULL, szModuleName, sizeof(szModuleName)); (void)win32_longpath(szModuleName); argv[0] = szModuleName; } #ifdef PERL_GLOBAL_STRUCT #define PERLVAR(prefix,var,type) /**/ #define PERLVARA(prefix,var,type) /**/ #define PERLVARI(prefix,var,type,init) PL_Vars.prefix##var = init; #define PERLVARIC(prefix,var,type,init) PL_Vars.prefix##var = init; #include "perlvars.h" #undef PERLVAR #undef PERLVARA #undef PERLVARI #undef PERLVARIC #endif PERL_SYS_INIT(&argc,&argv); if (!(my_perl = perl_alloc())) return (1); perl_construct(my_perl); PL_perl_destruct_level = 0; /* PERL_SYS_INIT() may update the environment, e.g. via ansify_path(). * This may reallocate the RTL environment block. Therefore we need * to make sure that `env` continues to have the same value as `environ` * if we have been called this way. If we have been called with any * other value for `env` then all environment munging by PERL_SYS_INIT() * will be lost again. */ if (use_environ) env = environ; exitstatus = perl_parse(my_perl, xs_init, argc, argv, env); if (!exitstatus) { #if defined(TOP_CLONE) && defined(USE_ITHREADS) /* XXXXXX testing */ new_perl = perl_clone(my_perl, 1); exitstatus = perl_run(new_perl); PERL_SET_THX(my_perl); #else exitstatus = perl_run(my_perl); #endif } perl_destruct(my_perl); perl_free(my_perl); #ifdef USE_ITHREADS if (new_perl) { PERL_SET_THX(new_perl); perl_destruct(new_perl); perl_free(new_perl); } #endif /* Some RTLs may want to free argv[] after main() returns. */ argv[0] = arg0; if (ansi) win32_free(ansi); PERL_SYS_TERM(); fprintf(stderr, "PGC count %u\n", PGC_Count); return (exitstatus); }