traceback.c.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(tb_new__doc__,
  9. "TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)\n"
  10. "--\n"
  11. "\n"
  12. "Create a new traceback object.");
  13. static PyObject *
  14. tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame,
  15. int tb_lasti, int tb_lineno);
  16. static PyObject *
  17. tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  18. {
  19. PyObject *return_value = NULL;
  20. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  21. #define NUM_KEYWORDS 4
  22. static struct {
  23. PyGC_Head _this_is_not_used;
  24. PyObject_VAR_HEAD
  25. PyObject *ob_item[NUM_KEYWORDS];
  26. } _kwtuple = {
  27. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  28. .ob_item = { &_Py_ID(tb_next), &_Py_ID(tb_frame), &_Py_ID(tb_lasti), &_Py_ID(tb_lineno), },
  29. };
  30. #undef NUM_KEYWORDS
  31. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  32. #else // !Py_BUILD_CORE
  33. # define KWTUPLE NULL
  34. #endif // !Py_BUILD_CORE
  35. static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL};
  36. static _PyArg_Parser _parser = {
  37. .keywords = _keywords,
  38. .fname = "TracebackType",
  39. .kwtuple = KWTUPLE,
  40. };
  41. #undef KWTUPLE
  42. PyObject *argsbuf[4];
  43. PyObject * const *fastargs;
  44. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  45. PyObject *tb_next;
  46. PyFrameObject *tb_frame;
  47. int tb_lasti;
  48. int tb_lineno;
  49. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 4, 4, 0, argsbuf);
  50. if (!fastargs) {
  51. goto exit;
  52. }
  53. tb_next = fastargs[0];
  54. if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) {
  55. _PyArg_BadArgument("TracebackType", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]);
  56. goto exit;
  57. }
  58. tb_frame = (PyFrameObject *)fastargs[1];
  59. tb_lasti = _PyLong_AsInt(fastargs[2]);
  60. if (tb_lasti == -1 && PyErr_Occurred()) {
  61. goto exit;
  62. }
  63. tb_lineno = _PyLong_AsInt(fastargs[3]);
  64. if (tb_lineno == -1 && PyErr_Occurred()) {
  65. goto exit;
  66. }
  67. return_value = tb_new_impl(type, tb_next, tb_frame, tb_lasti, tb_lineno);
  68. exit:
  69. return return_value;
  70. }
  71. /*[clinic end generated code: output=7bc9927e362fdfb7 input=a9049054013a1b77]*/