Merged revisions 70463 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70463 | benjamin.peterson | 2009-03-18 15:52:15 -0500 (Wed, 18 Mar 2009) | 1 line

  fix strange errors when setting attributes on tracebacks #4034
........
This commit is contained in:
Benjamin Peterson 2009-03-18 21:49:29 +00:00
parent 1637a68ab5
commit 53f098cdc6
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.unlink(os.path.join(testdir, f))
os.rmdir(testdir) 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): def test_base_exception(self):
# Test that exceptions derived from BaseException are formatted right # Test that exceptions derived from BaseException are formatted right
e = KeyboardInterrupt() e = KeyboardInterrupt()

View File

@ -14,6 +14,9 @@ Core and Builtins
- xrange() is now registered as a Sequence. - xrange() is now registered as a Sequence.
- Issue #4034: Fix weird attribute error messages of the traceback object. (As a
result traceback.__members__ no longer exists.)
- Issue #5247: Improve error message when unknown format codes are - Issue #5247: Improve error message when unknown format codes are
used when using str.format() with str, unicode, long, int, and used when using str.format() with str, unicode, long, int, and
float arguments. float arguments.

View File

@ -572,7 +572,17 @@ static PyObject *builtin_object;
int _PyFrame_Init() int _PyFrame_Init()
{ {
builtin_object = PyString_InternFromString("__builtins__"); 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 * PyFrameObject *

View File

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