GeezerVison is showing github.com — Fix exec_file for Python 3 < 3.4. · ssam18/python@3e405b6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/exec.cpp +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,9 +86,12 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local) |
86 | 86 | char *f = python::extract<char *>(filename); |
87 | 87 |
|
88 | 88 | // 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 |
91 | 90 | 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); |
92 | 95 | #else |
93 | 96 | PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r")); |
94 | 97 | if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file"); |
|