Skip to content

Commit 3e405b6

Browse files
committed
Fix exec_file for Python 3 < 3.4.
1 parent e1e9eb3 commit 3e405b6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/exec.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
8686
char *f = python::extract<char *>(filename);
8787

8888
// Let python open the file to avoid potential binary incompatibilities.
89-
#if PY_VERSION_HEX >= 0x03000000
90-
// See http://www.codeproject.com/Articles/820116/Embedding-Python-program-in-a-C-Cplusplus-code
89+
#if PY_VERSION_HEX >= 0x03400000
9190
FILE *fs = _Py_fopen(f, "r");
91+
#elif PY_VERSION_HEX >= 0x03000000
92+
PyObject *fo = Py_BuildValue("s", f);
93+
FILE *fs = _Py_fopen(fo, "r");
94+
Py_DECREF(fo);
9295
#else
9396
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
9497
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");

0 commit comments

Comments
 (0)