Blame python-2.6.6-rhythmbox-workaround.patch

c217786
diff -up Python-2.6.6/Python/import.c.rhythmbox-workaround Python-2.6.6/Python/import.c
c217786
--- Python-2.6.6/Python/import.c.rhythmbox-workaround	2011-03-21 14:27:59.149116031 -0400
c217786
+++ Python-2.6.6/Python/import.c	2011-03-21 14:57:21.929864498 -0400
c217786
@@ -2702,6 +2702,48 @@ PyImport_ReloadModule(PyObject *m)
c217786
 }
c217786
 
c217786
 
c217786
+int _Py_rhythmbox_workaround_rhbz684991 = 0;
c217786
+
c217786
+static void
c217786
+do_rhythmbox_workaround_rhbz684991(PyObject *module_name)
c217786
+{
c217786
+    /*
c217786
+      Python 2.6.5 had a PyErr_Clear() here, which was removed in 2.6.6
c217786
+      as part of r79204
c217786
+
c217786
+      Unfortunately, rhythmbox-0.12.8 has a bug which generates an
c217786
+      assertion failure, which was being masked by this call; it needs
c217786
+      the call to PyErr_Clear during the import of "gobject" to avoid
c217786
+      later crashing.
c217786
+      
c217786
+      To reinstate this behavior without patching rhythmbox, we add a
c217786
+      workaround here, calling PyErr_Clear if it looks like we're running
c217786
+      rhythmbox and are at the precise point where the call is needed.
c217786
+      
c217786
+      This is rhbz#684991
c217786
+    */
c217786
+  
c217786
+    /*  
c217786
+        _Py_rhythmbox_workaround_rhbz684991 is set by PySys_SetArgv, when
c217786
+        it is called by the exact arguments used by rhythmbox
c217786
+    */
c217786
+    if (_Py_rhythmbox_workaround_rhbz684991) {
c217786
+
c217786
+        /* The precise error that must be discarded is when
c217786
+           importing "gobject": */
c217786
+        if (PyString_CheckExact(module_name)) {
c217786
+            if (0 == strcmp(PyString_AS_STRING(module_name), "gobject")) {
c217786
+                /* Clear the bogus error: */
c217786
+                PyErr_Clear();
c217786
+
c217786
+                /* Only do it once */
c217786
+                _Py_rhythmbox_workaround_rhbz684991 = 0;
c217786
+            }
c217786
+        }
c217786
+    }
c217786
+}
c217786
+
c217786
+
c217786
 /* Higher-level import emulator which emulates the "import" statement
c217786
    more accurately -- it invokes the __import__() function from the
c217786
    builtins of the current globals.  This means that the import is
c217786
@@ -2745,6 +2787,8 @@ PyImport_Import(PyObject *module_name)
c217786
     }
c217786
     else {
c217786
         /* No globals -- use standard builtins, and fake globals */
c217786
+        do_rhythmbox_workaround_rhbz684991(module_name);
c217786
+
c217786
         builtins = PyImport_ImportModuleLevel("__builtin__",
c217786
                                               NULL, NULL, NULL, 0);
c217786
         if (builtins == NULL)
c217786
diff -up Python-2.6.6/Python/sysmodule.c.rhythmbox-workaround Python-2.6.6/Python/sysmodule.c
c217786
--- Python-2.6.6/Python/sysmodule.c.rhythmbox-workaround	2011-03-21 14:43:49.180870432 -0400
c217786
+++ Python-2.6.6/Python/sysmodule.c	2011-03-21 14:45:23.676002290 -0400
c217786
@@ -1631,9 +1631,18 @@ PySys_SetArgvEx(int argc, char **argv, i
c217786
     Py_DECREF(av);
c217786
 }
c217786
 
c217786
+extern int _Py_rhythmbox_workaround_rhbz684991;
c217786
+
c217786
 void
c217786
 PySys_SetArgv(int argc, char **argv)
c217786
 {
c217786
+    /* Detect and set up workaround for rhythmbox, used in import.c */
c217786
+    if (argc == 1) {
c217786
+        if (0 == strcmp(argv[0], "rb")) {
c217786
+            _Py_rhythmbox_workaround_rhbz684991 = 1;
c217786
+        }
c217786
+    }
c217786
+
c217786
     PySys_SetArgvEx(argc, argv, 1);
c217786
 }
c217786