summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-23 15:57:20 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-23 15:57:20 -0400
commit7aa42aa8b3947a43e128d1fe9123aef9c9c1b844 (patch)
treeb3c85e085dc67078502d9d361e82ecc635b34c68 /python
parent59a71e7d740414a3b55a70a8e67dba2e68996662 (diff)
downloadfork-ledger-7aa42aa8b3947a43e128d1fe9123aef9c9c1b844.tar.gz
fork-ledger-7aa42aa8b3947a43e128d1fe9123aef9c9c1b844.tar.bz2
fork-ledger-7aa42aa8b3947a43e128d1fe9123aef9c9c1b844.zip
Report the name of a Python function if we have difficulties calling it.
Diffstat (limited to 'python')
-rw-r--r--python/pyinterp.cc16
-rw-r--r--python/pyinterp.h10
2 files changed, 20 insertions, 6 deletions
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<value_t>(val)();
- Py_DECREF(val);
+ extract<value_t> 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() {