22 #if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x03080000
27 if (!global.contains(
"__builtins__"))
47 template <eval_mode mode = eval_expr>
57 std::string
buffer =
"# -*- coding: utf-8 -*-\n" + (std::string) expr;
62 start = Py_eval_input;
65 start = Py_single_input;
68 start = Py_file_input;
78 return reinterpret_steal<object>(
result);
81 template <eval_mode mode = eval_expr,
size_t N>
85 return eval<mode>(expr, std::move(global), std::move(
local));
89 eval<eval_statements>(expr, std::move(global), std::move(
local));
94 eval<eval_statements>(
s, std::move(global), std::move(
local));
97 #if defined(PYPY_VERSION)
98 template <eval_mode mode = eval_statements>
102 template <eval_mode mode = eval_statements>
106 template <eval_mode mode = eval_statements>
111 template <eval_mode mode = eval_statements>
122 start = Py_eval_input;
125 start = Py_single_input;
128 start = Py_file_input;
135 std::string fname_str = (std::string) fname;
136 FILE *
f = _Py_fopen_obj(fname.
ptr(),
"r");
139 pybind11_fail(
"File \"" + fname_str +
"\" could not be opened!");
142 if (!global.contains(
"__file__")) {
143 global[
"__file__"] = std::move(fname);
147 = PyRun_FileEx(
f, fname_str.c_str(), start, global.ptr(),
local.ptr(), closeFile);
152 return reinterpret_steal<object>(
result);