followup to vector memory leak fixes:

fix for problems with NMesh vertices.
  plug some more leaks in matrix module.
  new vector method newVectorProxy().

In BPy-Land, we have overloaded the meaning of our Vector
type.  One use is for vectors in the traditional mathmatical
sense.  The other legacy use is as a proxy for Blender data.
The recent memory leak fixed have lead to the Vector type
behaving as mathematical vectors.

However, the NMesh module is still using Vector types as a
proxy to manipulate NMVert data.  To support this usage, in
the vector module there is a new factory method
newVectorProxy().  This creates a Vector that references
memory outside the Vector.  Vectors created by
newVectorProxy() do NOT free their referenced memory.  The
newVectorProxy() is used only in bpy code and is not exposed
thru the scripting interface.

Anyone using newVectorProxy() must be aware of object
lifetime and scoping issues because the returned Vector
holds a pointer to memory it does not own.  This works in
the NMVert case since we are referencing memory belonging to
the NMVert object via an NMVert method.
This commit is contained in:
Stephen Swaney
2004-10-14 17:35:16 +00:00
parent 6fbd4e3e1f
commit 7dda27fcd7
5 changed files with 53 additions and 13 deletions

View File

@@ -262,7 +262,8 @@ PyObject *Matrix_Resize4x4( MatrixObject * self )
PyObject *Matrix_TranslationPart( MatrixObject * self )
{
float *vec;
float *vec = NULL;
PyObject *retval;
if( self->colSize < 3 ) {
return EXPP_ReturnPyObjError( PyExc_AttributeError,
@@ -282,7 +283,9 @@ PyObject *Matrix_TranslationPart( MatrixObject * self )
vec[2] = self->matrix[3][2];
}
return ( PyObject * ) newVectorObject( vec, 3 );
retval = ( PyObject * ) newVectorObject( vec, 3 );
PyMem_Free( vec );
return retval;
}
PyObject *Matrix_RotationPart( MatrixObject * self )
@@ -556,7 +559,8 @@ static PyObject *Matrix_repr( MatrixObject * self )
//compatability
static PyObject *Matrix_item( MatrixObject * self, int i )
{
float *vec;
float *vec = NULL;
PyObject *retval;
int x;
if( i < 0 || i >= self->rowSize )
@@ -572,7 +576,9 @@ static PyObject *Matrix_item( MatrixObject * self, int i )
vec[x] = self->matrix[i][x];
}
return ( PyObject * ) newVectorObject( vec, self->colSize );
retval =( PyObject * ) newVectorObject( vec, self->colSize );
PyMem_Free( vec );
return retval;
}
static PyObject *Matrix_slice( MatrixObject * self, int begin, int end )