fix strange errors when setting attributes on tracebacks #4034

This commit is contained in:
Benjamin Peterson 2009-03-18 20:52:15 +00:00
parent 7c33bd5ecb
commit 6ffe852f90
4 changed files with 22 additions and 23 deletions

View File

@ -111,14 +111,6 @@ def test():
os.unlink(os.path.join(testdir, f))
os.rmdir(testdir)
def test_members(self):
# Covers Python/structmember.c::listmembers()
try:
1/0
except:
import sys
sys.exc_traceback.__members__
def test_base_exception(self):
# Test that exceptions derived from BaseException are formatted right
e = KeyboardInterrupt()

View File

@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
Core and Builtins
-----------------
- Issue #4034: Fix weird attribute error messages of the traceback object. (As a
result traceback.__members__ no longer exists.)
- Issue #4474: PyUnicode_FromWideChar now converts characters outside
the BMP to surrogate pairs, on systems with sizeof(wchar_t) == 4
and sizeof(Py_UNICODE) == 2.

View File

@ -604,7 +604,17 @@ static PyObject *builtin_object;
int _PyFrame_Init()
{
builtin_object = PyString_InternFromString("__builtins__");
return (builtin_object != NULL);
if (builtin_object == NULL)
return 0;
/*
Traceback objects are not created the normal way (through calling the
type), so PyType_Ready has to be called here.
*/
if (PyType_Ready(&PyTraceBack_Type)) {
Py_DECREF(builtin_object);
return 0;
}
return 1;
}
PyFrameObject *

View File

@ -11,20 +11,14 @@
#define OFF(x) offsetof(PyTracebackObject, x)
static struct memberlist tb_memberlist[] = {
{"tb_next", T_OBJECT, OFF(tb_next)},
{"tb_frame", T_OBJECT, OFF(tb_frame)},
{"tb_lasti", T_INT, OFF(tb_lasti)},
{"tb_lineno", T_INT, OFF(tb_lineno)},
static PyMemberDef tb_memberlist[] = {
{"tb_next", T_OBJECT, OFF(tb_next), READONLY},
{"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
{"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
{"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
{NULL} /* Sentinel */
};
static PyObject *
tb_getattr(PyTracebackObject *tb, char *name)
{
return PyMember_Get((char *)tb, tb_memberlist, name);
}
static void
tb_dealloc(PyTracebackObject *tb)
{
@ -58,7 +52,7 @@ PyTypeObject PyTraceBack_Type = {
0,
(destructor)tb_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)tb_getattr, /*tp_getattr*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@ -80,8 +74,8 @@ PyTypeObject PyTraceBack_Type = {
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
tb_memberlist, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
};