diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-04-04 00:03:09 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-04-04 00:03:09 +0400 |
commit | acfd7c82abdc26b7cd2859e762f12cc066a4ef68 (patch) | |
tree | 41c8ea9b40a662db1cc86bc167feec4ea563ea2b /source | |
parent | 5926ad2db281aeb965d382533973393f0459315b (diff) |
Relaxed type checking concerning boolean arguments in class constructors
and __call__ methods so that not only True and False but also various
other boolean expressions (e.g., 0, 1, and None) are accepted.
Diffstat (limited to 'source')
14 files changed, 82 insertions, 34 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 8b26afd85a5..a3777d6415c 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -326,7 +326,7 @@ PyObject * BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator( ChainSilhou //============================== bool bool_from_PyBool( PyObject *b ) { - return (b == Py_True || PyInt_AsLong(b) != 0); + return PyObject_IsTrue(b) != 0; } IntegrationType IntegrationType_from_BPy_IntegrationType( PyObject* obj ) { diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index 73e073256f2..6bc25ed8fdd 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -390,7 +390,7 @@ PyObject * StrokeAttribute_setThickness( BPy_StrokeAttribute *self, PyObject *ar PyObject * StrokeAttribute_setVisible( BPy_StrokeAttribute *self, PyObject *args ) { PyObject *py_b; - if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) )) + if(!( PyArg_ParseTuple(args, "O", &py_b) )) return NULL; self->sa->setVisible( bool_from_PyBool(py_b) ); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index 1773e86c065..84529321f29 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -330,7 +330,7 @@ PyObject * FEdge_setViewEdge( BPy_FEdge *self, PyObject *args ) { PyObject *FEdge_setSmooth( BPy_FEdge *self , PyObject *args) { PyObject *py_b; - if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) )) + if(!( PyArg_ParseTuple(args, "O", &py_b) )) return NULL; self->fe->setSmooth( bool_from_PyBool(py_b) ); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index f7c5e261db5..6bca6db2cb7 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -354,7 +354,7 @@ PyObject *Stroke_setTextureId( BPy_Stroke *self , PyObject *args) { PyObject *Stroke_setTips( BPy_Stroke *self , PyObject *args) { PyObject *py_b; - if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) )) + if(!( PyArg_ParseTuple(args, "O", &py_b) )) return NULL; self->s->setTips( bool_from_PyBool(py_b) ); diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp index f30b2bbdd96..5714f415d80 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp @@ -145,7 +145,7 @@ int Chain___init__(BPy_Chain *self, PyObject *args, PyObject *kwds) PyObject * Chain_push_viewedge_back( BPy_Chain *self, PyObject *args ) { PyObject *obj1 = 0, *obj2 = 0; - if(!( PyArg_ParseTuple(args, "O!O!", &ViewEdge_Type, &obj1, &PyBool_Type, &obj2) )) + if(!( PyArg_ParseTuple(args, "O!O", &ViewEdge_Type, &obj1, &obj2) )) return NULL; ViewEdge *ve = ((BPy_ViewEdge *) obj1)->ve; @@ -158,7 +158,7 @@ PyObject * Chain_push_viewedge_back( BPy_Chain *self, PyObject *args ) { PyObject * Chain_push_viewedge_front( BPy_Chain *self, PyObject *args ) { PyObject *obj1 = 0, *obj2 = 0; - if(!( PyArg_ParseTuple(args, "O!O!", &ViewEdge_Type, &obj1, &PyBool_Type, &obj2) )) + if(!( PyArg_ParseTuple(args, "O!O", &ViewEdge_Type, &obj1, &obj2) )) return NULL; ViewEdge *ve = ((BPy_ViewEdge *) obj1)->ve; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 872db712e91..9adc6c405e0 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -124,8 +124,8 @@ int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *args ) self->a_it = new AdjacencyIterator(*( ((BPy_AdjacencyIterator *) obj1)->a_it )); } else if( BPy_ViewVertex_Check(obj1) ) { - bool restrictToSelection = ( obj2 && PyBool_Check(obj2) ) ? bool_from_PyBool(obj2) : true; - bool restrictToUnvisited = ( obj3 && PyBool_Check(obj3) ) ? bool_from_PyBool(obj3) : true; + bool restrictToSelection = ( obj2 ) ? bool_from_PyBool(obj2) : true; + bool restrictToUnvisited = ( obj3 ) ? bool_from_PyBool(obj3) : true; self->a_it = new AdjacencyIterator( ((BPy_ViewVertex *) obj1)->vv, restrictToSelection, restrictToUnvisited ); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp index 3d41e4b66c1..79ef0a93dba 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -111,29 +111,53 @@ int ChainPredicateIterator___init__(BPy_ChainPredicateIterator *self, PyObject * { PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; - if (!( PyArg_ParseTuple(args, "O|OOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6) )) + if (!( PyArg_ParseTuple(args, "|OOOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6) )) return -1; if( obj1 && BPy_ChainPredicateIterator_Check(obj1) ) { self->cp_it = new ChainPredicateIterator(*( ((BPy_ChainPredicateIterator *) obj1)->cp_it )); - } else if( obj1 && BPy_UnaryPredicate1D_Check(obj1) && ((BPy_UnaryPredicate1D *) obj1)->up1D && - obj2 && BPy_BinaryPredicate1D_Check(obj2) && ((BPy_BinaryPredicate1D *) obj2)->bp1D ) { + } else if( obj1 && BPy_UnaryPredicate1D_Check(obj1) && + obj2 && BPy_BinaryPredicate1D_Check(obj2) ) { + if (!((BPy_UnaryPredicate1D *) obj1)->up1D) { + PyErr_SetString(PyExc_TypeError, "1st argument: invalid UnaryPredicate1D object"); + return -1; + } + if (!((BPy_BinaryPredicate1D *) obj2)->bp1D) { + PyErr_SetString(PyExc_TypeError, "2nd argument: invalid BinaryPredicate1D object"); + return -1; + } UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj1)->up1D; BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *) obj2)->bp1D; - bool restrictToSelection = ( obj3 && PyBool_Check(obj3) ) ? bool_from_PyBool(obj3) : true; - bool restrictToUnvisited = ( obj4 && PyBool_Check(obj4) ) ? bool_from_PyBool(obj4) : true; - ViewEdge *begin = ( obj5 && BPy_ViewEdge_Check(obj5) ) ? ((BPy_ViewEdge *) obj5)->ve : 0; - bool orientation = ( obj6 && PyBool_Check(obj6) ) ? bool_from_PyBool(obj6) : true; + bool restrictToSelection = ( obj3 ) ? bool_from_PyBool(obj3) : true; + bool restrictToUnvisited = ( obj4 ) ? bool_from_PyBool(obj4) : true; + ViewEdge *begin; + if ( !obj5 || obj5 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj5) ) + begin = ((BPy_ViewEdge *) obj5)->ve; + else { + PyErr_SetString(PyExc_TypeError, "5th argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj6 ) ? bool_from_PyBool(obj6) : true; self->cp_it = new ChainPredicateIterator( *up1D, *bp1D, restrictToSelection, restrictToUnvisited, begin, orientation); } else { - bool restrictToSelection = ( obj1 && PyBool_Check(obj1) ) ? bool_from_PyBool(obj1) : true; - bool restrictToUnvisited = ( obj2 && PyBool_Check(obj2) ) ? bool_from_PyBool(obj2) : true; - ViewEdge *begin = ( obj3 && BPy_ViewEdge_Check(obj3) ) ? ((BPy_ViewEdge *) obj3)->ve : 0; - bool orientation = ( obj4 && PyBool_Check(obj4) ) ? bool_from_PyBool(obj4) : true; + bool restrictToSelection = ( obj1 ) ? bool_from_PyBool(obj1) : true; + bool restrictToUnvisited = ( obj2 ) ? bool_from_PyBool(obj2) : true; + ViewEdge *begin; + if ( !obj3 || obj3 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj3) ) + begin = ((BPy_ViewEdge *) obj3)->ve; + else { + PyErr_SetString(PyExc_TypeError, "3rd argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj4 ) ? bool_from_PyBool(obj4) : true; self->cp_it = new ChainPredicateIterator( restrictToSelection, restrictToUnvisited, begin, orientation); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp index 4bfaab92a8e..3ad22fe5235 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -118,9 +118,17 @@ int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject self->cs_it = new ChainSilhouetteIterator(*( ((BPy_ChainSilhouetteIterator *) obj1)->cs_it )); } else { - bool restrictToSelection = ( obj1 && PyBool_Check(obj1) ) ? bool_from_PyBool(obj1) : true; - ViewEdge *begin = ( obj2 && BPy_ViewEdge_Check(obj2) ) ? ((BPy_ViewEdge *) obj2)->ve : 0; - bool orientation = ( obj3 && PyBool_Check(obj3) ) ? bool_from_PyBool(obj3) : true; + bool restrictToSelection = ( obj1 ) ? bool_from_PyBool(obj1) : true; + ViewEdge *begin; + if ( !obj2 || obj2 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj2) ) + begin = ((BPy_ViewEdge *) obj2)->ve; + else { + PyErr_SetString(PyExc_TypeError, "2nd argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj3 ) ? bool_from_PyBool(obj3) : true; self->cs_it = new ChainSilhouetteIterator( restrictToSelection, begin, orientation); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index efa9503de75..df239793e3e 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -121,17 +121,25 @@ int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args ) { PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - if (!( PyArg_ParseTuple(args, "O|OOO", &obj1, &obj2, &obj3, &obj4) )) + if (!( PyArg_ParseTuple(args, "|OOOO", &obj1, &obj2, &obj3, &obj4) )) return -1; if( obj1 && BPy_ChainingIterator_Check(obj1) ) { self->c_it = new ChainingIterator(*( ((BPy_ChainingIterator *) obj1)->c_it )); } else { - bool restrictToSelection = ( obj1 && PyBool_Check(obj1) ) ? bool_from_PyBool(obj1) : true; - bool restrictToUnvisited = ( obj2 && PyBool_Check(obj2) ) ? bool_from_PyBool(obj2) : true; - ViewEdge *begin = ( obj3 && BPy_ViewEdge_Check(obj3) ) ? ((BPy_ViewEdge *) obj3)->ve : 0; - bool orientation = ( obj4 && PyBool_Check(obj4) ) ? bool_from_PyBool(obj4) : true; + bool restrictToSelection = ( obj1 ) ? bool_from_PyBool(obj1) : true; + bool restrictToUnvisited = ( obj2 ) ? bool_from_PyBool(obj2) : true; + ViewEdge *begin; + if ( !obj3 || obj3 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj3) ) + begin = ((BPy_ViewEdge *) obj3)->ve; + else { + PyErr_SetString(PyExc_TypeError, "3rd argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj4 ) ? bool_from_PyBool(obj4) : true; self->c_it = new ChainingIterator( restrictToSelection, restrictToUnvisited, begin, orientation); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index 9b913510e4d..ae1ceaf5da1 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -135,8 +135,16 @@ int ViewEdgeIterator___init__(BPy_ViewEdgeIterator *self, PyObject *args ) self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*( ((BPy_ViewEdgeIterator *) obj1)->ve_it )); } else { - ViewEdge *begin = ( obj1 && BPy_ViewEdge_Check(obj1) ) ? ((BPy_ViewEdge *) obj1)->ve : 0; - bool orientation = ( obj2 && PyBool_Check(obj2) ) ? bool_from_PyBool(obj2) : true; + ViewEdge *begin; + if ( !obj1 || obj1 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj1) ) + begin = ((BPy_ViewEdge *) obj1)->ve; + else { + PyErr_SetString(PyExc_TypeError, "1st argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj2 ) ? bool_from_PyBool(obj2) : true; self->ve_it = new ViewEdgeInternal::ViewEdgeIterator( begin, orientation); @@ -192,7 +200,7 @@ PyObject *ViewEdgeIterator_getOrientation( BPy_ViewEdgeIterator *self ) { PyObject *ViewEdgeIterator_setOrientation( BPy_ViewEdgeIterator *self, PyObject *args ) { PyObject *py_b; - if(!( PyArg_ParseTuple(args, "O!", &PyBool_Type, &py_b) )) + if(!( PyArg_ParseTuple(args, "O", &py_b) )) return NULL; self->ve_it->setOrientation( bool_from_PyBool(py_b) ); diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp index e61179eb901..1d22be137e3 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp @@ -105,7 +105,7 @@ int CalligraphicShader___init__( BPy_CalligraphicShader* self, PyObject *args) PyObject *obj3 = 0, *obj4 = 0; - if(!( PyArg_ParseTuple(args, "ddO!O!", &d1, &d2, &PyList_Type, &obj3, &PyBool_Type, &obj4) )) + if(!( PyArg_ParseTuple(args, "ddO!O", &d1, &d2, &PyList_Type, &obj3, &obj4) )) return -1; if( PyList_Size(obj3) != 2 ) { stringstream msg("CalligraphicShader() accepts a list of 2 elements ("); diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp index e938714f559..c226901895b 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp @@ -106,7 +106,7 @@ int SpatialNoiseShader___init__( BPy_SpatialNoiseShader* self, PyObject *args) PyObject *obj4 = 0, *obj5 = 0; - if(!( PyArg_ParseTuple(args, "ffiO!O!", &f1, &f2, &i3, &PyBool_Type, &obj4, &PyBool_Type, &obj5) )) { + if(!( PyArg_ParseTuple(args, "ffiOO", &f1, &f2, &i3, &obj4, &obj5) )) { cout << "ERROR: SpatialNoiseShader___init__" << endl; return -1; } diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp index 6fe43bb7c4b..2223410087a 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp @@ -105,7 +105,7 @@ int StrokeTextureShader___init__( BPy_StrokeTextureShader* self, PyObject *args) const char *s1; PyObject *obj2 = 0, *obj3 = 0; - if(!( PyArg_ParseTuple(args, "s|O!O!", &s1, &MediumType_Type, &obj2, &PyBool_Type, &obj3) )) { + if(!( PyArg_ParseTuple(args, "s|O!O", &s1, &MediumType_Type, &obj2, &obj3) )) { cout << "ERROR: StrokeTextureShader___init__" << endl; return -1; } diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp index 1a399b72128..66a3fa01a3f 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp @@ -105,7 +105,7 @@ int ThicknessVariationPatternShader___init__( BPy_ThicknessVariationPatternShade float f2 = 1.0, f3 = 5.0; PyObject *obj4 = 0; - if(!( PyArg_ParseTuple(args, "s|ffO!", &s1, &f2, &f3, &PyBool_Type, &obj4) )) { + if(!( PyArg_ParseTuple(args, "s|ffO", &s1, &f2, &f3, &obj4) )) { cout << "ERROR: ThicknessVariationPatternShader___init__" << endl; return -1; } |