From a377b74638245f8eb1a956c9840e16a448de553e Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sun, 29 Mar 2009 21:50:10 +0000 Subject: Improvements on error handling in the Python API. --- .../intern/python/Interface1D/BPy_FrsCurve.cpp | 57 ++++++++++------------ 1 file changed, 25 insertions(+), 32 deletions(-) (limited to 'source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp') diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp index 1506092511a..541391e05a7 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -138,18 +138,13 @@ int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) self->c = new Curve(); } else if( BPy_FrsCurve_Check(obj) ) { - if( ((BPy_FrsCurve *) obj)->c ) - self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); - else - return -1; + self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); } else if( BPy_Id_Check(obj) ) { - if( ((BPy_Id *) obj)->id ) - self->c = new Curve(*( ((BPy_Id *) obj)->id )); - else - return -1; + self->c = new Curve(*( ((BPy_Id *) obj)->id )); } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; } @@ -162,37 +157,39 @@ int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args ) { PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: FrsCurve_push_vertex_back" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O", &obj) )) + return NULL; if( BPy_CurvePoint_Check(obj) ) { self->c->push_vertex_back( ((BPy_CurvePoint *) obj)->cp ); } else if( BPy_SVertex_Check(obj) ) { self->c->push_vertex_back( ((BPy_SVertex *) obj)->sv ); + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; } Py_RETURN_NONE; } PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args ) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: FrsCurve_push_vertex_front" << endl; - Py_RETURN_NONE; - } + PyObject *obj; - if( BPy_CurvePoint_Check(obj) ) { - self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); - } else if( BPy_SVertex_Check(obj) ) { - self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); - } + if(!( PyArg_ParseTuple(args, "O", &obj) )) + return NULL; - Py_RETURN_NONE; + if( BPy_CurvePoint_Check(obj) ) { + self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); + } else if( BPy_SVertex_Check(obj) ) { + self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; } + Py_RETURN_NONE; +} + PyObject * FrsCurve_empty( BPy_FrsCurve *self ) { return PyBool_from_bool( self->c->empty() ); } @@ -219,10 +216,8 @@ PyObject * FrsCurve_verticesEnd( BPy_FrsCurve *self ) { PyObject * FrsCurve_pointsBegin( BPy_FrsCurve *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsBegin" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->c->pointsBegin(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); @@ -231,10 +226,8 @@ PyObject * FrsCurve_pointsBegin( BPy_FrsCurve *self, PyObject *args ) { PyObject * FrsCurve_pointsEnd( BPy_FrsCurve *self, PyObject *args ) { float f = 0; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsEnd" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "|f", &f) )) + return NULL; Interface0DIterator if0D_it( self->c->pointsEnd(f) ); return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); -- cgit v1.2.3