[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[PATCH] Add isys.traceback(), which generates a traceback with no exception.
- From: "pjones" <pjones redhat com>
- To: anaconda-devel-list redhat com
- Cc:
- Subject: [PATCH] Add isys.traceback(), which generates a traceback with no exception.
- Date: Wed, 3 Dec 2008 14:40:44 -0500
Chris asked for this to help with his traceback handling fixups. It
generates a traceback object at the current location, but doesn't raise
an exception.
---
isys/isys.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/isys/isys.c b/isys/isys.c
index b3466ab..3c28ffd 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -132,6 +132,7 @@ static PyObject * doGetBlkidData(PyObject * s, PyObject * args);
static PyObject * doGetDeviceByToken(PyObject *s, PyObject *args);
static PyObject * doIsCapsLockEnabled(PyObject * s, PyObject * args);
static PyObject * doGetLinkStatus(PyObject * s, PyObject * args);
+static PyObject * doTraceback(PyObject *self, PyObject *args, PyObject *kwds);
static PyMethodDef isysModuleMethods[] = {
{ "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -179,6 +180,7 @@ static PyMethodDef isysModuleMethods[] = {
{ "getdevicebytoken", (PyCFunction) doGetDeviceByToken, METH_VARARGS, NULL },
{ "isCapsLockEnabled", (PyCFunction) doIsCapsLockEnabled, METH_VARARGS, NULL },
{ "getLinkStatus", (PyCFunction) doGetLinkStatus, METH_VARARGS, NULL },
+ { "traceback", (PyCFunction) doTraceback, METH_VARARGS|METH_KWARGS, NULL },
{ NULL, NULL, 0, NULL }
} ;
@@ -932,4 +934,38 @@ static PyObject * doGetLinkStatus(PyObject * s, PyObject * args) {
return PyBool_FromLong(0);
}
+#include "frameobject.h"
+
+static PyObject *
+doTraceback(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ char *kwlist[] = {"frame", NULL};
+ PyFrameObject *frame = NULL;
+ PyThreadState *tstate;
+ PyTracebackObject *oldtb;
+ PyTracebackObject *tb;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:traceback",
+ kwlist, &frame))
+ return NULL;
+
+ tstate = PyThreadState_GET();
+ oldtb = (PyTracebackObject *)tstate->curexc_traceback;
+
+ /* this has side effects we have to undo afterwards. */
+ if (PyTraceBack_Here(frame) < 0)
+ return NULL;
+
+ tb = (PyTracebackObject *)tstate->curexc_traceback;
+
+ /* PyTraceBack_Here makes the new traceback be the "current"
+ * traceback, which isn't really desired */
+ tstate->curexc_traceback = (PyObject *)oldtb;
+
+ /* PyTraceBack_Here adds the current traceback as this traceback's
+ * "next" traceback, which we really don't want. */
+ tb->tb_next = NULL;
+ return (PyObject *)tb;
+}
+
/* vim:set shiftwidth=4 softtabstop=4: */
--
1.6.0.1
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]