Fix missing default globals in eval/exec when embedding

Fixes #887.
This commit is contained in:
Dean Moldovan
2017-06-06 17:05:19 +02:00
parent 91bbe2f2e5
commit 1d3c4bc54d
3 changed files with 18 additions and 17 deletions

View File

@@ -153,3 +153,10 @@ TEST_CASE("Subinterpreter") {
REQUIRE(py::hasattr(py::module::import("__main__"), "main_tag"));
REQUIRE(py::hasattr(py::module::import("widget_module"), "extension_module_tag"));
}
TEST_CASE("Execution frame") {
// When the interpreter is embedded, there is no execution frame, but `py::exec`
// should still function by using reasonable globals: `__main__.__dict__`.
py::exec("var = dict(number=42)");
REQUIRE(py::globals()["var"]["number"].cast<int>() == 42);
}