Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-03-13 22:24:05 +0300
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-03-13 22:24:05 +0300
commit2fbcd6c4bdc48817e7f27e567cbf81d2545b1a49 (patch)
tree18a23b1aaed184b520536912c71d6e64de5320cb /source
parent838234e5eab3911a2aefea67da6c28b436f708ec (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/freestyle/intern/python/Director.cpp59
1 files changed, 52 insertions, 7 deletions
diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp
index 8c3d6fcf0cf..8535c82be51 100644
--- a/source/blender/freestyle/intern/python/Director.cpp
+++ b/source/blender/freestyle/intern/python/Director.cpp
@@ -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);
}