diff options
author | Stephen Swaney <sswaney@centurytel.net> | 2004-10-14 21:35:16 +0400 |
---|---|---|
committer | Stephen Swaney <sswaney@centurytel.net> | 2004-10-14 21:35:16 +0400 |
commit | 7dda27fcd7266befeb9c8f191726154831438b59 (patch) | |
tree | 79e00f3b1cece2fd594ba7b3a4b87c0cfb962445 /source/blender/python/api2_2x/vector.c | |
parent | 6fbd4e3e1f5169aed15856f7b1c412176035b236 (diff) |
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.
Diffstat (limited to 'source/blender/python/api2_2x/vector.c')
-rw-r--r-- | source/blender/python/api2_2x/vector.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/source/blender/python/api2_2x/vector.c b/source/blender/python/api2_2x/vector.c index 83da130b8fd..ba527352786 100644 --- a/source/blender/python/api2_2x/vector.c +++ b/source/blender/python/api2_2x/vector.c @@ -222,8 +222,8 @@ static PyObject *Vector_getattr( VectorObject * self, char *name ) self->vec[1] * self->vec[1] ) ); } else - EXPP_ReturnPyObjError( PyExc_AttributeError, - "can only return the length of a 2D ,3D or 4D vector\n" ); + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "can only return the length of a 2D ,3D or 4D vector\n" ); } return Py_FindMethod( Vector_methods, ( PyObject * ) self, name ); @@ -696,3 +696,32 @@ PyObject *newVectorObject( float *vec, int size ) return ( PyObject * ) self; } + + +/* + create a Vector that is a proxy for blender data. + we do not own this data, we NEVER free it. + Note: users must deal with bad pointer issue +*/ + +PyObject *newVectorProxy( float *vec, int size) +{ + VectorObject *proxy; + int x; + + proxy = PyObject_NEW( VectorObject, &vector_Type ); + + proxy->delete_pymem = 0; /* must NOT free this alloc later */ + + if( !vec || size < 1 ) { + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "cannot creat zero length vector proxy" ); + } + + proxy->vec = vec; + proxy->size = size; + proxy->flag = 0; + + return ( PyObject * ) proxy; +} + |