From 67e4d7dc63a6654b848d9966991ca2b507b78aa7 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Tue, 31 Mar 2009 22:45:11 +0000 Subject: Improvements on error handling in the Python API. --- .../python/Interface1D/FEdge/BPy_FEdgeSharp.cpp | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp') diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp index 336331d92d5..c6bc201e37d 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp @@ -136,15 +136,13 @@ int FEdgeSharp___init__(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds) self->fes = new FEdgeSharp(); } else if( BPy_FEdgeSharp_Check(obj1) ) { - if( ((BPy_FEdgeSharp *) obj1)->fes ) - self->fes = new FEdgeSharp(*( ((BPy_FEdgeSharp *) obj1)->fes )); - else - return -1; + self->fes = new FEdgeSharp(*( ((BPy_FEdgeSharp *) obj1)->fes )); } else if( BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { self->fes = new FEdgeSharp( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv ); } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } @@ -186,9 +184,13 @@ PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self ) { PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) { - cout << "ERROR: FEdgeSharp_setNormalA" << endl; - Py_RETURN_NONE; + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + return NULL; + if( PyList_Size(obj) != 3 ) { + stringstream msg("FEdgeSharp::setNormalA() accepts a list of 3 elements ("); + msg << PyList_Size(obj) << " found)"; + PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + return NULL; } Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), @@ -203,9 +205,13 @@ PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) { - cout << "ERROR: FEdgeSharp_setNormalB" << endl; - Py_RETURN_NONE; + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + return NULL; + if( PyList_Size(obj) != 3 ) { + stringstream msg("FEdgeSharp::setNormalB() accepts a list of 3 elements ("); + msg << PyList_Size(obj) << " found)"; + PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + return NULL; } Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), @@ -220,10 +226,8 @@ PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) { PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) { unsigned int i; - if(!( PyArg_ParseTuple(args, "I", &i) )) { - cout << "ERROR: FEdgeSharp_setaMaterialIndex" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "I", &i) )) + return NULL; self->fes->setaFrsMaterialIndex( i ); @@ -233,10 +237,8 @@ PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) PyObject * FEdgeSharp_setbMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) { unsigned int i; - if(!( PyArg_ParseTuple(args, "I", &i) )) { - cout << "ERROR: FEdgeSharp_setbMaterialIndex" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "I", &i) )) + return NULL; self->fes->setbFrsMaterialIndex( i ); -- cgit v1.2.3