diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-23 01:57:37 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-23 01:57:37 -0400 |
commit | f0d13734b40d4c671a20340deeb9b2c5faa09037 (patch) | |
tree | 25c26480aa29da429f4e2d30894815a832473fc0 /python | |
parent | 6df9debc6fba78987dd476f7f232df096f4b44af (diff) | |
download | fork-ledger-f0d13734b40d4c671a20340deeb9b2c5faa09037.tar.gz fork-ledger-f0d13734b40d4c671a20340deeb9b2c5faa09037.tar.bz2 fork-ledger-f0d13734b40d4c671a20340deeb9b2c5faa09037.zip |
Look up definitions in the Python evaluator directly, not with eval.
Diffstat (limited to 'python')
-rw-r--r-- | python/pyinterp.cc | 15 | ||||
-rw-r--r-- | python/pyinterp.h | 2 |
2 files changed, 6 insertions, 11 deletions
diff --git a/python/pyinterp.cc b/python/pyinterp.cc index 36dd3e35..ab8f4b8b 100644 --- a/python/pyinterp.cc +++ b/python/pyinterp.cc @@ -97,7 +97,7 @@ python_interpreter_t::python_interpreter_t() : session_t(), main_nspace() if (! main_module) throw_(std::logic_error, "Python failed to initialize"); - main_nspace = main_module.attr("__dict__"); + main_nspace = extract<dict>(main_module.attr("__dict__")); if (! main_nspace) throw_(std::logic_error, "Python failed to initialize"); @@ -116,10 +116,7 @@ object python_interpreter_t::import(const string& str) throw_(std::logic_error, "Failed to import Python module " << str); // Import all top-level entries directly into the main namespace - object nspace = mod.attr("__dict__"); - - dict main_nspace_dict = extract<dict>(main_nspace); - main_nspace_dict.update(nspace); + main_nspace.update(mod.attr("__dict__")); return mod; } @@ -207,13 +204,11 @@ expr_t::ptr_op_t python_interpreter_t::lookup(const string& name) break; } - DEBUG("python.interp", "Python eval: " << name); + DEBUG("python.interp", "Python lookup: " << name); - try { - if (boost::python::object obj = eval(name)) + if (main_nspace.has_key(name)) + if (boost::python::object obj = main_nspace.get(name)) return WRAP_FUNCTOR(functor_t(name, obj)); - } - catch (...) {} return expr_t::ptr_op_t(); } diff --git a/python/pyinterp.h b/python/pyinterp.h index 60aa9c20..a38cd565 100644 --- a/python/pyinterp.h +++ b/python/pyinterp.h @@ -43,7 +43,7 @@ namespace ledger { class python_interpreter_t : public session_t { public: - boost::python::object main_nspace; + boost::python::dict main_nspace; python_interpreter_t(); |