From 290ae52d81f0d46a5f05f2613c641acf7877e689 Mon Sep 17 00:00:00 2001 From: Toni Alatalo Date: Wed, 14 Sep 2005 10:53:51 +0000 Subject: [PATCH] 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). --- source/blender/python/api2_2x/BezTriple.c | 47 ++++++++++++++--------- source/blender/python/api2_2x/CurNurb.c | 6 ++- 2 files changed, 33 insertions(+), 20 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"); + 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]); - numbuf[i] = (float) PyFloat_AsDouble( pyo ); - Py_DECREF( pyo ); /* from GetItem() */ - } + 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; } diff --git a/source/blender/python/api2_2x/CurNurb.c b/source/blender/python/api2_2x/CurNurb.c index 5a86b50fd8d..9704c343b27 100644 --- a/source/blender/python/api2_2x/CurNurb.c +++ b/source/blender/python/api2_2x/CurNurb.c @@ -498,9 +498,11 @@ PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * args ) ( PyExc_MemoryError, "allocation failed" ) ); /* copy old points to new */ - memmove( nurb->bezt, tmp, sizeof( BezTriple ) * npoints ); - if( tmp ) + if( tmp ) { + memmove( nurb->bezt, tmp, sizeof( BezTriple ) * npoints ); MEM_freeN( tmp ); + } + nurb->pntsu++; /* add new point to end of list */ memcpy( nurb->bezt + npoints,