diff options
author | Thomas Heller <theller@ctypes.org> | 2005-02-03 20:35:10 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2005-02-03 20:35:10 (GMT) |
commit | 9f2e3be4e86f95b33e9e307ecf115e72ae73b5e1 (patch) | |
tree | e6cb9bdb63fb82a2116d1f805bc6b05fb4a7b1b6 /PC/bdist_wininst | |
parent | 8abe7bfb2f5b231a71f9bd10d2c52680c545f87a (diff) | |
download | cpython-9f2e3be4e86f95b33e9e307ecf115e72ae73b5e1.zip cpython-9f2e3be4e86f95b33e9e307ecf115e72ae73b5e1.tar.gz cpython-9f2e3be4e86f95b33e9e307ecf115e72ae73b5e1.tar.bz2 |
Running a bdist_wininst installer, built with Python 2.3, installing
for Python 2.4 caused a segfault when post_install_script was used.
The reason was that the file handle passed to PyRun_SimpleFile() was
created with MSVCRT.DLL, but Python 2.4 uses MSVCR71.DLL.
So, I replaced PyRun_SimpleFile() with PyRun_SimpleString(). The
segfault is gone, but the output of the postinstall script doesn't
show up, because still freopen() from MSVCRT is used.
Already backported.
Diffstat (limited to 'PC/bdist_wininst')
-rw-r--r-- | PC/bdist_wininst/install.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c index eb65d4c..0ce2371 100644 --- a/PC/bdist_wininst/install.c +++ b/PC/bdist_wininst/install.c @@ -88,6 +88,11 @@ #include <stdarg.h> #include <string.h> #include <time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <malloc.h> +#include <io.h> +#include <fcntl.h> #include "archive.h" @@ -671,7 +676,7 @@ static int prepare_script_environment(HINSTANCE hPython) * 1 if the Python-dll does not export the functions we need * 2 if no install-script is specified in pathname * 3 if the install-script file could not be opened - * the return value of PyRun_SimpleFile() otherwise, + * the return value of PyRun_SimpleString() otherwise, * which is 0 if everything is ok, -1 if an exception had occurred * in the install-script. */ @@ -681,7 +686,7 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) { DECLPROC(hPython, void, Py_Initialize, (void)); DECLPROC(hPython, int, PySys_SetArgv, (int, char **)); - DECLPROC(hPython, int, PyRun_SimpleFile, (FILE *, char *)); + DECLPROC(hPython, int, PyRun_SimpleString, (char *)); DECLPROC(hPython, void, Py_Finalize, (void)); DECLPROC(hPython, PyObject *, Py_BuildValue, (char *, ...)); DECLPROC(hPython, PyObject *, PyCFunction_New, @@ -690,10 +695,10 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) DECLPROC(hPython, PyObject *, PyErr_Format, (PyObject *, char *)); int result = 0; - FILE *fp; + int fh; if (!Py_Initialize || !PySys_SetArgv - || !PyRun_SimpleFile || !Py_Finalize) + || !PyRun_SimpleString || !Py_Finalize) return 1; if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format) @@ -705,8 +710,8 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) if (pathname == NULL || pathname[0] == '\0') return 2; - fp = fopen(pathname, "r"); - if (!fp) { + fh = open(pathname, _O_RDONLY); + if (-1 == fh) { fprintf(stderr, "Could not open postinstall-script %s\n", pathname); return 3; @@ -718,10 +723,22 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) prepare_script_environment(hPython); PySys_SetArgv(argc, argv); - result = PyRun_SimpleFile(fp, pathname); + result = 3; + { + struct _stat statbuf; + if(0 == _fstat(fh, &statbuf)) { + char *script = alloca(statbuf.st_size + 5); + int n = read(fh, script, statbuf.st_size); + if (n > 0) { + script[n] = '\n'; + script[n+1] = 0; + result = PyRun_SimpleString(script); + } + } + } Py_Finalize(); - fclose(fp); + close(fh); return result; } |