Kaydet (Commit) a7604bf1 authored tarafından Nicholas Bastin's avatar Nicholas Bastin

Moved tracebackobject to traceback.h, Closes SF Bug #497067

üst 8183fa46
...@@ -5,9 +5,17 @@ ...@@ -5,9 +5,17 @@
extern "C" { extern "C" {
#endif #endif
struct _frame;
/* Traceback interface */ /* Traceback interface */
struct _frame; typedef struct _traceback {
PyObject_HEAD
struct _traceback *tb_next;
struct _frame *tb_frame;
int tb_lasti;
int tb_lineno;
} PyTracebackObject;
PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *); PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);
PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
......
...@@ -12,6 +12,8 @@ What's New in Python 2.4 alpha 1? ...@@ -12,6 +12,8 @@ What's New in Python 2.4 alpha 1?
Core and builtins Core and builtins
----------------- -----------------
- Moved tracebackobject into traceback.h and renamed to PyTracebackObject
- Optimized the byte coding for multiple assignments like "a,b=b,a" and - Optimized the byte coding for multiple assignments like "a,b=b,a" and
"a,b,c=1,2,3". Improves their speed by 25% to 30%. "a,b,c=1,2,3". Improves their speed by 25% to 30%.
......
...@@ -7,16 +7,9 @@ ...@@ -7,16 +7,9 @@
#include "frameobject.h" #include "frameobject.h"
#include "structmember.h" #include "structmember.h"
#include "osdefs.h" #include "osdefs.h"
#include "traceback.h"
typedef struct _tracebackobject { #define OFF(x) offsetof(PyTracebackObject, x)
PyObject_HEAD
struct _tracebackobject *tb_next;
PyFrameObject *tb_frame;
int tb_lasti;
int tb_lineno;
} tracebackobject;
#define OFF(x) offsetof(tracebackobject, x)
static struct memberlist tb_memberlist[] = { static struct memberlist tb_memberlist[] = {
{"tb_next", T_OBJECT, OFF(tb_next)}, {"tb_next", T_OBJECT, OFF(tb_next)},
...@@ -27,13 +20,13 @@ static struct memberlist tb_memberlist[] = { ...@@ -27,13 +20,13 @@ static struct memberlist tb_memberlist[] = {
}; };
static PyObject * static PyObject *
tb_getattr(tracebackobject *tb, char *name) tb_getattr(PyTracebackObject *tb, char *name)
{ {
return PyMember_Get((char *)tb, tb_memberlist, name); return PyMember_Get((char *)tb, tb_memberlist, name);
} }
static void static void
tb_dealloc(tracebackobject *tb) tb_dealloc(PyTracebackObject *tb)
{ {
PyObject_GC_UnTrack(tb); PyObject_GC_UnTrack(tb);
Py_TRASHCAN_SAFE_BEGIN(tb) Py_TRASHCAN_SAFE_BEGIN(tb)
...@@ -44,7 +37,7 @@ tb_dealloc(tracebackobject *tb) ...@@ -44,7 +37,7 @@ tb_dealloc(tracebackobject *tb)
} }
static int static int
tb_traverse(tracebackobject *tb, visitproc visit, void *arg) tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)
{ {
int err = 0; int err = 0;
if (tb->tb_next) { if (tb->tb_next) {
...@@ -58,7 +51,7 @@ tb_traverse(tracebackobject *tb, visitproc visit, void *arg) ...@@ -58,7 +51,7 @@ tb_traverse(tracebackobject *tb, visitproc visit, void *arg)
} }
static void static void
tb_clear(tracebackobject *tb) tb_clear(PyTracebackObject *tb)
{ {
Py_XDECREF(tb->tb_next); Py_XDECREF(tb->tb_next);
Py_XDECREF(tb->tb_frame); Py_XDECREF(tb->tb_frame);
...@@ -70,7 +63,7 @@ PyTypeObject PyTraceBack_Type = { ...@@ -70,7 +63,7 @@ PyTypeObject PyTraceBack_Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, 0,
"traceback", "traceback",
sizeof(tracebackobject), sizeof(PyTracebackObject),
0, 0,
(destructor)tb_dealloc, /*tp_dealloc*/ (destructor)tb_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
...@@ -102,16 +95,16 @@ PyTypeObject PyTraceBack_Type = { ...@@ -102,16 +95,16 @@ PyTypeObject PyTraceBack_Type = {
0, /* tp_dict */ 0, /* tp_dict */
}; };
static tracebackobject * static PyTracebackObject *
newtracebackobject(tracebackobject *next, PyFrameObject *frame) newtracebackobject(PyTracebackObject *next, PyFrameObject *frame)
{ {
tracebackobject *tb; PyTracebackObject *tb;
if ((next != NULL && !PyTraceBack_Check(next)) || if ((next != NULL && !PyTraceBack_Check(next)) ||
frame == NULL || !PyFrame_Check(frame)) { frame == NULL || !PyFrame_Check(frame)) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return NULL; return NULL;
} }
tb = PyObject_GC_New(tracebackobject, &PyTraceBack_Type); tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
if (tb != NULL) { if (tb != NULL) {
Py_XINCREF(next); Py_XINCREF(next);
tb->tb_next = next; tb->tb_next = next;
...@@ -129,8 +122,8 @@ int ...@@ -129,8 +122,8 @@ int
PyTraceBack_Here(PyFrameObject *frame) PyTraceBack_Here(PyFrameObject *frame)
{ {
PyThreadState *tstate = frame->f_tstate; PyThreadState *tstate = frame->f_tstate;
tracebackobject *oldtb = (tracebackobject *) tstate->curexc_traceback; PyTracebackObject *oldtb = (PyTracebackObject *) tstate->curexc_traceback;
tracebackobject *tb = newtracebackobject(oldtb, frame); PyTracebackObject *tb = newtracebackobject(oldtb, frame);
if (tb == NULL) if (tb == NULL)
return -1; return -1;
tstate->curexc_traceback = (PyObject *)tb; tstate->curexc_traceback = (PyObject *)tb;
...@@ -222,11 +215,11 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name) ...@@ -222,11 +215,11 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
} }
static int static int
tb_printinternal(tracebackobject *tb, PyObject *f, int limit) tb_printinternal(PyTracebackObject *tb, PyObject *f, int limit)
{ {
int err = 0; int err = 0;
int depth = 0; int depth = 0;
tracebackobject *tb1 = tb; PyTracebackObject *tb1 = tb;
while (tb1 != NULL) { while (tb1 != NULL) {
depth++; depth++;
tb1 = tb1->tb_next; tb1 = tb1->tb_next;
...@@ -267,6 +260,6 @@ PyTraceBack_Print(PyObject *v, PyObject *f) ...@@ -267,6 +260,6 @@ PyTraceBack_Print(PyObject *v, PyObject *f)
} }
err = PyFile_WriteString("Traceback (most recent call last):\n", f); err = PyFile_WriteString("Traceback (most recent call last):\n", f);
if (!err) if (!err)
err = tb_printinternal((tracebackobject *)v, f, limit); err = tb_printinternal((PyTracebackObject *)v, f, limit);
return err; return err;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment