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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-11-24 13:23:23 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-11-24 13:23:23 +0300
commit05f2e47ff091de670e6f871daea60276b8171724 (patch)
tree0087c00fb21ba48e3e6631d83eee6cd15578a8d7 /source/blender/python
parenta5cecd8284f0e9bdccacaa226a82f8c20d60ecf2 (diff)
bugfix [#23871] OSX panel button bug (Python Namespace issue)
This is an annoying but which isn't a problem for Python because they don't execute multiple scripts, one after another (there is one __main__ and everything else is a module). So when the __main__ module in sys.modules is overwritten, it decref's the module and clears the dictionary with _PyModule_Clear(), even though the modules dictionary is still in use. Strangely this problem only happens with Python3.1.1 and Python3.2x svn but not 3.1.2 This commit restores the namespace after _PyModule_Clear() sets all its values to None.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_interface.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index a894fa60237..7caf07a0973 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -302,7 +302,7 @@ void BPY_end_python( void )
/* Can run a file or text block */
int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struct ReportList *reports)
{
- PyObject *py_dict, *py_result= NULL;
+ PyObject *py_dict= NULL, *py_result= NULL;
PyGILState_STATE gilstate;
if (fn==NULL && text==NULL) {
@@ -373,8 +373,23 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
} else {
Py_DECREF( py_result );
}
-
- PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
+
+/* super annoying, undo _PyModule_Clear() */
+#define PYMODULE_CLEAR_WORKAROUND
+
+ if(py_dict) {
+#ifdef PYMODULE_CLEAR_WORKAROUND
+ PyObject *py_dict_back= PyDict_Copy(py_dict);
+#endif
+ /* 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_back);
+#endif
+#undef PYMODULE_CLEAR_WORKAROUND
+ }
bpy_context_clear(C, &gilstate);