[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19448] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python: Improvements on error handling in the Python API.
Tamito Kajiyama
rd6t-kjym at asahi-net.or.jp
Sun Mar 29 19:44:14 CEST 2009
Revision: 19448
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19448
Author: kjym3
Date: 2009-03-29 19:44:14 +0200 (Sun, 29 Mar 2009)
Log Message:
-----------
Improvements on error handling in the Python API.
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_SShape.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ViewMap.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ViewShape.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp 2009-03-29 15:17:55 UTC (rev 19447)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface0D.cpp 2009-03-29 17:44:14 UTC (rev 19448)
@@ -249,10 +249,8 @@
PyObject *Interface0D_getFEdge( BPy_Interface0D *self, PyObject *args ) {
PyObject *py_if0D;
- if(!( PyArg_ParseTuple(args, "O", &py_if0D) && BPy_Interface0D_Check(py_if0D) )) {
- cout << "ERROR: Interface0D_getFEdge" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &Interface0D_Type, &py_if0D) ))
+ return NULL;
FEdge *fe = self->if0D->getFEdge(*( ((BPy_Interface0D *) py_if0D)->if0D ));
if( fe )
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface1D.cpp 2009-03-29 15:17:55 UTC (rev 19447)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Interface1D.cpp 2009-03-29 17:44:14 UTC (rev 19448)
@@ -246,10 +246,8 @@
PyObject *Interface1D_setTimeStamp( BPy_Interface1D *self, PyObject *args) {
int timestamp = 0 ;
- if( !PyArg_ParseTuple(args, (char *)"i", ×tamp) ) {
- cout << "ERROR: Interface1D_setTimeStamp" << endl;
- Py_RETURN_NONE;
- }
+ if( !PyArg_ParseTuple(args, "i", ×tamp) )
+ return NULL;
self->if1D->setTimeStamp( timestamp );
@@ -270,10 +268,8 @@
PyObject * Interface1D_pointsBegin( BPy_Interface1D *self, PyObject *args ) {
float f = 0;
- if(!( PyArg_ParseTuple(args, "|f", &f) )) {
- cout << "ERROR: Interface1D_pointsBegin" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "|f", &f) ))
+ return NULL;
Interface0DIterator if0D_it( self->if1D->pointsBegin(f) );
return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it );
@@ -282,10 +278,8 @@
PyObject * Interface1D_pointsEnd( BPy_Interface1D *self, PyObject *args ) {
float f = 0;
- if(!( PyArg_ParseTuple(args, "|f", &f) )) {
- cout << "ERROR: Interface1D_pointsEnd" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "|f", &f) ))
+ return NULL;
Interface0DIterator if0D_it( self->if1D->pointsEnd(f) );
return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it );
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_SShape.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_SShape.cpp 2009-03-29 15:17:55 UTC (rev 19447)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_SShape.cpp 2009-03-29 17:44:14 UTC (rev 19448)
@@ -144,15 +144,15 @@
int SShape___init__(BPy_SShape *self, PyObject *args, PyObject *kwds)
{
- PyObject *obj;
+ PyObject *obj = NULL;
- if (! PyArg_ParseTuple(args, "|O", &obj) )
+ if (! PyArg_ParseTuple(args, "|O!", &SShape_Type, &obj) )
return -1;
if( !obj ) {
self->ss = new SShape();
- } else if( BPy_SShape_Check(obj) ) {
+ } else {
self->ss = new SShape(*( ((BPy_SShape *) obj)->ss ));
}
@@ -173,10 +173,8 @@
PyObject * SShape_AddEdge( BPy_SShape *self , PyObject *args) {
PyObject *py_fe = 0;
- if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) {
- cout << "ERROR: SShape_AddEdge" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) ))
+ return NULL;
self->ss->AddEdge( ((BPy_FEdge *) py_fe)->fe );
@@ -186,10 +184,8 @@
PyObject * SShape_AddNewVertex( BPy_SShape *self , PyObject *args) {
PyObject *py_sv = 0;
- if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) {
- cout << "ERROR: SShape_AddNewVertex" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O1", &SVertex_Type, &py_sv) ))
+ return NULL;
self->ss->AddNewVertex( ((BPy_SVertex *) py_sv)->sv );
@@ -199,10 +195,8 @@
PyObject * SShape_setBBox( BPy_SShape *self , PyObject *args) {
PyObject *py_bb = 0;
- if(!( PyArg_ParseTuple(args, "O", &py_bb) && BPy_BBox_Check(py_bb) )) {
- cout << "ERROR: SShape_SetBBox" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &BBox_Type, &py_bb) ))
+ return NULL;
self->ss->setBBox(*( ((BPy_BBox*) py_bb)->bb ));
@@ -256,10 +250,8 @@
PyObject * SShape_setId( BPy_SShape *self , PyObject *args) {
PyObject *py_id;
- if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) {
- cout << "ERROR: SShape_setId" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) ))
+ return NULL;
self->ss->setId(*( ((BPy_Id *) py_id)->id ));
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp 2009-03-29 15:17:55 UTC (rev 19447)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp 2009-03-29 17:44:14 UTC (rev 19448)
@@ -196,6 +196,7 @@
PyFloat_AsDouble( obj6 ) );
} else {
+ PyErr_SetString(PyExc_TypeError, "invalid arguments");
return -1;
}
@@ -266,10 +267,8 @@
PyObject *StrokeAttribute_getAttributeReal( BPy_StrokeAttribute *self, PyObject *args ) {
char *attr;
- if(!( PyArg_ParseTuple(args, "s", &attr) )) {
- cout << "ERROR: StrokeAttribute_getAttributeReal" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "s", &attr) ))
+ return NULL;
double a = self->sa->getAttributeReal( attr );
return PyFloat_FromDouble( a );
@@ -278,10 +277,8 @@
PyObject *StrokeAttribute_getAttributeVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
char *attr;
- if(!( PyArg_ParseTuple(args, "s", &attr) )) {
- cout << "ERROR: StrokeAttribute_getAttributeVec2f" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "s", &attr) ))
+ return NULL;
Vec2f a = self->sa->getAttributeVec2f( attr );
return Vector_from_Vec2f( a );
@@ -291,10 +288,8 @@
PyObject *StrokeAttribute_getAttributeVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
char *attr;
- if(!( PyArg_ParseTuple(args, "s", &attr) )) {
- cout << "ERROR: StrokeAttribute_getAttributeVec3f" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "s", &attr) ))
+ return NULL;
Vec3f a = self->sa->getAttributeVec3f( attr );
return Vector_from_Vec3f( a );
@@ -303,10 +298,8 @@
PyObject *StrokeAttribute_isAttributeAvailableReal( BPy_StrokeAttribute *self, PyObject *args ) {
char *attr;
- if(!( PyArg_ParseTuple(args, "s", &attr) )) {
- cout << "ERROR: StrokeAttribute_isAttributeAvailableReal" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "s", &attr) ))
+ return NULL;
return PyBool_from_bool( self->sa->isAttributeAvailableReal( attr ) );
}
@@ -314,10 +307,8 @@
PyObject *StrokeAttribute_isAttributeAvailableVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
char *attr;
- if(!( PyArg_ParseTuple(args, "s", &attr) )) {
- cout << "ERROR: StrokeAttribute_isAttributeAvailableVec2f" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "s", &attr) ))
+ return NULL;
return PyBool_from_bool( self->sa->isAttributeAvailableVec2f( attr ) );
}
@@ -325,10 +316,8 @@
PyObject *StrokeAttribute_isAttributeAvailableVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
char *attr;
- if(!( PyArg_ParseTuple(args, "s", &attr) )) {
- cout << "ERROR: StrokeAttribute_isAttributeAvailableVec3f" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "s", &attr) ))
+ return NULL;
return PyBool_from_bool( self->sa->isAttributeAvailableVec3f( attr ) );
}
@@ -337,10 +326,8 @@
PyObject * StrokeAttribute_setColor( BPy_StrokeAttribute *self, PyObject *args ) {
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0 ;
- if(!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) )) {
- cout << "ERROR: StrokeAttribute_setColor" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) ))
+ return NULL;
if( PyList_Check(obj1) && !obj2 && !obj3 ){
@@ -355,6 +342,10 @@
self->sa->setColor( PyFloat_AsDouble(obj1),
PyFloat_AsDouble(obj2),
PyFloat_AsDouble(obj3) );
+
+ } else {
+ PyErr_SetString(PyExc_TypeError, "invalid arguments");
+ return NULL;
}
Py_RETURN_NONE;
@@ -363,10 +354,8 @@
PyObject * StrokeAttribute_setAlpha( BPy_StrokeAttribute *self, PyObject *args ){
float f = 0;
- if(!( PyArg_ParseTuple(args, "f", &f) )) {
- cout << "ERROR: StrokeAttribute_setAlpha" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "f", &f) ))
+ return NULL;
self->sa->setAlpha( f );
Py_RETURN_NONE;
@@ -375,10 +364,8 @@
PyObject * StrokeAttribute_setThickness( BPy_StrokeAttribute *self, PyObject *args ) {
PyObject *obj1 = 0, *obj2 = 0;
- if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) )) {
- cout << "ERROR: StrokeAttribute_setThickness" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) ))
+ return NULL;
if( PyList_Check(obj1) && !obj2 ){
@@ -391,6 +378,10 @@
self->sa->setThickness( PyFloat_AsDouble(obj1),
PyFloat_AsDouble(obj2) );
+
+ } else {
+ PyErr_SetString(PyExc_TypeError, "invalid arguments");
+ return NULL;
}
Py_RETURN_NONE;
@@ -399,10 +390,8 @@
PyObject * StrokeAttribute_setVisible( BPy_StrokeAttribute *self, PyObject *args ) {
PyObject *py_b;
- if(!( PyArg_ParseTuple(args, "O", &py_b) && PyBool_Check(py_b) )) {
- cout << "ERROR: StrokeAttribute_setVisible" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) ))
+ return NULL;
self->sa->setVisible( bool_from_PyBool(py_b) );
@@ -414,10 +403,8 @@
char *s = 0;
double d = 0;
- if(!( PyArg_ParseTuple(args, "sd", &s, &d) )) {
- cout << "ERROR: StrokeAttribute_setAttributeReal" << endl;
- Py_RETURN_NONE;
- }
+ if(!( PyArg_ParseTuple(args, "sd", &s, &d) ))
+ return NULL;
self->sa->setAttributeReal( s, d );
Py_RETURN_NONE;
@@ -427,10 +414,8 @@
char *s;
PyObject *obj = 0;
- if(!( PyArg_ParseTuple(args, "sO", &s, &obj) )) {
- cout << "ERROR: StrokeAttribute_setAttributeVec2f" << endl;
- Py_RETURN_NONE;
- }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list