Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-26 14:33:57 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-26 14:33:57 +0400
commit0e6f8e3e25d9c48501c12cdb56bc78868b568ff5 (patch)
tree8633e1f31c844764a475d403a6d976e6c691dd22 /source
parent6cc79fc3d0c55294d5e47642aae75348922d59c2 (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')
-rw-r--r--source/blender/python/BPY_extern.h1
-rw-r--r--source/blender/python/intern/bpy_interface.c12
-rw-r--r--source/blender/python/intern/bpy_rna.c4
-rw-r--r--source/blender/python/intern/bpy_rna.h1
-rw-r--r--source/blender/render/intern/source/external_engine.c2
-rw-r--r--source/blender/windowmanager/intern/wm.c2
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