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

more fixes to get testcases work, includes module init and other minor fixes

[SVN r53285]
This commit is contained in:
Haoyu Bai
2009-05-26 17:05:53 +00:00
parent 92f07fc4d6
commit e73277e156
6 changed files with 53 additions and 18 deletions

View File

@@ -38,11 +38,19 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
{
// should be 'char const *' but older python versions don't use 'const' yet.
char *f = python::extract<char *>(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.
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
python::handle<> file(pyfile);
PyObject* result = PyRun_File(PyFile_AsFile(file.get()),
FILE *fs = PyFile_AsFile(file.get());
#endif
PyObject* result = PyRun_File(fs,
f,
Py_file_input,
global.ptr(), local.ptr());