Skip to content

Commit

Permalink
Fix exec_file for Python 3 < 3.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseefeld committed Apr 9, 2015
1 parent e1e9eb3 commit 3e405b6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@Lastique

Lastique May 6, 2015

Member

This version check is incorrect, it should be #if PY_VERSION_HEX >= 0x03040000.

FILE *fs = _Py_fopen(f, "r");
#elif PY_VERSION_HEX >= 0x03000000
PyObject *fo = Py_BuildValue("s", f);
FILE *fs = _Py_fopen(fo, "r");

This comment has been minimized.

Copy link
@mmatrosov

mmatrosov Dec 11, 2015

Contributor

The funny thing is that Python 3.0.1 does not provide function _Py_fopen and this code simply does not compile.

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");
Expand Down

1 comment on commit 3e405b6

@mmatrosov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanseefeld Thank you for the fix! I did not think it would require special treatment for Python 3 < 3.4 and did not check it.

Please sign in to comment.