From 36f8f6941134583cef0fa48701a1989f2f49d4ec Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 6 May 2015 15:06:29 +0300 Subject: [PATCH] Fix compilation with python 3.0-3.3 Backport commit 3e405b6fd5db5615bbef241763de070118222ca7 to develop branch: Fix exec_file for Python 3 < 3.4. Also fix version check to actually fix compilation with python 3.4. --- src/exec.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 9fe1b23b..1268fbf8 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -84,11 +84,12 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local) if (local.is_none()) local = global; // should be 'char const *' but older python versions don't use 'const' yet. char *f = python::extract(filename); -#if PY_VERSION_HEX >= 0x03000000 - // TODO(bhy) temporary workaround for Python 3. - // should figure out a way to avoid binary incompatibilities as the Python 2 - // version did. +#if PY_VERSION_HEX >= 0x03040000 FILE *fs = fopen(f, "r"); +#elif PY_VERSION_HEX >= 0x03000000 + PyObject *fo = Py_BuildValue("s", f); + FILE *fs = _Py_fopen(fo, "r"); + Py_DECREF(fo); #else // Let python open the file to avoid potential binary incompatibilities. PyObject *pyfile = PyFile_FromString(f, const_cast("r"));