diff options
Diffstat (limited to 'libs/python/src')
-rw-r--r-- | libs/python/src/SConscript | 44 | ||||
-rw-r--r-- | libs/python/src/exec.cpp | 15 |
2 files changed, 51 insertions, 8 deletions
diff --git a/libs/python/src/SConscript b/libs/python/src/SConscript new file mode 100644 index 0000000000..a1d3de6baf --- /dev/null +++ b/libs/python/src/SConscript @@ -0,0 +1,44 @@ +# -*- python -*- +# +# Copyright (c) 2016 Stefan Seefeld +# All rights reserved. +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +Import('env') + +env.AppendUnique(CPPDEFINES = ["${LINK_DYNAMIC and 'BOOST_PYTHON_DYN_LINK=1' or ''}"]) +env.AppendUnique(CPPDEFINES = ['BOOST_PYTHON_SOURCE']) + +env.BoostLibrary( + 'python', + ['numeric.cpp', + 'list.cpp', + 'long.cpp', + 'dict.cpp', + 'tuple.cpp', + 'str.cpp', + 'slice.cpp', + 'converter/from_python.cpp', + 'converter/registry.cpp', + 'converter/type_id.cpp', + 'object/enum.cpp', + 'object/class.cpp', + 'object/function.cpp', + 'object/inheritance.cpp', + 'object/life_support.cpp', + 'object/pickle_support.cpp', + 'errors.cpp', + 'module.cpp', + 'converter/builtin_converters.cpp', + 'converter/arg_to_python_base.cpp', + 'object/iterator.cpp', + 'object/stl_iterator.cpp', + 'object_protocol.cpp', + 'object_operators.cpp', + 'wrapper.cpp', + 'import.cpp', + 'exec.cpp', + 'object/function_doc_signature.cpp']) diff --git a/libs/python/src/exec.cpp b/libs/python/src/exec.cpp index 2910db7c85..fa2860e40e 100644 --- a/libs/python/src/exec.cpp +++ b/libs/python/src/exec.cpp @@ -84,24 +84,23 @@ 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<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 >= 0x03040000 FILE *fs = _Py_fopen(f, "r"); +#elif PY_VERSION_HEX >= 0x03000000 + PyObject *fo = Py_BuildValue("s", f); + FILE *fs = _Py_fopen(fo, "r"); + 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"); python::handle<> file(pyfile); FILE *fs = PyFile_AsFile(file.get()); #endif - - int closeit = 1; // Close file before PyRun returns - PyObject* result = PyRun_FileEx(fs, + PyObject* result = PyRun_File(fs, f, Py_file_input, - global.ptr(), local.ptr(), - closeit); + global.ptr(), local.ptr()); if (!result) throw_error_already_set(); return object(detail::new_reference(result)); } |