diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-26 14:33:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-26 14:33:57 +0400 |
commit | 0e6f8e3e25d9c48501c12cdb56bc78868b568ff5 (patch) | |
tree | 8633e1f31c844764a475d403a6d976e6c691dd22 /source/blender/python | |
parent | 6cc79fc3d0c55294d5e47642aae75348922d59c2 (diff) |
fix for crash when a python operator or render engine was freed in the C code and then referenced from python.
now further access in python gives an exception at the line when the freed data is accessed.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_extern.h | 1 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 12 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 1 |
4 files changed, 15 insertions, 3 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 83a40ecc068..53bd128562a 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -80,6 +80,7 @@ int BPY_button_exec(struct bContext *C, const char *expr, double *value, const int BPY_string_exec(struct bContext *C, const char *expr); void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */ +void BPY_RNA_DECREF_INVALIDATE(void *pyob_ptr); int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result); void BPY_context_set(struct bContext *C); void BPY_context_update(struct bContext *C); diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index f6ab100ca1a..39621fcf390 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -510,6 +510,18 @@ void BPY_DECREF(void *pyob_ptr) PyGILState_Release(gilstate); } +void BPY_RNA_DECREF_INVALIDATE(void *pyob_ptr) +{ + PyGILState_STATE gilstate = PyGILState_Ensure(); + const int do_invalidate = (Py_REFCNT((PyObject *)pyob_ptr) > 1); + Py_DECREF((PyObject *)pyob_ptr); + if (do_invalidate) { + pyrna_invalidate(pyob_ptr); + } + PyGILState_Release(gilstate); +} + + /* return -1 on error, else 0 */ int BPY_button_exec(bContext *C, const char *expr, double *value, const short verbose) { diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 122cc76a3f2..170eeb9e2af 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -119,13 +119,11 @@ int pyrna_prop_validity_check(BPy_PropertyRNA *self) return -1; } -#if defined(USE_PYRNA_INVALIDATE_GC) || defined(USE_PYRNA_INVALIDATE_WEAKREF) -static void pyrna_invalidate(BPy_DummyPointerRNA *self) +void pyrna_invalidate(BPy_DummyPointerRNA *self) { self->ptr.type = NULL; /* this is checked for validity */ self->ptr.id.data = NULL; /* should not be needed but prevent bad pointer access, just in case */ } -#endif #ifdef USE_PYRNA_INVALIDATE_GC #define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g) + 1)) diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 1fb4b116872..880ef4c2185 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -207,6 +207,7 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) int pyrna_write_check(void); void pyrna_write_set(int val); +void pyrna_invalidate(BPy_DummyPointerRNA *self); int pyrna_struct_validity_check(BPy_StructRNA *pysrna); int pyrna_prop_validity_check(BPy_PropertyRNA *self); |