From 549b190566c2d340ba9991d3c2cdfa7e12d18b9b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 1 Feb 2011 09:02:49 +0000 Subject: own fix for bug #23871 (r33277), crashes when running multiple operators in a batch script with a double free. Cant see why this happens but this different fix doesn't crash so using it instead. --- source/blender/python/intern/bpy_interface.c | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'source/blender/python') diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 38efb4523c4..444cda0cc88 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -313,6 +313,19 @@ void BPY_python_end(void) } +/* super annoying, undo _PyModule_Clear(), bug [#23871] */ +#define PYMODULE_CLEAR_WORKAROUND + +#ifdef PYMODULE_CLEAR_WORKAROUND +/* bad!, we should never do this, but currently only safe way I could find to keep namespace. + * from being cleared. - campbell */ +typedef struct { + PyObject_HEAD + PyObject *md_dict; + /* ommit other values, we only want the dict. */ +} PyModuleObject; +#endif + static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports) { PyObject *py_dict= NULL, *py_result= NULL; @@ -389,23 +402,19 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st Py_DECREF( py_result ); } -/* super annoying, undo _PyModule_Clear() */ -#define PYMODULE_CLEAR_WORKAROUND - if(py_dict) { #ifdef PYMODULE_CLEAR_WORKAROUND - PyObject *py_dict_back= PyDict_Copy(py_dict); - Py_INCREF(py_dict); + PyModuleObject *mmod= (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__"); + PyObject *dict_back = mmod->md_dict; + /* freeing the module will clear the namespace, + * gives problems running classes defined in this namespace being used later. */ + mmod->md_dict= NULL; + Py_DECREF(dict_back); #endif + +#undef PYMODULE_CLEAR_WORKAROUND /* normal */ PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None); -#ifdef PYMODULE_CLEAR_WORKAROUND - PyDict_Clear(py_dict); - PyDict_Update(py_dict, py_dict_back); - Py_DECREF(py_dict); - Py_DECREF(py_dict_back); -#endif -#undef PYMODULE_CLEAR_WORKAROUND } bpy_context_clear(C, &gilstate); -- cgit v1.2.3