_debugsupport.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <Python.h>
  11. static PyObject*
  12. tb_set_next(PyObject *self, PyObject *args)
  13. {
  14. PyTracebackObject *tb, *old;
  15. PyObject *next;
  16. if (!PyArg_ParseTuple(args, "O!O:tb_set_next", &PyTraceBack_Type, &tb, &next))
  17. return NULL;
  18. if (next == Py_None)
  19. next = NULL;
  20. else if (!PyTraceBack_Check(next)) {
  21. PyErr_SetString(PyExc_TypeError,
  22. "tb_set_next arg 2 must be traceback or None");
  23. return NULL;
  24. }
  25. else
  26. Py_INCREF(next);
  27. old = tb->tb_next;
  28. tb->tb_next = (PyTracebackObject*)next;
  29. Py_XDECREF(old);
  30. Py_INCREF(Py_None);
  31. return Py_None;
  32. }
  33. static PyMethodDef module_methods[] = {
  34. {"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS,
  35. "Set the tb_next member of a traceback object."},
  36. {NULL, NULL, 0, NULL} /* Sentinel */
  37. };
  38. #if PY_MAJOR_VERSION < 3
  39. #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
  40. #define PyMODINIT_FUNC void
  41. #endif
  42. PyMODINIT_FUNC
  43. init_debugsupport(void)
  44. {
  45. Py_InitModule3("jinja2._debugsupport", module_methods, "");
  46. }
  47. #else /* Python 3.x module initialization */
  48. static struct PyModuleDef module_definition = {
  49. PyModuleDef_HEAD_INIT,
  50. "jinja2._debugsupport",
  51. NULL,
  52. -1,
  53. module_methods,
  54. NULL,
  55. NULL,
  56. NULL,
  57. NULL
  58. };
  59. PyMODINIT_FUNC
  60. PyInit__debugsupport(void)
  61. {
  62. return PyModule_Create(&module_definition);
  63. }
  64. #endif