Better error handling in the Python API.
Added error handling to prevent crashes even when errors have occurred in user-defined predicates, stroke shaders, and chaining iterators.
This commit is contained in:
@@ -47,9 +47,14 @@ bool Director_BPy_BinaryPredicate0D___call__( PyObject *obj, Interface0D& i1, In
|
||||
PyObject *arg1 = BPy_Interface0D_from_Interface0D(i1);
|
||||
PyObject *arg2 = BPy_Interface0D_from_Interface0D(i2);
|
||||
PyObject *result = PyObject_CallMethod( obj, "__call__", "OO", arg1, arg2 );
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(arg1);
|
||||
Py_DECREF(arg2);
|
||||
if (!result) {
|
||||
cerr << "Warning: BinaryPredicate0D::__call__() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return false;
|
||||
}
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(result);
|
||||
return ret;
|
||||
}
|
||||
@@ -60,9 +65,14 @@ bool Director_BPy_BinaryPredicate1D___call__( PyObject *obj, Interface1D& i1, In
|
||||
PyObject *arg1 = BPy_Interface1D_from_Interface1D(i1);
|
||||
PyObject *arg2 = BPy_Interface1D_from_Interface1D(i2);
|
||||
PyObject *result = PyObject_CallMethod( obj, "__call__", "OO", arg1, arg2 );
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(arg1);
|
||||
Py_DECREF(arg2);
|
||||
if (!result) {
|
||||
cerr << "Warning: BinaryPredicate1D::__call__() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return false;
|
||||
}
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(result);
|
||||
return ret;
|
||||
}
|
||||
@@ -72,8 +82,13 @@ bool Director_BPy_BinaryPredicate1D___call__( PyObject *obj, Interface1D& i1, In
|
||||
bool Director_BPy_UnaryPredicate0D___call__( PyObject *obj, Interface0DIterator& if0D_it) {
|
||||
PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it);
|
||||
PyObject *result = PyObject_CallMethod( obj, "__call__", "O", arg );
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(arg);
|
||||
if (!result) {
|
||||
cerr << "Warning: UnaryPredicate0D::__call__() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return false;
|
||||
}
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(result);
|
||||
return ret;
|
||||
}
|
||||
@@ -83,8 +98,13 @@ bool Director_BPy_UnaryPredicate0D___call__( PyObject *obj, Interface0DIterator&
|
||||
bool Director_BPy_UnaryPredicate1D___call__( PyObject *obj, Interface1D& if1D) {
|
||||
PyObject *arg = BPy_Interface1D_from_Interface1D(if1D);
|
||||
PyObject *result = PyObject_CallMethod( obj, "__call__", "O", arg );
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(arg);
|
||||
if (!result) {
|
||||
cerr << "Warning: UnaryPredicate1D::__call__() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return false;
|
||||
}
|
||||
bool ret = bool_from_PyBool(result);
|
||||
Py_DECREF(result);
|
||||
return ret;
|
||||
}
|
||||
@@ -95,20 +115,35 @@ void Director_BPy_StrokeShader_shade( PyObject *obj, Stroke& s) {
|
||||
PyObject *arg = BPy_Stroke_from_Stroke_ptr(&s);
|
||||
PyObject *result = PyObject_CallMethod( obj, "shade", "O", arg );
|
||||
Py_DECREF(arg);
|
||||
if (!result) {
|
||||
cerr << "Warning: StrokeShader::shade() failed" << endl;
|
||||
PyErr_Clear();
|
||||
return;
|
||||
}
|
||||
Py_DECREF(result);
|
||||
}
|
||||
|
||||
// ChainingIterator: init, traverse
|
||||
void Director_BPy_ChainingIterator_init( PyObject *obj ) {
|
||||
PyObject *result = PyObject_CallMethod( obj, "init", "", 0 );
|
||||
if (!result) {
|
||||
cerr << "Warning: ChainingIterator::init() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return;
|
||||
}
|
||||
Py_DECREF(result);
|
||||
}
|
||||
|
||||
ViewEdge * Director_BPy_ChainingIterator_traverse( PyObject *obj, AdjacencyIterator& a_it ) {
|
||||
PyObject *arg = BPy_AdjacencyIterator_from_AdjacencyIterator(a_it);
|
||||
PyObject *result = PyObject_CallMethod( obj, "traverse", "O", arg );
|
||||
ViewEdge *ret = ((BPy_ViewEdge *) result)->ve;
|
||||
Py_DECREF(arg);
|
||||
if (!result) {
|
||||
cerr << "Warning: ChainingIterator::traverse() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return NULL;
|
||||
}
|
||||
ViewEdge *ret = ((BPy_ViewEdge *) result)->ve;
|
||||
Py_DECREF(result);
|
||||
return ret;
|
||||
}
|
||||
@@ -119,6 +154,12 @@ void Director_BPy_UnaryFunction0D___call__( void *uf0D, PyObject *obj, Interface
|
||||
|
||||
PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it);
|
||||
PyObject *result = PyObject_CallMethod( obj, "__call__", "O", arg );
|
||||
Py_DECREF(arg);
|
||||
if (!result) {
|
||||
cerr << "Warning: UnaryFunction0D::__call__() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if( BPy_UnaryFunction0DDouble_Check(obj) ) {
|
||||
((UnaryFunction0D<double> *) uf0D)->result = PyFloat_AsDouble(result);
|
||||
@@ -162,7 +203,6 @@ void Director_BPy_UnaryFunction0D___call__( void *uf0D, PyObject *obj, Interface
|
||||
|
||||
}
|
||||
|
||||
Py_DECREF(arg);
|
||||
Py_DECREF(result);
|
||||
}
|
||||
|
||||
@@ -170,6 +210,12 @@ void Director_BPy_UnaryFunction1D___call__( void *uf1D, PyObject *obj, Interface
|
||||
|
||||
PyObject *arg = BPy_Interface1D_from_Interface1D(if1D);
|
||||
PyObject *result = PyObject_CallMethod( obj, "__call__", "O", arg );
|
||||
Py_DECREF(arg);
|
||||
if (!result) {
|
||||
cerr << "Warning: UnaryFunction1D::__call__() failed." << endl;
|
||||
PyErr_Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if( BPy_UnaryFunction1DDouble_Check(obj) ) {
|
||||
((UnaryFunction1D<double> *) uf1D)->result = PyFloat_AsDouble(result);
|
||||
@@ -204,7 +250,6 @@ void Director_BPy_UnaryFunction1D___call__( void *uf1D, PyObject *obj, Interface
|
||||
|
||||
}
|
||||
|
||||
Py_DECREF(arg);
|
||||
Py_DECREF(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user