[Bf-python] Water-tight Thin wrapped data

Campbell Barton cbarton at metavr.com
Fri Feb 2 09:25:23 CET 2007


Hi, one major problem with the existihng Python API is that its fairly 
easy for thin wrapped data to become invalid (free'd from Blender) and 
wrighting to it can corrupt memory.

A simple example is if you access an objects matrix.
then remove the object. (and the python object is free'd)

Writing to the matrix will access a pointer thats invalid. since the 
matrix get's free'd when the object is.


Theres more cases where this can happen too.

Iv been thinking of ways the API can be changed so this never happens.


A simple solution would be to maintain a list of dependancies.

Each PyObject would need a new entry in the struct for the "origin"

you could keep a listbase of python objects and when a blender object is 
Free'd, that list would be searched and any python objects would have 
their pointers set to NULL. - That way future access to that data would 
raise a python error.

I dont like the thrashing this might cause but its probably better then 
python accessing invalid data.


Another solution is to have blender data be able to reference its 
PyObjects but I think that people wont like that.


Any thoughts as to the best way to make it so thin wrapped data works 
better?






More information about the Bf-python mailing list