[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33277] trunk/blender/source/blender/ python/intern/bpy_interface.c: bugfix [#23871] OSX panel button bug ( Python Namespace issue)
Campbell Barton
ideasman42 at gmail.com
Wed Nov 24 11:23:23 CET 2010
Revision: 33277
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33277
Author: campbellbarton
Date: 2010-11-24 11:23:23 +0100 (Wed, 24 Nov 2010)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_interface.c
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2010-11-24 09:13:59 UTC (rev 33276)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2010-11-24 10:23:23 UTC (rev 33277)
@@ -302,7 +302,7 @@
/* 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,9 +373,24 @@
} else {
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);
+#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
+ }
- PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
-
bpy_context_clear(C, &gilstate);
return py_result ? 1:0;
More information about the Bf-blender-cvs
mailing list