From f0d13734b40d4c671a20340deeb9b2c5faa09037 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 23 Jan 2009 01:57:37 -0400 Subject: Look up definitions in the Python evaluator directly, not with eval. --- python/pyinterp.cc | 15 +++++---------- python/pyinterp.h | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'python') 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(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(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(); -- cgit v1.2.3