/* * Once init'ed, you might want to extractBinaries() * If you do, what comes after is very platform specific. * Once you've taken care of the platform specific details, * or if there are no binaries to extract, you go on * to pyi_launch_execute(), which is the important part. */ int pyi_launch_execute(ARCHIVE_STATUS *status, int argc, char *argv[]) { int rc = 0; /* Load Python DLL */ if (pyi_pylib_load(status)) { return -1; } else { /* With this flag Python cleanup will be called. */ status->is_pylib_loaded = true; } /* Start Python. */ if (pyi_pylib_start_python(status, argc, argv)) return -1; /* Import modules from archive - bootstrap */ if (pyi_pylib_import_modules(status)) return -1; /* Install zlibs - now all hooks in place */ if (pyi_pylib_install_zlibs(status)) return -1; /* Run scripts */ rc = pyi_pylib_run_scripts(status); VS("LOADER: OK.\n"); return rc; }
/* * Once init'ed, you might want to extractBinaries() * If you do, what comes after is very platform specific. * Once you've taken care of the platform specific details, * or if there are no binaries to extract, you go on * to pyi_launch_execute(), which is the important part. */ int pyi_launch_execute(ARCHIVE_STATUS *status) { int rc = 0; /* Load Python DLL */ if (pyi_pylib_load(status)) { return -1; } else { /* With this flag Python cleanup will be called. */ status->is_pylib_loaded = true; } /* Start Python. */ if (pyi_pylib_start_python(status)) { return -1; } /* Import core pyinstaller modules from the executable - bootstrap */ if (pyi_pylib_import_modules(status)) { return -1; } /* Install zlibs - now all hooks in place */ if (pyi_pylib_install_zlibs(status)) { return -1; } #ifndef WIN32 /* * On Linux sys.getfilesystemencoding() returns None but should not. * If it's None(NULL), get the filesystem encoding by using direct * C calls and override it with correct value. * * TODO: This may not be needed any more. Please confirm on Linux. */ if (!*PI_Py_FileSystemDefaultEncoding) { char *saved_locale, *loc_codeset; saved_locale = strdup(setlocale(LC_CTYPE, NULL)); VS("LOADER: LC_CTYPE was %s but resulted in NULL FileSystemDefaultEncoding\n", saved_locale); setlocale(LC_CTYPE, ""); loc_codeset = nl_langinfo(CODESET); setlocale(LC_CTYPE, saved_locale); free(saved_locale); VS("LOADER: Setting FileSystemDefaultEncoding to %s (was NULL)\n", loc_codeset); *PI_Py_FileSystemDefaultEncoding = loc_codeset; } #endif /* WIN32 */ /* Run scripts */ rc = pyi_launch_run_scripts(status); VS("LOADER: OK.\n"); return rc; }
/* * Once init'ed, you might want to extractBinaries() * If you do, what comes after is very platform specific. * Once you've taken care of the platform specific details, * or if there are no binaries to extract, you go on * to pyi_launch_execute(), which is the important part. */ int pyi_launch_execute(ARCHIVE_STATUS *status, int argc, char *argv[]) { int rc = 0; /* Load Python DLL */ if (pyi_pylib_load(status)) { return -1; } else { /* With this flag Python cleanup will be called. */ status->is_pylib_loaded = true; } /* Start Python. */ if (pyi_pylib_start_python(status, argc, argv)) return -1; /* Import modules from archive - bootstrap */ if (pyi_pylib_import_modules(status)) return -1; /* Install zlibs - now all hooks in place */ if (pyi_pylib_install_zlibs(status)) return -1; /* * On Linux sys.getfilesystemencoding() returns None but should not. * If it's None(NULL), get the filesystem encoding by using direct * C calls and override it with correct value. */ if (!*PI_Py_FileSystemDefaultEncoding) { char *saved_locale, *loc_codeset; saved_locale = strdup(setlocale(LC_CTYPE, NULL)); setlocale(LC_CTYPE, ""); loc_codeset = nl_langinfo(CODESET); setlocale(LC_CTYPE, saved_locale); free(saved_locale); *PI_Py_FileSystemDefaultEncoding = loc_codeset; } /* Run scripts */ rc = pyi_pylib_run_scripts(status); VS("LOADER: OK.\n"); return rc; }
/* * Use this from a dll instead of pyi_pylib_load(). * It will attach to an existing pythonXX.dll or load one if needed. */ int pyi_pylib_attach(ARCHIVE_STATUS *status, int *loadedNew) { #ifdef _WIN32 HMODULE dll; char nm[PATH_MAX + 1]; int pyvers = ntohl(status->cookie.pyvers); int ret = 0; /* Get python's name */ sprintf(nm, "python%02d.dll", pyvers); /* See if it's loaded */ dll = GetModuleHandleA(nm); if (dll == 0) { *loadedNew = 1; return pyi_pylib_load(status); } ret = pyi_python_map_names(dll, pyvers); *loadedNew = 0; return ret; #endif return 0; }