@@ -15,6 +15,11 @@ namespace python
1515{
1616
1717object BOOST_PYTHON_DECL eval (str string, object global, object local)
18+ {
19+ return eval (python::extract<char const *>(string));
20+ }
21+
22+ object BOOST_PYTHON_DECL eval (char const *string, object global, object local)
1823{
1924 // Set suitable default values for global and local dicts.
2025 if (global.is_none ())
@@ -26,13 +31,18 @@ object BOOST_PYTHON_DECL eval(str string, object global, object local)
2631 }
2732 if (local.is_none ()) local = global;
2833 // should be 'char const *' but older python versions don't use 'const' yet.
29- char *s = python::extract <char *>(string);
34+ char *s = const_cast <char *>(string);
3035 PyObject* result = PyRun_String (s, Py_eval_input, global.ptr (), local.ptr ());
3136 if (!result) throw_error_already_set ();
3237 return object (detail::new_reference (result));
3338}
3439
3540object BOOST_PYTHON_DECL exec (str string, object global, object local)
41+ {
42+ return exec (python::extract<char const *>(string));
43+ }
44+
45+ object BOOST_PYTHON_DECL exec (char const *string, object global, object local)
3646{
3747 // Set suitable default values for global and local dicts.
3848 if (global.is_none ())
@@ -44,13 +54,18 @@ object BOOST_PYTHON_DECL exec(str string, object global, object local)
4454 }
4555 if (local.is_none ()) local = global;
4656 // should be 'char const *' but older python versions don't use 'const' yet.
47- char *s = python::extract <char *>(string);
57+ char *s = const_cast <char *>(string);
4858 PyObject* result = PyRun_String (s, Py_file_input, global.ptr (), local.ptr ());
4959 if (!result) throw_error_already_set ();
5060 return object (detail::new_reference (result));
5161}
5262
5363object BOOST_PYTHON_DECL exec_statement (str string, object global, object local)
64+ {
65+ return exec_statement (python::extract<char const *>(string), global, local);
66+ }
67+
68+ object BOOST_PYTHON_DECL exec_statement (char const *string, object global, object local)
5469{
5570 // Set suitable default values for global and local dicts.
5671 if (global.is_none ())
@@ -62,7 +77,7 @@ object BOOST_PYTHON_DECL exec_statement(str string, object global, object local)
6277 }
6378 if (local.is_none ()) local = global;
6479 // should be 'char const *' but older python versions don't use 'const' yet.
65- char *s = python::extract <char *>(string);
80+ char *s = const_cast <char *>(string);
6681 PyObject* result = PyRun_String (s, Py_single_input, global.ptr (), local.ptr ());
6782 if (!result) throw_error_already_set ();
6883 return object (detail::new_reference (result));
@@ -72,6 +87,11 @@ object BOOST_PYTHON_DECL exec_statement(str string, object global, object local)
7287// global and local are the global and local scopes respectively,
7388// used during execution.
7489object BOOST_PYTHON_DECL exec_file (str filename, object global, object local)
90+ {
91+ return exec_file (python::extract<char const *>(filename), global, local);
92+ }
93+
94+ object BOOST_PYTHON_DECL exec_file (char const *filename, object global, object local)
7595{
7696 // Set suitable default values for global and local dicts.
7797 if (global.is_none ())
@@ -83,7 +103,7 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
83103 }
84104 if (local.is_none ()) local = global;
85105 // should be 'char const *' but older python versions don't use 'const' yet.
86- char *f = python::extract <char *>(filename);
106+ char *f = const_cast <char *>(filename);
87107 // Let python open the file to avoid potential binary incompatibilities.
88108#if PY_VERSION_HEX >= 0x03040000
89109 FILE *fs = _Py_fopen (f, " r" );
0 commit comments