Kaydet (Commit) f725bdb5 authored tarafından Thomas Heller's avatar Thomas Heller

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.

(I would be very gratefull if someone proofreads the patch, at least).
üst cf5d664a
...@@ -87,6 +87,11 @@ ...@@ -87,6 +87,11 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <malloc.h>
#include <io.h>
#include <fcntl.h>
#include "archive.h" #include "archive.h"
...@@ -573,7 +578,7 @@ PyMethodDef meth[] = { ...@@ -573,7 +578,7 @@ PyMethodDef meth[] = {
* 1 if the Python-dll does not export the functions we need * 1 if the Python-dll does not export the functions we need
* 2 if no install-script is specified in pathname * 2 if no install-script is specified in pathname
* 3 if the install-script file could not be opened * 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 * which is 0 if everything is ok, -1 if an exception had occurred
* in the install-script. * in the install-script.
*/ */
...@@ -583,7 +588,7 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) ...@@ -583,7 +588,7 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
{ {
DECLPROC(hPython, void, Py_Initialize, (void)); DECLPROC(hPython, void, Py_Initialize, (void));
DECLPROC(hPython, int, PySys_SetArgv, (int, char **)); 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, void, Py_Finalize, (void));
DECLPROC(hPython, PyObject *, PyImport_ImportModule, (char *)); DECLPROC(hPython, PyObject *, PyImport_ImportModule, (char *));
DECLPROC(hPython, int, PyObject_SetAttrString, DECLPROC(hPython, int, PyObject_SetAttrString,
...@@ -599,10 +604,10 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) ...@@ -599,10 +604,10 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
PyObject *mod; PyObject *mod;
int result = 0; int result = 0;
FILE *fp; int fh;
if (!Py_Initialize || !PySys_SetArgv if (!Py_Initialize || !PySys_SetArgv
|| !PyRun_SimpleFile || !Py_Finalize) || !PyRun_SimpleString || !Py_Finalize)
return 1; return 1;
if (!PyImport_ImportModule || !PyObject_SetAttrString if (!PyImport_ImportModule || !PyObject_SetAttrString
...@@ -622,13 +627,12 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) ...@@ -622,13 +627,12 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
if (pathname == NULL || pathname[0] == '\0') if (pathname == NULL || pathname[0] == '\0')
return 2; return 2;
fp = fopen(pathname, "r"); fh = open(pathname, _O_RDONLY);
if (!fp) { if (-1 == fh) {
fprintf(stderr, "Could not open postinstall-script %s\n", fprintf(stderr, "Could not open postinstall-script %s\n",
pathname); pathname);
return 3; return 3;
} }
SetDlgItemText(hDialog, IDC_INFO, "Running Script..."); SetDlgItemText(hDialog, IDC_INFO, "Running Script...");
Py_Initialize(); Py_Initialize();
...@@ -647,10 +651,22 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv) ...@@ -647,10 +651,22 @@ run_installscript(HINSTANCE hPython, char *pathname, int argc, char **argv)
} }
PySys_SetArgv(argc, argv); 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(); Py_Finalize();
fclose(fp); close(fh);
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment