diff options
author | Ken Hughes <khughes@pacific.edu> | 2006-01-01 18:50:53 +0300 |
---|---|---|
committer | Ken Hughes <khughes@pacific.edu> | 2006-01-01 18:50:53 +0300 |
commit | 5029a4444a7d62125c83ade29b0c04b5d513a374 (patch) | |
tree | 1b9e213fbae82fce91f4632e890946edd4b69509 /source/blender/python/api2_2x/BezTriple.c | |
parent | 3634128841007e768ff3d6869399005876216dd3 (diff) |
Bug fix #3671: Blender.Beztriple.New() did not accept sequences as parameters,
even though its error messages suggested it did. Thanks to Yann for the
patch (I also added the ability to accept parameters without requiring
them to be in a tuple). Also documented the New() function.
Diffstat (limited to 'source/blender/python/api2_2x/BezTriple.c')
-rw-r--r-- | source/blender/python/api2_2x/BezTriple.c | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/source/blender/python/api2_2x/BezTriple.c b/source/blender/python/api2_2x/BezTriple.c index 98e53d2fef8..1e835b3f316 100644 --- a/source/blender/python/api2_2x/BezTriple.c +++ b/source/blender/python/api2_2x/BezTriple.c @@ -136,43 +136,55 @@ PyTypeObject BezTriple_Type = { static PyObject *M_BezTriple_New( PyObject* self, PyObject * args ) { float numbuf[9]; - int status, length; PyObject* in_args = NULL; + int length; - if( !PyArg_ParseTuple( args, "|O", &in_args) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected sequence of 3 or 9 floats or nothing" ); + /* accept list, tuple, or 3 or 9 args (which better be floats) */ + + length = PyTuple_Size( args ); + if( length == 3 || length == 9 ) + in_args = args; + else if( !PyArg_ParseTuple( args, "|O", &in_args) ) + goto TypeError; if( !in_args ) { numbuf[0] = 0.0f; numbuf[1] = 0.0f; numbuf[2] = 0.0f; numbuf[3] = 0.0f; numbuf[4] = 0.0f; numbuf[5] = 0.0f; numbuf[6] = 0.0f; numbuf[7] = 0.0f; numbuf[8] = 0.0f; } else { + int i, length; if( !PySequence_Check( in_args ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected sequence of 3 or 9 floats or nothing" ); - + goto TypeError; + length = PySequence_Length( in_args ); - if( length == 9 ) - status = PyArg_ParseTuple( in_args, "fffffffff", - &numbuf[0], &numbuf[1], &numbuf[2], - &numbuf[3], &numbuf[4], &numbuf[5], - &numbuf[6], &numbuf[7], &numbuf[8]); - else if( length == 3 ) { - status = PyArg_ParseTuple( in_args, "fff", - &numbuf[0], &numbuf[1], &numbuf[2]); + if( length != 9 && length != 3 ) + goto TypeError; + + for(i=0; i<length; i++) { + PyObject *item, *pyfloat; + item=PySequence_ITEM(in_args, i); + if( !item ) + goto TypeError; + pyfloat=PyNumber_Float(item); + Py_DECREF(item); + if( !pyfloat ) + goto TypeError; + numbuf[i]=PyFloat_AS_DOUBLE(pyfloat); + Py_DECREF(pyfloat); + } + + if( length == 3 ) { numbuf[3] = numbuf[0]; numbuf[6] = numbuf[0]; numbuf[4] = numbuf[1]; numbuf[7] = numbuf[1]; numbuf[5] = numbuf[2]; numbuf[8] = numbuf[2]; - } else - return EXPP_ReturnPyObjError( PyExc_TypeError, - "wrong number of points" ); - if( !status ) - return EXPP_ReturnPyObjError( PyExc_AttributeError, - "sequence item not number"); + } } return newBezTriple( numbuf ); + +TypeError: + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected sequence of 3 or 9 floats or nothing" ); } /**************************************************************************** |