work on tha runtime
[jinja2.git] / jinja2 / _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 static PyObject *
24 tb_set_next(PyObject *self, PyObject *args)
25 {
26         PyTracebackObject *tb, *old;
27         PyObject *next;
28
29         if (!PyArg_ParseTuple(args, "O!O:tb_set_next", &PyTraceBack_Type, &tb, &next))
30                 return NULL;
31         if (next == Py_None)
32                 next = NULL;
33         else if (!PyTraceBack_Check(next)) {
34                 PyErr_SetString(PyExc_TypeError,
35                                 "tb_set_next arg 2 must be traceback or None");
36                 return NULL;
37         }
38         else
39                 Py_INCREF(next);
40
41         old = tb->tb_next;
42         tb->tb_next = (PyTracebackObject*)next;
43         Py_XDECREF(old);
44
45         Py_INCREF(Py_None);
46         return Py_None;
47 }
48
49
50 static PyMethodDef module_methods[] = {
51         {"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS,
52          "Set the tb_next member of a traceback object."},
53         {NULL, NULL, 0, NULL}           /* Sentinel */
54 };
55
56 #ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
57 #define PyMODINIT_FUNC void
58 #endif
59 PyMODINIT_FUNC
60 init_debugger(void)
61 {
62         PyObject *module = Py_InitModule3("jinja._debugger", module_methods, "");
63         if (!module)
64                 return;
65 }