diff options
author | Toni Alatalo <antont@kyperjokki.fi> | 2005-09-14 14:53:51 +0400 |
---|---|---|
committer | Toni Alatalo <antont@kyperjokki.fi> | 2005-09-14 14:53:51 +0400 |
commit | 290ae52d81f0d46a5f05f2613c641acf7877e689 (patch) | |
tree | 43516091ba63c23efee2d133601c8b1aea1f2e2f /source/blender/python/api2_2x/BezTriple.c | |
parent | 1b4f29353fa4c7b223b1c86244ec27ec69733a37 (diff) |
Memory management flag to behave better, as hinted by Ken Hughes.
Still not good, i.e. getting these when quitting: Error Totblock: 4
new bpytriple len: 60 0x8889bdc ... 'cause nothing frees them..
Changed the loop that parsed input args to PyArg_ParseTuple to have
support for passing ints from Python too as the floats that are the
coordinates. Didn't find PyInt_AsFloat and figured that this is an ok
way anyhow.
Changed the default handle mode from AUTO to ALIGN, which is the same
as in UI and more useful at least for me.
Little sanifying in CurNurb (this was done with Ton).
Diffstat (limited to 'source/blender/python/api2_2x/BezTriple.c')
-rw-r--r-- | source/blender/python/api2_2x/BezTriple.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/source/blender/python/api2_2x/BezTriple.c b/source/blender/python/api2_2x/BezTriple.c index 1fd736a1bc6..3cdce19ab9c 100644 --- a/source/blender/python/api2_2x/BezTriple.c +++ b/source/blender/python/api2_2x/BezTriple.c @@ -440,6 +440,7 @@ PyObject *newBezTriple( PyObject *args) BPy_BezTriple *pybez = NULL; int length; float numbuf[9]; + int status; /* check input args: sequence of nine floats - x,y,z for h1, pt, h2 @@ -459,23 +460,32 @@ PyObject *newBezTriple( PyObject *args) "wrong number of points"); { int i; - PyObject *pyo; - for( i = 0; i < length; i++) { - pyo = PySequence_GetItem( args, i ); - if( !pyo ) - return EXPP_ReturnPyObjError - ( PyExc_AttributeError, - "wrong number of points"); - if( !PyFloat_Check( pyo )) - return EXPP_ReturnPyObjError - ( PyExc_AttributeError, - "sequence item not number"); - - numbuf[i] = (float) PyFloat_AsDouble( pyo ); - Py_DECREF( pyo ); /* from GetItem() */ - } + if (length == 9) + status = PyArg_ParseTuple( 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( args, "fff", + &numbuf[0], + &numbuf[1], + &numbuf[2]); + else + return EXPP_ReturnPyObjError + ( PyExc_AttributeError, + "wrong number of points"); + if ( !status ) + return EXPP_ReturnPyObjError + ( PyExc_AttributeError, + "sequence item not number"); } - /* create our bpy object */ pybez = ( BPy_BezTriple* ) PyObject_New( BPy_BezTriple, @@ -486,7 +496,8 @@ PyObject *newBezTriple( PyObject *args) pybez->beztriple = MEM_callocN( sizeof( BezTriple ), "new bpytriple"); /* check malloc */ - pybez->own_memory = 1; /* we own it. must free later */ + pybez->own_memory = 0; /* we own it. must free later */ + /* set to 0 for creating to work. how should freeing be done? */ switch( length ) { @@ -518,8 +529,8 @@ PyObject *newBezTriple( PyObject *args) } - pybez->beztriple->h1 = HD_AUTO; - pybez->beztriple->h2 = HD_AUTO; + pybez->beztriple->h1 = HD_ALIGN; + pybez->beztriple->h2 = HD_ALIGN; return ( PyObject* ) pybez; } |