From 2f5e1969ed6f976930fef2e5e83df80979e22a88 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sat, 4 Apr 2009 15:26:12 +0000 Subject: Improvements on error handling in the Python API. --- .../intern/python/Interface0D/BPy_SVertex.cpp | 45 ++++++++++++---------- .../intern/python/Interface0D/BPy_ViewVertex.cpp | 12 ++---- 2 files changed, 29 insertions(+), 28 deletions(-) (limited to 'source/blender/freestyle/intern/python') diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 748cbc8f1db..db27f343ebc 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -187,10 +187,13 @@ PyObject * SVertex_viewvertex( BPy_SVertex *self ) { PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) { PyObject *py_point; - if(!( PyArg_ParseTuple(args, "O", &py_point) - && PyList_Check(py_point) && PyList_Size(py_point) == 3 )) { - cout << "ERROR: SVertex_setPoint3D" << endl; - Py_RETURN_NONE; + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_point) )) + return NULL; + if( PyList_Size(py_point) != 3 ) { + stringstream msg("SVertex::setPoint3D() accepts a list of 3 elements ("); + msg << PyList_Size(py_point) << " found)"; + PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + return NULL; } Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ), @@ -204,10 +207,13 @@ PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) { PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) { PyObject *py_point; - if(!( PyArg_ParseTuple(args, "O", &py_point) - && PyList_Check(py_point) && PyList_Size(py_point) == 3 )) { - cout << "ERROR: SVertex_setPoint2D" << endl; - Py_RETURN_NONE; + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_point) )) + return NULL; + if( PyList_Size(py_point) != 3 ) { + stringstream msg("SVertex::setPoint2D() accepts a list of 3 elements ("); + msg << PyList_Size(py_point) << " found)"; + PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + return NULL; } Vec3r v( PyFloat_AsDouble( PyList_GetItem(py_point, 0) ), @@ -221,10 +227,13 @@ PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) { PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) { PyObject *py_normal; - if(!( PyArg_ParseTuple(args, "O", &py_normal) - && PyList_Check(py_normal) && PyList_Size(py_normal) == 3 )) { - cout << "ERROR: SVertex_AddNormal" << endl; - Py_RETURN_NONE; + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &py_normal) )) + return NULL; + if( PyList_Size(py_normal) != 3 ) { + stringstream msg("SVertex::AddNormal() accepts a list of 3 elements ("); + msg << PyList_Size(py_normal) << " found)"; + PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + return NULL; } Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ), @@ -238,10 +247,8 @@ PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) { PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) { BPy_Id *py_id; - if( !PyArg_ParseTuple(args, "O", &py_id) ) { - cout << "ERROR: SVertex_setId" << endl; - Py_RETURN_NONE; - } + if( !PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) ) + return NULL; self->sv->setId( *(py_id->id) ); @@ -251,10 +258,8 @@ PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) { PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) { PyObject *py_fe; - if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { - cout << "ERROR: SVertex_AddFEdge" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe ); diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp index ba06d071977..660125a1251 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -131,10 +131,8 @@ PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args ) { if( !self->vv ) Py_RETURN_NONE; - if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) { - cout << "ERROR: ViewVertex_setNature" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) + return NULL; PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); ((ViewVertex *) self->py_if0D.if0D)->setNature( PyInt_AsLong(i) ); @@ -165,10 +163,8 @@ PyObject * ViewVertex_edgesIterator( BPy_ViewVertex *self, PyObject *args ) { if( !self->vv ) Py_RETURN_NONE; - if(!( PyArg_ParseTuple(args, "O", &py_ve) && BPy_ViewEdge_Check(py_ve) )) { - cout << "ERROR: ViewVertex_setNature" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve; ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) ); -- cgit v1.2.3