Skip to content

Commit a911c17

Browse files
committed
[#11100] Fix binary incompatibilities with fopen() in exec_file() routine.
1 parent 8d5d777 commit a911c17

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/exec.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ 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+
88+
// Let python open the file to avoid potential binary incompatibilities.
8789
#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.
91-
FILE *fs = fopen(f, "r");
90+
// See http://www.codeproject.com/Articles/820116/Embedding-Python-program-in-a-C-Cplusplus-code
91+
FILE *fs = _Py_fopen(f, "r");
9292
#else
93-
// Let python open the file to avoid potential binary incompatibilities.
9493
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
9594
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
9695
python::handle<> file(pyfile);
9796
FILE *fs = PyFile_AsFile(file.get());
9897
#endif
98+
9999
PyObject* result = PyRun_File(fs,
100100
f,
101101
Py_file_input,

0 commit comments

Comments
 (0)