Py/RNA Stability: don't allow python to reference freed ID's and crash.

Second method for not having python crash blender on invalid access (ifdef'd out ATM, so no functional change).

This uses a weakref list per ID, and invalidates all members of that list when the ID is freed.
the list is not stores in the ID pointer but using a hash table since storing python in DNA data is not acceptable.

This is more correct then the previous method but shows down execution of scripts significantly since its always adding and removing from lists when data is created and freed.
This commit is contained in:
2011-03-01 14:53:26 +00:00
parent f0f639f8b8
commit 623822626a
2 changed files with 163 additions and 6 deletions

View File

@@ -44,12 +44,25 @@ extern PyTypeObject pyrna_prop_collection_Type;
#define BPy_PropertyRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_prop_Type))
#define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type)
/* method to invalidate removed py data, XXX, slow to remove objects, otherwise no overhead */
// #define USE_PYRNA_INVALIDATE_GC
/* play it safe and keep optional for now, need to test further now this affects looping on 10000's of verts for eg. */
// #define USE_WEAKREFS
/* method to invalidate removed py data, XXX, slow to remove objects, otherwise no overhead */
//#define USE_PYRNA_INVALIDATE_GC
/* different method */
//#define USE_PYRNA_INVALIDATE_WEAKREF
/* sanity checks on above defs */
#if defined(USE_PYRNA_INVALIDATE_WEAKREF) && !defined(USE_WEAKREFS)
#define USE_WEAKREFS
#endif
#if defined(USE_PYRNA_INVALIDATE_GC) && defined(USE_PYRNA_INVALIDATE_WEAKREF)
#error "Only 1 reference check method at a time!"
#endif
typedef struct {
PyObject_HEAD /* required python macro */
PointerRNA ptr;