4 #ifndef CT_CYTHON_FUNC_WRAPPER 5 #define CT_CYTHON_FUNC_WRAPPER 11 #define CANTERA_USE_INTERNAL 15 typedef double(*callback_wrapper)(double,
void*,
void**);
22 CallbackError(
void* type,
void* value) :
23 m_type((PyObject*) type),
24 m_value((PyObject*) value)
27 const char*
what()
const throw() {
31 PyObject* name = PyObject_GetAttrString(m_type,
"__name__");
32 PyObject* value_str = PyObject_Str(m_value);
34 #if PY_MAJOR_VERSION > 2 35 PyObject* name_bytes = PyUnicode_AsASCIIString(name);
36 PyObject* value_bytes = PyUnicode_AsASCIIString(value_str);
38 PyObject* name_bytes = PyObject_Bytes(name);
39 PyObject* value_bytes = PyObject_Bytes(value_str);
44 Py_DECREF(name_bytes);
53 Py_DECREF(value_bytes);
59 Py_XDECREF(value_str);
74 Func1Py(callback_wrapper callback,
void* pyobj) :
79 double eval(
double t)
const {
80 void* err[2] = {0, 0};
81 double y = m_callback(t, m_pyobj, err);
83 throw CallbackError(err[0], err[1]);
89 callback_wrapper m_callback;
94 CANTERA_CAPI PyObject* pyCanteraError;
100 inline int translate_exception()
103 if (!PyErr_Occurred()) {
108 }
catch (
const CallbackError& exn) {
110 PyErr_SetObject(exn.m_type, exn.m_value);
111 }
catch (
const std::out_of_range& exn) {
112 PyErr_SetString(PyExc_IndexError, exn.what());
114 PyErr_SetString(pyCanteraError, exn.
what());
115 }
catch (
const std::exception& exn) {
116 PyErr_SetString(PyExc_RuntimeError, exn.what());
118 PyErr_SetString(PyExc_Exception,
"Unknown exception");
std::string formattedMessage_
Formatted message returned by what()
const char * what() const
Get a description of the error.
virtual doublereal eval(doublereal t) const
Evaluate the function.
Base class for 'functor' classes that evaluate a function of one variable.
Base class for exceptions thrown by Cantera classes.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...