With number of course. Jinja2.pdf not Jinja.pdf
[jinja2.git] / jinja2 / _debugsupport.c
1 /**
2  * jinja2._debugsupport
3  * ~~~~~~~~~~~~~~~~~~~~
4  *
5  * C implementation of `tb_set_next`.
6  *
7  * :copyright: (c) 2010 by the Jinja Team.
8  * :license: BSD.
9  */
10
11 #include <Python.h>
12
13
14 static PyObject*
15 tb_set_next(PyObject *self, PyObject *args)
16 {
17         PyTracebackObject *tb, *old;
18         PyObject *next;
19
20         if (!PyArg_ParseTuple(args, "O!O:tb_set_next", &PyTraceBack_Type, &tb, &next))
21                 return NULL;
22         if (next == Py_None)
23                 next = NULL;
24         else if (!PyTraceBack_Check(next)) {
25                 PyErr_SetString(PyExc_TypeError,
26                                 "tb_set_next arg 2 must be traceback or None");
27                 return NULL;
28         }
29         else
30                 Py_INCREF(next);
31
32         old = tb->tb_next;
33         tb->tb_next = (PyTracebackObject*)next;
34         Py_XDECREF(old);
35
36         Py_INCREF(Py_None);
37         return Py_None;
38 }
39
40 static PyMethodDef module_methods[] = {
41         {"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS,
42          "Set the tb_next member of a traceback object."},
43         {NULL, NULL, 0, NULL}           /* Sentinel */
44 };
45
46
47 #if PY_MAJOR_VERSION < 3
48
49 #ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
50 #define PyMODINIT_FUNC void
51 #endif
52 PyMODINIT_FUNC
53 init_debugsupport(void)
54 {
55         Py_InitModule3("jinja2._debugsupport", module_methods, "");
56 }
57
58 #else /* Python 3.x module initialization */
59
60 static struct PyModuleDef module_definition = {
61         PyModuleDef_HEAD_INIT,
62         "jinja2._debugsupport",
63         NULL,
64         -1,
65         module_methods,
66         NULL,
67         NULL,
68         NULL,
69         NULL
70 };
71
72 PyMODINIT_FUNC
73 PyInit__debugsupport(void)
74 {
75         return PyModule_Create(&module_definition);
76 }
77
78 #endif