# HG changeset patch # User Dan Nicholson # Date 1378736409 -3600 # Mon Sep 09 15:20:09 2013 +0100 # Branch 2.7 # Node ID 660d32439a957e71ab070323c92be7c9b0acad23 # Parent 525419fcee90f5245cfc3c52ebc0c650eaf325a2 Issue #4636: Run bdist_wininst install scripts in 2/3 compatibile environment When bdist_wininst install scripts are run, they use the wininst stubs to setup the environment. Even if the package is pure, the wininst environment immediately becomes version specific by importing the builtins module. Make this compatible by checking the runtime version and importing __builtin__ when Python2 is being used. diff -r 525419fcee90 -r 660d32439a95 PC/bdist_wininst/install.c --- a/PC/bdist_wininst/install.c Tue Sep 10 02:23:26 2013 +0100 +++ b/PC/bdist_wininst/install.c Mon Sep 09 15:20:09 2013 +0100 @@ -651,6 +651,7 @@ static int prepare_script_environment(HINSTANCE hPython) { PyObject *mod; + int maj_version; DECLPROC(hPython, PyObject *, PyImport_ImportModule, (char *)); DECLPROC(hPython, int, PyObject_SetAttrString, (PyObject *, char *, PyObject *)); DECLPROC(hPython, PyObject *, PyObject_GetAttrString, (PyObject *, char *)); @@ -659,13 +660,19 @@ DECLPROC(hPython, int, PyArg_ParseTuple, (PyObject *, char *, ...)); DECLPROC(hPython, PyObject *, PyErr_Format, (PyObject *, char *)); DECLPROC(hPython, PyObject *, PyLong_FromVoidPtr, (void *)); + DECLPROC(hPython, const char *, Py_GetVersion, (void)); if (!PyImport_ImportModule || !PyObject_GetAttrString || !PyObject_SetAttrString || !PyCFunction_New) return 1; - if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format) + if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format || + !Py_GetVersion) return 1; - mod = PyImport_ImportModule("__builtin__"); + maj_version = atoi(Py_GetVersion()); + if (maj_version >= 3) + mod = PyImport_ImportModule("builtins"); + else + mod = PyImport_ImportModule("__builtin__"); if (mod) { int i; g_PyExc_ValueError = PyObject_GetAttrString(mod, "ValueError");