diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-03-30 01:50:10 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-03-30 01:50:10 +0400 |
commit | a377b74638245f8eb1a956c9840e16a448de553e (patch) | |
tree | f9d9197211b89561069bf887de764468924ab9e7 /source/blender/freestyle/intern/python/StrokeShader | |
parent | fbd92e985ed5bf19a92839b4b3fec9a93ce6519f (diff) |
Improvements on error handling in the Python API.
Diffstat (limited to 'source/blender/freestyle/intern/python/StrokeShader')
5 files changed, 13 insertions, 11 deletions
diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp index d20fbeab1ec..e61179eb901 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp @@ -105,9 +105,12 @@ int CalligraphicShader___init__( BPy_CalligraphicShader* self, PyObject *args) PyObject *obj3 = 0, *obj4 = 0; - if(!( PyArg_ParseTuple(args, "ddOO", &d1, &d2, &obj3, &obj4) - && PyList_Check(obj3) && PyList_Size(obj3) > 1 && PyBool_Check(obj4) )) { - cout << "ERROR: CalligraphicShader___init__" << endl; + if(!( PyArg_ParseTuple(args, "ddO!O!", &d1, &d2, &PyList_Type, &obj3, &PyBool_Type, &obj4) )) + return -1; + if( PyList_Size(obj3) != 2 ) { + stringstream msg("CalligraphicShader() accepts a list of 2 elements ("); + msg << PyList_Size(obj3) << " found)"; + PyErr_SetString(PyExc_TypeError, msg.str().c_str()); return -1; } diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp index a3440295767..9d20000bffe 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp @@ -102,7 +102,7 @@ int ConstantThicknessShader___init__( BPy_ConstantThicknessShader* self, PyObjec { float f; - if(!( PyArg_ParseTuple(args, "|f", &f) )) { + if(!( PyArg_ParseTuple(args, "f", &f) )) { cout << "ERROR: ConstantThicknessShader___init__" << endl; return -1; } diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp index f8780b7baee..e938714f559 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp @@ -106,8 +106,7 @@ int SpatialNoiseShader___init__( BPy_SpatialNoiseShader* self, PyObject *args) PyObject *obj4 = 0, *obj5 = 0; - if(!( PyArg_ParseTuple(args, "ffiOO", &f1, &f2, &i3, &obj4, &obj5) - && PyBool_Check(obj4) && PyBool_Check(obj5) )) { + if(!( PyArg_ParseTuple(args, "ffiO!O!", &f1, &f2, &i3, &PyBool_Type, &obj4, &PyBool_Type, &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 480a5b2d2ff..6fe43bb7c4b 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp @@ -105,13 +105,13 @@ int StrokeTextureShader___init__( BPy_StrokeTextureShader* self, PyObject *args) const char *s1; PyObject *obj2 = 0, *obj3 = 0; - if(!( PyArg_ParseTuple(args, "s|OO", &s1, &obj2, &obj3) )) { + if(!( PyArg_ParseTuple(args, "s|O!O!", &s1, &MediumType_Type, &obj2, &PyBool_Type, &obj3) )) { cout << "ERROR: StrokeTextureShader___init__" << endl; return -1; } - Stroke::MediumType mt = (obj2 && BPy_MediumType_Check(obj2)) ? MediumType_from_BPy_MediumType(obj2) : Stroke::OPAQUE_MEDIUM; - bool b = (obj3 && PyBool_Check(obj3)) ? bool_from_PyBool(obj3) : true; + Stroke::MediumType mt = (obj2) ? MediumType_from_BPy_MediumType(obj2) : Stroke::OPAQUE_MEDIUM; + bool b = (obj3) ? bool_from_PyBool(obj3) : true; self->py_ss.ss = new StrokeShaders::StrokeTextureShader(s1,mt,b); return 0; diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp index d7f49b60fa5..1a399b72128 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp @@ -105,12 +105,12 @@ int ThicknessVariationPatternShader___init__( BPy_ThicknessVariationPatternShade float f2 = 1.0, f3 = 5.0; PyObject *obj4 = 0; - if(!( PyArg_ParseTuple(args, "s|ffO", &s1, &f2, &f3, &obj4) )) { + if(!( PyArg_ParseTuple(args, "s|ffO!", &s1, &f2, &f3, &PyBool_Type, &obj4) )) { cout << "ERROR: ThicknessVariationPatternShader___init__" << endl; return -1; } - bool b = (obj4 && PyBool_Check(obj4)) ? bool_from_PyBool(obj4) : true; + bool b = (obj4) ? bool_from_PyBool(obj4) : true; self->py_ss.ss = new StrokeShaders::ThicknessVariationPatternShader(s1, f2, f3, b); return 0; |