From a911c17fd6e6532807d3a17d597eb391bd484d09 Mon Sep 17 00:00:00 2001 From: Mikhail Matrosov Date: Wed, 11 Mar 2015 00:54:18 +0300 Subject: [PATCH] [#11100] Fix binary incompatibilities with fopen() in exec_file() routine. --- src/exec.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 9fe1b23b..0a4cafcd 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -84,18 +84,18 @@ 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. - FILE *fs = fopen(f, "r"); -#else + // 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 + FILE *fs = _Py_fopen(f, "r"); +#else PyObject *pyfile = PyFile_FromString(f, const_cast("r")); if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file"); python::handle<> file(pyfile); FILE *fs = PyFile_AsFile(file.get()); #endif + PyObject* result = PyRun_File(fs, f, Py_file_input,