Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Also make sure that every exception class has __module__ set to 'exceptions'.
This commit is contained in:
parent
ca460d9722
commit
38f6237dfe
|
@ -185,15 +185,6 @@ class ExceptionTests(unittest.TestCase):
|
||||||
|
|
||||||
def testAttributes(self):
|
def testAttributes(self):
|
||||||
# test that exception attributes are happy
|
# 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 = [
|
exceptionList = [
|
||||||
(BaseException, (), {'message' : '', 'args' : ()}),
|
(BaseException, (), {'message' : '', 'args' : ()}),
|
||||||
|
@ -236,16 +227,16 @@ class ExceptionTests(unittest.TestCase):
|
||||||
'print_file_and_line' : None, 'msg' : 'msgStr',
|
'print_file_and_line' : None, 'msg' : 'msgStr',
|
||||||
'filename' : None, 'lineno' : None, 'offset' : None}),
|
'filename' : None, 'lineno' : None, 'offset' : None}),
|
||||||
(UnicodeError, (), {'message' : '', 'args' : (),}),
|
(UnicodeError, (), {'message' : '', 'args' : (),}),
|
||||||
(sampleUnicodeEncodeError,
|
(UnicodeEncodeError, ('ascii', u'a', 0, 1, 'ordinal not in range'),
|
||||||
{'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7,
|
{'message' : '', 'args' : ('ascii', u'a', 0, 1,
|
||||||
'ordinal not in range(128)'),
|
'ordinal not in range'),
|
||||||
'encoding' : 'ascii', 'object' : u'Hello \xe1',
|
'encoding' : 'ascii', 'object' : u'a',
|
||||||
'start' : 6, 'reason' : 'ordinal not in range(128)'}),
|
'start' : 0, 'reason' : 'ordinal not in range'}),
|
||||||
(sampleUnicodeDecodeError,
|
(UnicodeDecodeError, ('ascii', '\xff', 0, 1, 'ordinal not in range'),
|
||||||
{'message' : '', 'args' : ('ascii', '\xff', 0, 1,
|
{'message' : '', 'args' : ('ascii', '\xff', 0, 1,
|
||||||
'ordinal not in range(128)'),
|
'ordinal not in range'),
|
||||||
'encoding' : 'ascii', 'object' : '\xff',
|
'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"),
|
(UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"),
|
||||||
{'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
|
{'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
|
||||||
'object' : u'\u3042', 'reason' : 'ouch',
|
'object' : u'\u3042', 'reason' : 'ouch',
|
||||||
|
@ -261,18 +252,14 @@ class ExceptionTests(unittest.TestCase):
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for args in exceptionList:
|
for exc, args, expected in exceptionList:
|
||||||
expected = args[-1]
|
|
||||||
try:
|
try:
|
||||||
exc = args[0]
|
raise exc(*args)
|
||||||
if len(args) == 2:
|
|
||||||
raise exc
|
|
||||||
else:
|
|
||||||
raise exc(*args[1])
|
|
||||||
except BaseException, e:
|
except BaseException, e:
|
||||||
if (e is not exc and # needed for sampleUnicode errors
|
if type(e) is not exc:
|
||||||
type(e) is not exc):
|
|
||||||
raise
|
raise
|
||||||
|
# Verify module name
|
||||||
|
self.assertEquals(type(e).__module__, 'exceptions')
|
||||||
# Verify no ref leaks in Exc_str()
|
# Verify no ref leaks in Exc_str()
|
||||||
s = str(e)
|
s = str(e)
|
||||||
for checkArgName in expected:
|
for checkArgName in expected:
|
||||||
|
|
|
@ -81,6 +81,7 @@ BaseException_clear(PyBaseExceptionObject *self)
|
||||||
static void
|
static void
|
||||||
BaseException_dealloc(PyBaseExceptionObject *self)
|
BaseException_dealloc(PyBaseExceptionObject *self)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK(self);
|
||||||
BaseException_clear(self);
|
BaseException_clear(self);
|
||||||
self->ob_type->tp_free((PyObject *)self);
|
self->ob_type->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -456,6 +457,7 @@ SystemExit_clear(PySystemExitObject *self)
|
||||||
static void
|
static void
|
||||||
SystemExit_dealloc(PySystemExitObject *self)
|
SystemExit_dealloc(PySystemExitObject *self)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK(self);
|
||||||
SystemExit_clear(self);
|
SystemExit_clear(self);
|
||||||
self->ob_type->tp_free((PyObject *)self);
|
self->ob_type->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -562,6 +564,7 @@ EnvironmentError_clear(PyEnvironmentErrorObject *self)
|
||||||
static void
|
static void
|
||||||
EnvironmentError_dealloc(PyEnvironmentErrorObject *self)
|
EnvironmentError_dealloc(PyEnvironmentErrorObject *self)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK(self);
|
||||||
EnvironmentError_clear(self);
|
EnvironmentError_clear(self);
|
||||||
self->ob_type->tp_free((PyObject *)self);
|
self->ob_type->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -760,6 +763,7 @@ WindowsError_clear(PyWindowsErrorObject *self)
|
||||||
static void
|
static void
|
||||||
WindowsError_dealloc(PyWindowsErrorObject *self)
|
WindowsError_dealloc(PyWindowsErrorObject *self)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK(self);
|
||||||
WindowsError_clear(self);
|
WindowsError_clear(self);
|
||||||
self->ob_type->tp_free((PyObject *)self);
|
self->ob_type->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -1035,6 +1039,7 @@ SyntaxError_clear(PySyntaxErrorObject *self)
|
||||||
static void
|
static void
|
||||||
SyntaxError_dealloc(PySyntaxErrorObject *self)
|
SyntaxError_dealloc(PySyntaxErrorObject *self)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK(self);
|
||||||
SyntaxError_clear(self);
|
SyntaxError_clear(self);
|
||||||
self->ob_type->tp_free((PyObject *)self);
|
self->ob_type->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -1551,6 +1556,7 @@ UnicodeError_clear(PyUnicodeErrorObject *self)
|
||||||
static void
|
static void
|
||||||
UnicodeError_dealloc(PyUnicodeErrorObject *self)
|
UnicodeError_dealloc(PyUnicodeErrorObject *self)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK(self);
|
||||||
UnicodeError_clear(self);
|
UnicodeError_clear(self);
|
||||||
self->ob_type->tp_free((PyObject *)self);
|
self->ob_type->tp_free((PyObject *)self);
|
||||||
}
|
}
|
||||||
|
@ -1637,7 +1643,7 @@ UnicodeEncodeError_str(PyObject *self)
|
||||||
static PyTypeObject _PyExc_UnicodeEncodeError = {
|
static PyTypeObject _PyExc_UnicodeEncodeError = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0,
|
0,
|
||||||
"UnicodeEncodeError",
|
EXC_MODULE_NAME "UnicodeEncodeError",
|
||||||
sizeof(PyUnicodeErrorObject), 0,
|
sizeof(PyUnicodeErrorObject), 0,
|
||||||
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
(reprfunc)UnicodeEncodeError_str, 0, 0, 0,
|
(reprfunc)UnicodeEncodeError_str, 0, 0, 0,
|
||||||
|
@ -1812,7 +1818,7 @@ static PyTypeObject _PyExc_UnicodeTranslateError = {
|
||||||
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
(reprfunc)UnicodeTranslateError_str, 0, 0, 0,
|
(reprfunc)UnicodeTranslateError_str, 0, 0, 0,
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
|
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,
|
(inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,
|
||||||
0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),
|
0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),
|
||||||
(initproc)UnicodeTranslateError_init, 0, BaseException_new,
|
(initproc)UnicodeTranslateError_init, 0, BaseException_new,
|
||||||
|
|
Loading…
Reference in New Issue