Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Also make sure that every exception class has __module__ set to
'exceptions'.
 (backport)
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index ec8895c..af07aa8 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -185,15 +185,6 @@
 
     def testAttributes(self):
         # test that exception attributes are happy
-        try:
-            str(u'Hello \u00E1')
-        except Exception, e:
-            sampleUnicodeEncodeError = e
-
-        try:
-            unicode('\xff')
-        except Exception, e:
-            sampleUnicodeDecodeError = e
 
         exceptionList = [
             (BaseException, (), {'message' : '', 'args' : ()}),
@@ -236,16 +227,16 @@
                  'print_file_and_line' : None, 'msg' : 'msgStr',
                  'filename' : None, 'lineno' : None, 'offset' : None}),
             (UnicodeError, (), {'message' : '', 'args' : (),}),
-            (sampleUnicodeEncodeError,
-                {'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7,
-                                           'ordinal not in range(128)'),
-                 'encoding' : 'ascii', 'object' : u'Hello \xe1',
-                 'start' : 6, 'reason' : 'ordinal not in range(128)'}),
-            (sampleUnicodeDecodeError,
+            (UnicodeEncodeError, ('ascii', u'a', 0, 1, 'ordinal not in range'),
+                {'message' : '', 'args' : ('ascii', u'a', 0, 1,
+                                           'ordinal not in range'),
+                 'encoding' : 'ascii', 'object' : u'a',
+                 'start' : 0, 'reason' : 'ordinal not in range'}),
+            (UnicodeDecodeError, ('ascii', '\xff', 0, 1, 'ordinal not in range'),
                 {'message' : '', 'args' : ('ascii', '\xff', 0, 1,
-                                           'ordinal not in range(128)'),
+                                           'ordinal not in range'),
                  'encoding' : 'ascii', 'object' : '\xff',
-                 'start' : 0, 'reason' : 'ordinal not in range(128)'}),
+                 'start' : 0, 'reason' : 'ordinal not in range'}),
             (UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"),
                 {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
                  'object' : u'\u3042', 'reason' : 'ouch',
@@ -261,18 +252,14 @@
         except NameError:
             pass
 
-        for args in exceptionList:
-            expected = args[-1]
+        for exc, args, expected in exceptionList:
             try:
-                exc = args[0]
-                if len(args) == 2:
-                    raise exc
-                else:
-                    raise exc(*args[1])
+                raise exc(*args)
             except BaseException, e:
-                if (e is not exc and     # needed for sampleUnicode errors
-                        type(e) is not exc):
+                if type(e) is not exc:
                     raise
+                # Verify module name
+                self.assertEquals(type(e).__module__, 'exceptions')
                 # Verify no ref leaks in Exc_str()
                 s = str(e)
                 for checkArgName in expected:
diff --git a/Misc/NEWS b/Misc/NEWS
index ceb26a1..2df8b0d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,10 @@
 Core and builtins
 -----------------
 
+- Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
+  Also make sure that every exception class has __module__ set to
+  'exceptions'.
+
 - Bug #1550983: emit better error messages for erroneous relative
   imports (if not in package and if beyond toplevel package).
 
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index c3ead69..cdf2609 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -81,6 +81,7 @@
 static void
 BaseException_dealloc(PyBaseExceptionObject *self)
 {
+    _PyObject_GC_UNTRACK(self);
     BaseException_clear(self);
     self->ob_type->tp_free((PyObject *)self);
 }
@@ -456,6 +457,7 @@
 static void
 SystemExit_dealloc(PySystemExitObject *self)
 {
+    _PyObject_GC_UNTRACK(self);
     SystemExit_clear(self);
     self->ob_type->tp_free((PyObject *)self);
 }
@@ -562,6 +564,7 @@
 static void
 EnvironmentError_dealloc(PyEnvironmentErrorObject *self)
 {
+    _PyObject_GC_UNTRACK(self);
     EnvironmentError_clear(self);
     self->ob_type->tp_free((PyObject *)self);
 }
@@ -760,6 +763,7 @@
 static void
 WindowsError_dealloc(PyWindowsErrorObject *self)
 {
+    _PyObject_GC_UNTRACK(self);
     WindowsError_clear(self);
     self->ob_type->tp_free((PyObject *)self);
 }
@@ -1035,6 +1039,7 @@
 static void
 SyntaxError_dealloc(PySyntaxErrorObject *self)
 {
+    _PyObject_GC_UNTRACK(self);
     SyntaxError_clear(self);
     self->ob_type->tp_free((PyObject *)self);
 }
@@ -1551,6 +1556,7 @@
 static void
 UnicodeError_dealloc(PyUnicodeErrorObject *self)
 {
+    _PyObject_GC_UNTRACK(self);
     UnicodeError_clear(self);
     self->ob_type->tp_free((PyObject *)self);
 }
@@ -1637,7 +1643,7 @@
 static PyTypeObject _PyExc_UnicodeEncodeError = {
     PyObject_HEAD_INIT(NULL)
     0,
-    "UnicodeEncodeError",
+    EXC_MODULE_NAME "UnicodeEncodeError",
     sizeof(PyUnicodeErrorObject), 0,
     (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     (reprfunc)UnicodeEncodeError_str, 0, 0, 0,
@@ -1812,7 +1818,7 @@
     (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     (reprfunc)UnicodeTranslateError_str, 0, 0, 0,
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
-    PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse,
+    PyDoc_STR("Unicode translation error."), (traverseproc)UnicodeError_traverse,
     (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,
     0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),
     (initproc)UnicodeTranslateError_init, 0, BaseException_new,