2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 17:12:22 +00:00

Fix exec_file for Python 3 < 3.4.

This commit is contained in:
Stefan Seefeld
2015-04-09 08:57:08 -04:00
parent e1e9eb303a
commit 3e405b6fd5

View File

@@ -86,9 +86,12 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
char *f = python::extract<char *>(filename);
// Let python open the file to avoid potential binary incompatibilities.
#if PY_VERSION_HEX >= 0x03000000
// See http://www.codeproject.com/Articles/820116/Embedding-Python-program-in-a-C-Cplusplus-code
#if PY_VERSION_HEX >= 0x03400000
FILE *fs = _Py_fopen(f, "r");
#elif PY_VERSION_HEX >= 0x03000000
PyObject *fo = Py_BuildValue("s", f);
FILE *fs = _Py_fopen(fo, "r");
Py_DECREF(fo);
#else
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");