summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/libs/python/src/exec.cpp
diff options
context:
space:
mode:
authorneksard <[email protected]>2022-02-10 16:45:33 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:33 +0300
commit1d9c550e7c38e051d7961f576013a482003a70d9 (patch)
treeb2cc84ee7850122e7ccf51d0ea21e4fa7e7a5685 /contrib/restricted/boost/libs/python/src/exec.cpp
parent8f7cf138264e0caa318144bf8a2c950e0b0a8593 (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/boost/libs/python/src/exec.cpp')
-rw-r--r--contrib/restricted/boost/libs/python/src/exec.cpp254
1 files changed, 127 insertions, 127 deletions
diff --git a/contrib/restricted/boost/libs/python/src/exec.cpp b/contrib/restricted/boost/libs/python/src/exec.cpp
index 27799876815..43e860d992b 100644
--- a/contrib/restricted/boost/libs/python/src/exec.cpp
+++ b/contrib/restricted/boost/libs/python/src/exec.cpp
@@ -1,129 +1,129 @@
-// Copyright Stefan Seefeld 2005.
-// 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)
-
-#include <boost/python/exec.hpp>
-#include <boost/python/borrowed.hpp>
-#include <boost/python/dict.hpp>
-#include <boost/python/extract.hpp>
-#include <boost/python/handle.hpp>
-
-namespace boost
-{
-namespace python
+// Copyright Stefan Seefeld 2005.
+// 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)
+
+#include <boost/python/exec.hpp>
+#include <boost/python/borrowed.hpp>
+#include <boost/python/dict.hpp>
+#include <boost/python/extract.hpp>
+#include <boost/python/handle.hpp>
+
+namespace boost
{
-
-object BOOST_PYTHON_DECL eval(str string, object global, object local)
-{
- return eval(python::extract<char const *>(string), global, local);
-}
-
-object BOOST_PYTHON_DECL eval(char const *string, object global, object local)
-{
- // Set suitable default values for global and local dicts.
- if (global.is_none())
- {
- if (PyObject *g = PyEval_GetGlobals())
- global = object(detail::borrowed_reference(g));
- else
- global = dict();
- }
- if (local.is_none()) local = global;
- // should be 'char const *' but older python versions don't use 'const' yet.
- char *s = const_cast<char *>(string);
- PyObject* result = PyRun_String(s, Py_eval_input, global.ptr(), local.ptr());
- if (!result) throw_error_already_set();
- return object(detail::new_reference(result));
-}
-
-object BOOST_PYTHON_DECL exec(str string, object global, object local)
-{
- return exec(python::extract<char const *>(string), global, local);
-}
-
-object BOOST_PYTHON_DECL exec(char const *string, object global, object local)
-{
- // Set suitable default values for global and local dicts.
- if (global.is_none())
- {
- if (PyObject *g = PyEval_GetGlobals())
- global = object(detail::borrowed_reference(g));
- else
- global = dict();
- }
- if (local.is_none()) local = global;
- // should be 'char const *' but older python versions don't use 'const' yet.
- char *s = const_cast<char *>(string);
- PyObject* result = PyRun_String(s, Py_file_input, global.ptr(), local.ptr());
- if (!result) throw_error_already_set();
- return object(detail::new_reference(result));
-}
-
-object BOOST_PYTHON_DECL exec_statement(str string, object global, object local)
-{
- return exec_statement(python::extract<char const *>(string), global, local);
-}
-
-object BOOST_PYTHON_DECL exec_statement(char const *string, object global, object local)
-{
- // Set suitable default values for global and local dicts.
- if (global.is_none())
- {
- if (PyObject *g = PyEval_GetGlobals())
- global = object(detail::borrowed_reference(g));
- else
- global = dict();
- }
- if (local.is_none()) local = global;
- // should be 'char const *' but older python versions don't use 'const' yet.
- char *s = const_cast<char *>(string);
- PyObject* result = PyRun_String(s, Py_single_input, global.ptr(), local.ptr());
- if (!result) throw_error_already_set();
- return object(detail::new_reference(result));
-}
-
-// Execute python source code from file filename.
-// global and local are the global and local scopes respectively,
-// used during execution.
-object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
-{
- return exec_file(python::extract<char const *>(filename), global, local);
-}
-
-object BOOST_PYTHON_DECL exec_file(char const *filename, object global, object local)
-{
- // Set suitable default values for global and local dicts.
- if (global.is_none())
- {
- if (PyObject *g = PyEval_GetGlobals())
- global = object(detail::borrowed_reference(g));
- else
- global = dict();
- }
- if (local.is_none()) local = global;
- // should be 'char const *' but older python versions don't use 'const' yet.
- char *f = const_cast<char *>(filename);
- // Let python open the file to avoid potential binary incompatibilities.
-#if PY_VERSION_HEX >= 0x03040000
+namespace python
+{
+
+object BOOST_PYTHON_DECL eval(str string, object global, object local)
+{
+ return eval(python::extract<char const *>(string), global, local);
+}
+
+object BOOST_PYTHON_DECL eval(char const *string, object global, object local)
+{
+ // Set suitable default values for global and local dicts.
+ if (global.is_none())
+ {
+ if (PyObject *g = PyEval_GetGlobals())
+ global = object(detail::borrowed_reference(g));
+ else
+ global = dict();
+ }
+ if (local.is_none()) local = global;
+ // should be 'char const *' but older python versions don't use 'const' yet.
+ char *s = const_cast<char *>(string);
+ PyObject* result = PyRun_String(s, Py_eval_input, global.ptr(), local.ptr());
+ if (!result) throw_error_already_set();
+ return object(detail::new_reference(result));
+}
+
+object BOOST_PYTHON_DECL exec(str string, object global, object local)
+{
+ return exec(python::extract<char const *>(string), global, local);
+}
+
+object BOOST_PYTHON_DECL exec(char const *string, object global, object local)
+{
+ // Set suitable default values for global and local dicts.
+ if (global.is_none())
+ {
+ if (PyObject *g = PyEval_GetGlobals())
+ global = object(detail::borrowed_reference(g));
+ else
+ global = dict();
+ }
+ if (local.is_none()) local = global;
+ // should be 'char const *' but older python versions don't use 'const' yet.
+ char *s = const_cast<char *>(string);
+ PyObject* result = PyRun_String(s, Py_file_input, global.ptr(), local.ptr());
+ if (!result) throw_error_already_set();
+ return object(detail::new_reference(result));
+}
+
+object BOOST_PYTHON_DECL exec_statement(str string, object global, object local)
+{
+ return exec_statement(python::extract<char const *>(string), global, local);
+}
+
+object BOOST_PYTHON_DECL exec_statement(char const *string, object global, object local)
+{
+ // Set suitable default values for global and local dicts.
+ if (global.is_none())
+ {
+ if (PyObject *g = PyEval_GetGlobals())
+ global = object(detail::borrowed_reference(g));
+ else
+ global = dict();
+ }
+ if (local.is_none()) local = global;
+ // should be 'char const *' but older python versions don't use 'const' yet.
+ char *s = const_cast<char *>(string);
+ PyObject* result = PyRun_String(s, Py_single_input, global.ptr(), local.ptr());
+ if (!result) throw_error_already_set();
+ return object(detail::new_reference(result));
+}
+
+// Execute python source code from file filename.
+// global and local are the global and local scopes respectively,
+// used during execution.
+object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
+{
+ return exec_file(python::extract<char const *>(filename), global, local);
+}
+
+object BOOST_PYTHON_DECL exec_file(char const *filename, object global, object local)
+{
+ // Set suitable default values for global and local dicts.
+ if (global.is_none())
+ {
+ if (PyObject *g = PyEval_GetGlobals())
+ global = object(detail::borrowed_reference(g));
+ else
+ global = dict();
+ }
+ if (local.is_none()) local = global;
+ // should be 'char const *' but older python versions don't use 'const' yet.
+ char *f = const_cast<char *>(filename);
+ // Let python open the file to avoid potential binary incompatibilities.
+#if PY_VERSION_HEX >= 0x03040000
FILE *fs = 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
- PyObject* result = PyRun_File(fs,
- f,
- Py_file_input,
- global.ptr(), local.ptr());
- if (!result) throw_error_already_set();
- return object(detail::new_reference(result));
-}
-
-} // namespace boost::python
-} // namespace boost
+#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
+ PyObject* result = PyRun_File(fs,
+ f,
+ Py_file_input,
+ global.ptr(), local.ptr());
+ if (!result) throw_error_already_set();
+ return object(detail::new_reference(result));
+}
+
+} // namespace boost::python
+} // namespace boost