Skip to content

Commit 36f8f69

Browse files
committed
Fix compilation with python 3.0-3.3
Backport commit 3e405b6 to develop branch: Fix exec_file for Python 3 < 3.4. Also fix version check to actually fix compilation with python 3.4.
1 parent ea87bfe commit 36f8f69

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/exec.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
8484
if (local.is_none()) local = global;
8585
// should be 'char const *' but older python versions don't use 'const' yet.
8686
char *f = python::extract<char *>(filename);
87-
#if PY_VERSION_HEX >= 0x03000000
88-
// TODO(bhy) temporary workaround for Python 3.
89-
// should figure out a way to avoid binary incompatibilities as the Python 2
90-
// version did.
87+
#if PY_VERSION_HEX >= 0x03040000
9188
FILE *fs = fopen(f, "r");
89+
#elif PY_VERSION_HEX >= 0x03000000
90+
PyObject *fo = Py_BuildValue("s", f);
91+
FILE *fs = _Py_fopen(fo, "r");
92+
Py_DECREF(fo);
9293
#else
9394
// Let python open the file to avoid potential binary incompatibilities.
9495
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));

0 commit comments

Comments
 (0)