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).
This commit is contained in:
Toni Alatalo 2005-09-14 10:53:51 +00:00
parent 1b4f29353f
commit 290ae52d81
2 changed files with 33 additions and 20 deletions

@ -440,6 +440,7 @@ PyObject *newBezTriple( PyObject *args)
BPy_BezTriple *pybez = NULL; BPy_BezTriple *pybez = NULL;
int length; int length;
float numbuf[9]; float numbuf[9];
int status;
/* /*
check input args: check input args:
sequence of nine floats - x,y,z for h1, pt, h2 sequence of nine floats - x,y,z for h1, pt, h2
@ -459,23 +460,32 @@ PyObject *newBezTriple( PyObject *args)
"wrong number of points"); "wrong number of points");
{ {
int i; int i;
PyObject *pyo; if (length == 9)
for( i = 0; i < length; i++) { status = PyArg_ParseTuple( args, "fffffffff",
pyo = PySequence_GetItem( args, i ); &numbuf[0],
if( !pyo ) &numbuf[1],
return EXPP_ReturnPyObjError &numbuf[2],
( PyExc_AttributeError, &numbuf[3],
"wrong number of points"); &numbuf[4],
if( !PyFloat_Check( pyo )) &numbuf[5],
return EXPP_ReturnPyObjError &numbuf[6],
( PyExc_AttributeError, &numbuf[7],
"sequence item not number"); &numbuf[8]);
numbuf[i] = (float) PyFloat_AsDouble( pyo ); else if (length == 3)
Py_DECREF( pyo ); /* from GetItem() */ 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 */ /* create our bpy object */
pybez = ( BPy_BezTriple* ) PyObject_New( BPy_BezTriple, pybez = ( BPy_BezTriple* ) PyObject_New( BPy_BezTriple,
@ -486,7 +496,8 @@ PyObject *newBezTriple( PyObject *args)
pybez->beztriple = MEM_callocN( sizeof( BezTriple ), "new bpytriple"); pybez->beztriple = MEM_callocN( sizeof( BezTriple ), "new bpytriple");
/* check malloc */ /* 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 ) { switch( length ) {
@ -518,8 +529,8 @@ PyObject *newBezTriple( PyObject *args)
} }
pybez->beztriple->h1 = HD_AUTO; pybez->beztriple->h1 = HD_ALIGN;
pybez->beztriple->h2 = HD_AUTO; pybez->beztriple->h2 = HD_ALIGN;
return ( PyObject* ) pybez; return ( PyObject* ) pybez;
} }

@ -498,9 +498,11 @@ PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * args )
( PyExc_MemoryError, "allocation failed" ) ); ( PyExc_MemoryError, "allocation failed" ) );
/* copy old points to new */ /* 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 ); MEM_freeN( tmp );
}
nurb->pntsu++; nurb->pntsu++;
/* add new point to end of list */ /* add new point to end of list */
memcpy( nurb->bezt + npoints, memcpy( nurb->bezt + npoints,