[PATCH] Add isys.traceback(), which generates a traceback with no exception.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux