[svn] some small code cleanups in jinja
[jinja2.git] / jinja / _debugger.c
1 /**
2  * Jinja Extended Debugger
3  * ~~~~~~~~~~~~~~~~~~~~~~~
4  *
5  * this module allows the jinja debugger to set the tb_next flag
6  * on traceback objects. This is required to inject a traceback into
7  * another one.
8  *
9  * For better windows support (not everybody has a visual studio 2003
10  * at home) it would be a good thing to have a ctypes implementation, but
11  * because the struct is not exported there is currently no sane way.
12  *
13  * :copyright: 2007 by Armin Ronacher.
14  * :license: BSD, see LICENSE for more details.
15  */
16
17 #include <Python.h>
18
19
20 /**
21  * set the tb_next attribute of a traceback object
22  */
23 PyObject*
24 tb_set_next(PyObject *self, PyObject *args)
25 {
26         PyObject *tb, *next;
27
28         if (!PyArg_ParseTuple(args, "OO", &tb, &next))
29                 return NULL;
30         if (!(PyTraceBack_Check(tb) && (PyTraceBack_Check(next) ||
31                                         next == Py_None))) {
32                 PyErr_SetString(PyExc_TypeError, "traceback object required.");
33                 return NULL;
34         }
35
36         ((PyTracebackObject*)tb)->tb_next = next;
37
38         Py_INCREF(Py_None);
39         return Py_None;
40 }
41
42
43 static PyMethodDef module_methods[] = {
44         {"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS,
45          "Set the tb_next member of a traceback object."},
46         {NULL, NULL, 0, NULL}           /* Sentinel */
47 };
48
49 #ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
50 #define PyMODINIT_FUNC void
51 #endif
52 PyMODINIT_FUNC
53 init_debugger(void)
54 {
55         PyObject *module = Py_InitModule3("_debugger", module_methods, "");
56         if (!module)
57                 return;
58 }