From 7aa42aa8b3947a43e128d1fe9123aef9c9c1b844 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 23 Jan 2009 15:57:20 -0400 Subject: Report the name of a Python function if we have difficulties calling it. --- python/pyinterp.cc | 16 ++++++++++++---- python/pyinterp.h | 10 ++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'python') diff --git a/python/pyinterp.cc b/python/pyinterp.cc index a38def60..582b8e78 100644 --- a/python/pyinterp.cc +++ b/python/pyinterp.cc @@ -250,14 +250,22 @@ value_t python_interpreter_t::functor_t::operator()(call_scope_t& args) if (PyObject * val = PyObject_CallObject(func.ptr(), boost::python::tuple(arglist).ptr())) { - value_t result = extract(val)(); - Py_DECREF(val); + extract xval(val); + value_t result; + if (xval.check()) { + result = xval(); + Py_DECREF(val); + } else { + Py_DECREF(val); + throw_(calc_error, + "Could not evaluate Python variable '" << name << "'"); + } return result; } else if (PyObject * err = PyErr_Occurred()) { PyErr_Print(); throw_(calc_error, - "While calling Python function '" /*<< name() <<*/ "': " << err); + "While calling Python function '" << name << "': " << err); } else { assert(false); } @@ -269,7 +277,7 @@ value_t python_interpreter_t::functor_t::operator()(call_scope_t& args) catch (const error_already_set&) { PyErr_Print(); throw_(calc_error, - "While calling Python function '" /*<< name() <<*/ "'"); + "While calling Python function '" << name << "'"); } return NULL_VALUE; } diff --git a/python/pyinterp.h b/python/pyinterp.h index a38cd565..cf9ee486 100644 --- a/python/pyinterp.h +++ b/python/pyinterp.h @@ -73,13 +73,19 @@ public: class functor_t { functor_t(); + protected: boost::python::object func; + public: - functor_t(const string&, boost::python::object _func) : func(_func) { + string name; + + functor_t(const string& _name, boost::python::object _func) + : func(_func), name(_name) { TRACE_CTOR(functor_t, "const string&, boost::python::object"); } - functor_t(const functor_t& other) : func(other.func) { + functor_t(const functor_t& other) + : func(other.func), name(other.name) { TRACE_CTOR(functor_t, "copy"); } virtual ~functor_t() throw() { -- cgit v1.2.3