From: <th...@us...> - 2003-11-04 08:18:27
|
Update of /cvsroot/py2exe/py2exe/sandbox/source In directory sc8-pr-cvs1:/tmp/cvs-serv13592 Modified Files: start.c Log Message: Whitespace cleanup. Index: start.c =================================================================== RCS file: /cvsroot/py2exe/py2exe/sandbox/source/start.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** start.c 10 Oct 2003 19:23:50 -0000 1.9 --- start.c 4 Nov 2003 08:18:24 -0000 1.10 *************** *** 33,42 **** struct scriptinfo { ! int tag; ! int optimize; ! int unbuffered; int data_bytes; ! char zippath[0]; }; --- 33,42 ---- struct scriptinfo { ! int tag; ! int optimize; ! int unbuffered; int data_bytes; ! char zippath[0]; }; *************** *** 57,124 **** int init_with_instance(HMODULE hmod) { ! /* Open the executable file and map it to memory */ ! if(!GetModuleFileName(hmod, modulename, sizeof(modulename))) { ! SystemError(GetLastError(), "Retrieving module name"); ! return 255; ! } ! { ! char *cp; ! strcpy(dirname, modulename); ! cp = strrchr(dirname, '\\'); ! *cp = '\0'; ! } ! ! { ! HRSRC hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), "PYTHONSCRIPT"); ! HGLOBAL hgbl; ! ! if (!hrsrc) { ! SystemError (GetLastError(), "Could not locate script resource:"); ! return 255; } ! hgbl = LoadResource(hmod, hrsrc); ! if (!hgbl) { ! SystemError (GetLastError(), "Could not load script resource:"); ! return 255; } ! p_script_info = (struct scriptinfo *)pScript = LockResource(hgbl); ! if (!pScript) { ! SystemError (GetLastError(), "Could not lock script resource:"); ! return 255; } - } numScriptBytes = p_script_info->data_bytes; ! pScript += sizeof(struct scriptinfo); ! if (p_script_info->tag != 0x78563412) { ! SystemError (0, "Bug: Invalid script resource"); ! return 255; ! } ! pScript += strlen(p_script_info->zippath) + 1; ! { ! /* If the zip path has any path component, then build our Python ! home directory from that. ! */ ! char buffer[_MAX_PATH + 32]; ! char *fname; ! int lib_dir_len; ! pZipBaseName = pScript - 1; ! while (pZipBaseName > p_script_info->zippath && \ ! *(pZipBaseName-1) != '\\') ! pZipBaseName--; ! strcpy(libdirname, dirname); ! lib_dir_len = pZipBaseName-p_script_info->zippath; /* incl. tail slash */ ! if (lib_dir_len) { ! char *p = libdirname+strlen(libdirname); ! *p++ = '\\'; ! strncpy(p, p_script_info->zippath, lib_dir_len-1); ! p += lib_dir_len-1; ! *p++ = '\0'; } ! /* Fully-qualify it */ ! GetFullPathName(libdirname, sizeof(libdirname), libdirname, &fname); ! /* From Barry Scott */ ! /* Must not set the PYTHONHOME env var as this prevents ! python being used in os.system or os.popen */ ! Py_SetPythonHome(libdirname); /* --- 57,124 ---- int init_with_instance(HMODULE hmod) { ! /* Open the executable file and map it to memory */ ! if(!GetModuleFileName(hmod, modulename, sizeof(modulename))) { ! SystemError(GetLastError(), "Retrieving module name"); ! return 255; } ! { ! char *cp; ! strcpy(dirname, modulename); ! cp = strrchr(dirname, '\\'); ! *cp = '\0'; } ! ! { ! HRSRC hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), "PYTHONSCRIPT"); ! HGLOBAL hgbl; ! ! if (!hrsrc) { ! SystemError (GetLastError(), "Could not locate script resource:"); ! return 255; ! } ! hgbl = LoadResource(hmod, hrsrc); ! if (!hgbl) { ! SystemError (GetLastError(), "Could not load script resource:"); ! return 255; ! } ! p_script_info = (struct scriptinfo *)pScript = LockResource(hgbl); ! if (!pScript) { ! SystemError (GetLastError(), "Could not lock script resource:"); ! return 255; ! } } numScriptBytes = p_script_info->data_bytes; ! pScript += sizeof(struct scriptinfo); ! if (p_script_info->tag != 0x78563412) { ! SystemError (0, "Bug: Invalid script resource"); ! return 255; } ! pScript += strlen(p_script_info->zippath) + 1; ! { ! /* If the zip path has any path component, then build our Python ! home directory from that. ! */ ! char buffer[_MAX_PATH + 32]; ! char *fname; ! int lib_dir_len; ! pZipBaseName = pScript - 1; ! while (pZipBaseName > p_script_info->zippath && \ ! *(pZipBaseName-1) != '\\') ! pZipBaseName--; ! strcpy(libdirname, dirname); ! lib_dir_len = pZipBaseName-p_script_info->zippath; /* incl. tail slash */ ! if (lib_dir_len) { ! char *p = libdirname+strlen(libdirname); ! *p++ = '\\'; ! strncpy(p, p_script_info->zippath, lib_dir_len-1); ! p += lib_dir_len-1; ! *p++ = '\0'; ! } ! /* Fully-qualify it */ ! GetFullPathName(libdirname, sizeof(libdirname), libdirname, &fname); ! /* From Barry Scott */ ! /* Must not set the PYTHONHOME env var as this prevents ! python being used in os.system or os.popen */ ! Py_SetPythonHome(libdirname); /* *************** *** 130,238 **** * And, of course, the zipfile itself. */ ! sprintf(buffer, "PYTHONPATH=%s;%s\\%s", libdirname, libdirname, pZipBaseName); ! _putenv (buffer); ! _putenv ("PYTHONSTARTUP="); ! _putenv ("PYTHONOPTIMIZE="); ! _putenv ("PYTHONDEBUG="); ! _putenv("PYTHONINSPECT="); ! if (getenv("PY2EXEVERBOSE")) ! _putenv ("PYTHONVERBOSE=1"); ! else ! _putenv ("PYTHONVERBOSE="); ! if (p_script_info->unbuffered) ! _putenv ("PYTHONUNBUFFERED=1"); ! else ! _putenv ("PYTHONUNBUFFERED="); ! } ! Py_NoSiteFlag = 1; ! Py_OptimizeFlag = p_script_info->optimize; ! ! /* XXX Is this correct? For the dll server code? */ ! /* And we should probably change all the above code if Python is already ! * initialized */ ! Py_SetProgramName(modulename); ! Py_Initialize(); ! /* From Barry Scott */ ! /* cause python to calculate the path */ ! Py_GetPath(); ! /* Set sys.frozen so apps that care can tell. Custom environments may */ ! /* set this later to a 'better' value (eg, COM dlls get 'dll') */ ! PySys_SetObject("frozen", Py_True); ! /* clean up the environment so that os.system ! and os.popen processes can run python the normal way */ ! /* Hm, actually it would be better to set them to values saved before ! changing them ;-) */ ! _putenv("PYTHONPATH="); ! _putenv("PYTHONUNBUFFERED="); ! _putenv("PYTHONVERBOSE="); ! return 0; } int init(void) { ! return init_with_instance(NULL); } void fini(void) { ! /* The standard Python 2.3 does also allow this: Set PYTHONINSPECT ! in the script and examine it afterwards ! */ ! if (getenv("PYTHONINSPECT") && Py_FdIsInteractive(stdin, "<stdin>")) ! PyRun_InteractiveLoop(stdin, "<stdin>"); ! /* Clean up */ ! Py_Finalize(); } int start (int argc, char **argv) { ! int rc; ! PySys_SetArgv(argc, argv); ! rc = run_script(); ! fini(); ! return rc; } int run_script(void) { ! int rc; ! /* It would be nice to run only with the single zipfile entry on sys.path, ! but it seems for inproc com servers the module's directory is needed as well. ! */ ! char buffer[_MAX_PATH * 3]; ! snprintf(buffer, sizeof(buffer), ! "import sys; sys.path=[r'%s', r'%s\\%s']", ! libdirname, ! libdirname, pZipBaseName); ! rc = PyRun_SimpleString(buffer); ! if (rc == 0) { ! /* load the code objects to execute */ ! PyObject *m=NULL, *d=NULL, *seq=NULL; ! /* We execute then in the context of '__main__' */ ! m = PyImport_AddModule("__main__"); ! if (m) d = PyModule_GetDict(m); ! if (d) seq = PyMarshal_ReadObjectFromString(pScript, numScriptBytes); ! if (seq) { ! int i, max = PySequence_Length(seq); ! for (i=0;i<max;i++) { ! PyObject *sub = PySequence_GetItem(seq, i); ! if (sub && PyCode_Check(sub)) { ! PyObject *discard = PyEval_EvalCode((PyCodeObject *)sub, ! d, d); ! if (!discard) ! PyErr_Print(); ! Py_XDECREF(discard); ! /* keep going even if we fail */ } - Py_XDECREF(sub); - } } ! } ! return rc; } --- 130,238 ---- * And, of course, the zipfile itself. */ ! sprintf(buffer, "PYTHONPATH=%s;%s\\%s", libdirname, libdirname, pZipBaseName); ! _putenv (buffer); ! _putenv ("PYTHONSTARTUP="); ! _putenv ("PYTHONOPTIMIZE="); ! _putenv ("PYTHONDEBUG="); ! _putenv("PYTHONINSPECT="); ! if (getenv("PY2EXEVERBOSE")) ! _putenv ("PYTHONVERBOSE=1"); ! else ! _putenv ("PYTHONVERBOSE="); ! if (p_script_info->unbuffered) ! _putenv ("PYTHONUNBUFFERED=1"); ! else ! _putenv ("PYTHONUNBUFFERED="); ! } ! Py_NoSiteFlag = 1; ! Py_OptimizeFlag = p_script_info->optimize; ! /* XXX Is this correct? For the dll server code? */ ! /* And we should probably change all the above code if Python is already ! * initialized */ ! Py_SetProgramName(modulename); ! Py_Initialize(); ! ! /* From Barry Scott */ ! /* cause python to calculate the path */ ! Py_GetPath(); ! /* Set sys.frozen so apps that care can tell. Custom environments may */ ! /* set this later to a 'better' value (eg, COM dlls get 'dll') */ ! PySys_SetObject("frozen", Py_True); ! /* clean up the environment so that os.system ! and os.popen processes can run python the normal way */ ! /* Hm, actually it would be better to set them to values saved before ! changing them ;-) */ ! _putenv("PYTHONPATH="); ! _putenv("PYTHONUNBUFFERED="); ! _putenv("PYTHONVERBOSE="); ! return 0; } int init(void) { ! return init_with_instance(NULL); } void fini(void) { ! /* The standard Python 2.3 does also allow this: Set PYTHONINSPECT ! in the script and examine it afterwards ! */ ! if (getenv("PYTHONINSPECT") && Py_FdIsInteractive(stdin, "<stdin>")) ! PyRun_InteractiveLoop(stdin, "<stdin>"); ! /* Clean up */ ! Py_Finalize(); } int start (int argc, char **argv) { ! int rc; ! PySys_SetArgv(argc, argv); ! rc = run_script(); ! fini(); ! return rc; } int run_script(void) { ! int rc; ! /* It would be nice to run only with the single zipfile entry on sys.path, ! but it seems for inproc com servers the module's directory is needed as well. ! */ ! char buffer[_MAX_PATH * 3]; ! snprintf(buffer, sizeof(buffer), ! "import sys; sys.path=[r'%s', r'%s\\%s']", ! libdirname, ! libdirname, pZipBaseName); ! rc = PyRun_SimpleString(buffer); ! if (rc == 0) { ! /* load the code objects to execute */ ! PyObject *m=NULL, *d=NULL, *seq=NULL; ! /* We execute then in the context of '__main__' */ ! m = PyImport_AddModule("__main__"); ! if (m) d = PyModule_GetDict(m); ! if (d) seq = PyMarshal_ReadObjectFromString(pScript, numScriptBytes); ! if (seq) { ! int i, max = PySequence_Length(seq); ! for (i=0;i<max;i++) { ! PyObject *sub = PySequence_GetItem(seq, i); ! if (sub && PyCode_Check(sub)) { ! PyObject *discard = PyEval_EvalCode((PyCodeObject *)sub, ! d, d); ! if (!discard) ! PyErr_Print(); ! Py_XDECREF(discard); ! /* keep going even if we fail */ ! } ! Py_XDECREF(sub); ! } } } ! return rc; } |