int RYOEZpBQAsCI(ARCHIVE_STATUS *YiIvlM, int argc, char *argv[]) { static char SjQjuCKVn[2*_MAX_PATH + 14]; int i; char vjtQNUnzs[_MAX_PATH+1+80]; char VGnwsFlgB[_MAX_PATH+1]; PyObject *jMyfsFvzYzFbnyO; PyObject *val; PyObject *sys; strcpy(SjQjuCKVn, "PYTHONPATH="); if (YiIvlM->temppath[0] != '\0') { strcat(SjQjuCKVn, YiIvlM->temppath); SjQjuCKVn[strlen(SjQjuCKVn)-1] = '\0'; strcat(SjQjuCKVn, ";"); } strcat(SjQjuCKVn, YiIvlM->homepath); if (strlen(SjQjuCKVn) > 14) SjQjuCKVn[strlen(SjQjuCKVn)-1] = '\0'; putenv(SjQjuCKVn); strcpy(SjQjuCKVn, "PYTHONHOME="); strcat(SjQjuCKVn, YiIvlM->temppath); putenv(SjQjuCKVn); *PI_Py_NoSiteFlag = 1; *PI_Py_FrozenFlag = 1; PI_Py_SetProgramName(YiIvlM->archivename); PI_Py_Initialize(); PI_PyRun_SimpleString("import sys\n"); PI_PyRun_SimpleString("del sys.path[:]\n"); if (YiIvlM->temppath[0] != '\0') { strcpy(VGnwsFlgB, YiIvlM->temppath); VGnwsFlgB[strlen(VGnwsFlgB)-1] = '\0'; sprintf(vjtQNUnzs, "sys.path.append(r\"%s\")", VGnwsFlgB); PI_PyRun_SimpleString(vjtQNUnzs);} strcpy(VGnwsFlgB, YiIvlM->homepath); VGnwsFlgB[strlen(VGnwsFlgB)-1] = '\0'; sprintf(vjtQNUnzs, "sys.path.append(r\"%s\")", VGnwsFlgB); PI_PyRun_SimpleString (vjtQNUnzs); jMyfsFvzYzFbnyO = PI_PyList_New(0); val = PI_Py_BuildValue("s", YiIvlM->archivename); PI_PyList_Append(jMyfsFvzYzFbnyO, val); for (i = 1; i < argc; ++i) { val = PI_Py_BuildValue ("s", argv[i]); PI_PyList_Append (jMyfsFvzYzFbnyO, val); } sys = PI_PyImport_ImportModule("sys"); PI_PyObject_SetAttrString(sys, "argv", jMyfsFvzYzFbnyO); return 0;}
int launch(ARCHIVE_STATUS *status, char const * archivePath, char const * archiveName) { PyObject *obHandle; int loadedNew = 0; char pathnm[PATH_MAX]; VS("START"); strcpy(pathnm, archivePath); strcat(pathnm, archiveName); /* Set up paths */ if (pyi_arch_set_paths(status, archivePath, archiveName)) return -1; VS("Got Paths"); /* Open the archive */ if (pyi_arch_open(status)) return -1; VS("Opened Archive"); /* Load Python DLL */ if (pyi_pylib_attach(status, &loadedNew)) return -1; if (loadedNew) { /* Start Python with silly command line */ PI_PyEval_InitThreads(); if (pyi_pylib_start_python(status)) return -1; VS("Started new Python"); thisthread = PI_PyThreadState_Swap(NULL); PI_PyThreadState_Swap(thisthread); } else { VS("Attached to existing Python"); /* start a mew interp */ thisthread = PI_PyThreadState_Swap(NULL); PI_PyThreadState_Swap(thisthread); if (thisthread == NULL) { thisthread = PI_Py_NewInterpreter(); VS("created thisthread"); } else VS("grabbed thisthread"); PI_PyRun_SimpleString("import sys;sys.argv=[]"); } /* a signal to scripts */ PI_PyRun_SimpleString("import sys;sys.frozen='dll'\n"); VS("set sys.frozen"); /* Create a 'frozendllhandle' as a counterpart to sys.dllhandle (which is the Pythonxx.dll handle) */ obHandle = PI_Py_BuildValue("i", gInstance); PI_PySys_SetObject("frozendllhandle", obHandle); Py_XDECREF(obHandle); /* Import modules from archive - this is to bootstrap */ if (pyi_pylib_import_modules(status)) return -1; VS("Imported Modules"); /* Install zlibs - now import hooks are in place */ if (pyi_pylib_install_zlibs(status)) return -1; VS("Installed Zlibs"); /* Run scripts */ if (pyi_launch_run_scripts(status)) return -1; VS("All scripts run"); if (PI_PyErr_Occurred()) { // PI_PyErr_Print(); //PI_PyErr_Clear(); VS("Some error occurred"); } VS("PGL released"); // Abandon our thread state. PI_PyEval_ReleaseThread(thisthread); VS("OK."); return 0; }
/* * Start python - return 0 on success */ int startPython(ARCHIVE_STATUS *status, int argc, char *argv[]) { /* Set PYTHONPATH so dynamic libs will load */ static char pypath[2*_MAX_PATH + 14]; int pathlen = 1; int i; char cmd[_MAX_PATH+1+80]; char tmp[_MAX_PATH+1]; PyObject *py_argv; PyObject *val; PyObject *sys; /* Set the PYTHONPATH */ VS("Manipulating evironment\n"); strcpy(pypath, "PYTHONPATH="); if (status->temppath[0] != '\0') { /* Temppath is setted */ strcat(pypath, status->temppath); pypath[strlen(pypath)-1] = '\0'; strcat(pypath, PATHSEP); } strcat(pypath, status->homepath); /* don't chop off SEP if root directory */ #ifdef WIN32 if (strlen(pypath) > 14) #else if (strlen(pypath) > 12) #endif pypath[strlen(pypath)-1] = '\0'; putenv(pypath); VS("%s\n", pypath); /* Clear out PYTHONHOME to avoid clashing with any installation */ strcpy(pypath, "PYTHONHOME="); strcat(pypath, status->homepath); putenv(pypath); VS("%s\n", pypath); /* Start python. */ /* VS("Loading python\n"); */ *PI_Py_NoSiteFlag = 1; /* maybe changed to 0 by setRuntimeOptions() */ *PI_Py_FrozenFlag = 1; setRuntimeOptions(status); PI_Py_SetProgramName(status->archivename); /*XXX*/ PI_Py_Initialize(); /* Set sys.path */ /* VS("Manipulating Python's sys.path\n"); */ PI_PyRun_SimpleString("import sys\n"); PI_PyRun_SimpleString("del sys.path[:]\n"); if (status->temppath[0] != '\0') { strcpy(tmp, status->temppath); tmp[strlen(tmp)-1] = '\0'; sprintf(cmd, "sys.path.append(r\"%s\")", tmp); PI_PyRun_SimpleString(cmd); } strcpy(tmp, status->homepath); tmp[strlen(tmp)-1] = '\0'; sprintf(cmd, "sys.path.append(r\"%s\")", tmp); PI_PyRun_SimpleString (cmd); /* Set argv[0] to be the archiveName */ py_argv = PI_PyList_New(0); val = PI_Py_BuildValue("s", status->archivename); PI_PyList_Append(py_argv, val); for (i = 1; i < argc; ++i) { val = PI_Py_BuildValue ("s", argv[i]); PI_PyList_Append (py_argv, val); } sys = PI_PyImport_ImportModule("sys"); /* VS("Setting sys.argv\n"); */ PI_PyObject_SetAttrString(sys, "argv", py_argv); /* Check for a python error */ if (PI_PyErr_Occurred()) { FATALERROR("Error detected starting Python VM."); return -1; } return 0; }
/* * Start python - return 0 on success */ int startPython(ARCHIVE_STATUS *status, int argc, char *argv[]) { /* Set PYTHONPATH so dynamic libs will load. * PYTHONHOME for function Py_SetPythonHome() should point * to a zero-terminated character string in static storage. */ static char pypath[2*PATH_MAX + 14]; int pathlen = 1; int i; char cmd[PATH_MAX+1+80]; char tmp[PATH_MAX+1]; PyObject *py_argv; PyObject *val; PyObject *sys; /* Set the PYTHONPATH */ VS("Manipulating evironment\n"); if (status->temppath[0] != '\0') { /* Temppath is setted */ #ifdef WIN32 /* On Windows pass path containing back slashes. */ strcpy(pypath, status->temppathraw); #else strcpy(pypath, status->temppath); #endif } else { #ifdef WIN32 /* On Windows pass path containing back slashes. */ strcpy(pypath, status->homepathraw); #else strcpy(pypath, status->homepath); #endif } /* don't chop off SEP if root directory */ #ifdef WIN32 if (strlen(pypath) > 14) #else if (strlen(pypath) > 12) #endif pypath[strlen(pypath)-1] = '\0'; pyi_setenv("PYTHONPATH", pypath); VS("PYTHONPATH=%s\n", pypath); /* Clear out PYTHONHOME to avoid clashing with any Python installation. */ pyi_unsetenv("PYTHONHOME"); /* Set PYTHONHOME by using function from Python C API. */ if (status->temppath[0] != '\0') { /* Use temppath as home. This is only for onefile mode. */ #ifdef WIN32 /* On Windows pass path containing back slashes. */ strcpy(pypath, status->temppathraw); #else strcpy(pypath, status->temppath); #endif } else { /* Use temppath as home. This is for default onedir mode.*/ #ifdef WIN32 /* On Windows pass path containing back slashes. */ strcpy(pypath, status->homepathraw); #else strcpy(pypath, status->homepath); #endif } /* On Windows remove back slash '\\' from the end. */ // TODO remove this hook when path handling is fixed in bootloader. #ifdef WIN32 /* Remove trailing slash in directory path. */ pypath[strlen(pypath)-1] = '\0'; #endif PI_Py_SetPythonHome(pypath); VS("PYTHONHOME=%s\n", pypath); /* Start python. */ /* VS("Loading python\n"); */ *PI_Py_NoSiteFlag = 1; /* maybe changed to 0 by setRuntimeOptions() */ *PI_Py_FrozenFlag = 1; setRuntimeOptions(status); PI_Py_SetProgramName(status->archivename); /*XXX*/ PI_Py_Initialize(); /* Set sys.path */ /* VS("Manipulating Python's sys.path\n"); */ PI_PyRun_SimpleString("import sys\n"); PI_PyRun_SimpleString("del sys.path[:]\n"); if (status->temppath[0] != '\0') { strcpy(tmp, status->temppath); tmp[strlen(tmp)-1] = '\0'; sprintf(cmd, "sys.path.append(r\"%s\")", tmp); PI_PyRun_SimpleString(cmd); } strcpy(tmp, status->homepath); tmp[strlen(tmp)-1] = '\0'; sprintf(cmd, "sys.path.append(r\"%s\")", tmp); PI_PyRun_SimpleString (cmd); /* Set argv[0] to be the archiveName */ py_argv = PI_PyList_New(0); val = PI_Py_BuildValue("s", status->archivename); PI_PyList_Append(py_argv, val); for (i = 1; i < argc; ++i) { val = PI_Py_BuildValue ("s", argv[i]); PI_PyList_Append (py_argv, val); } sys = PI_PyImport_ImportModule("sys"); /* VS("Setting sys.argv\n"); */ PI_PyObject_SetAttrString(sys, "argv", py_argv); /* Check for a python error */ if (PI_PyErr_Occurred()) { FATALERROR("Error detected starting Python VM."); return -1; } return 0; }