diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-01 12:02:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-01 12:02:49 +0300 |
commit | 549b190566c2d340ba9991d3c2cdfa7e12d18b9b (patch) | |
tree | e3636b4631c4f8a38af7d882240ab1d0e2323372 /source/blender/python | |
parent | c6d43a02cb30aafaa594c8dba0b540f8c54299b8 (diff) |
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.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 33 |
1 files changed, 21 insertions, 12 deletions
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); |