diff options
-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 | ||||
-rw-r--r-- | source/blender/render/intern/source/external_engine.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 2 |
6 files changed, 17 insertions, 5 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); diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 636b3205b23..9647b100d2d 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -138,7 +138,7 @@ void RE_engine_free(RenderEngine *engine) { #ifdef WITH_PYTHON if (engine->py_instance) { - BPY_DECREF(engine->py_instance); + BPY_RNA_DECREF_INVALIDATE(engine->py_instance); } #endif diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index a34d294461c..fa00ec63b31 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -78,7 +78,7 @@ void WM_operator_free(wmOperator *op) if (op->py_instance) { /* do this first in case there are any __del__ functions or * similar that use properties */ - BPY_DECREF(op->py_instance); + BPY_RNA_DECREF_INVALIDATE(op->py_instance); } #endif |