structseq.c.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. static PyObject *
  9. structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict);
  10. static PyObject *
  11. structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  12. {
  13. PyObject *return_value = NULL;
  14. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  15. #define NUM_KEYWORDS 2
  16. static struct {
  17. PyGC_Head _this_is_not_used;
  18. PyObject_VAR_HEAD
  19. PyObject *ob_item[NUM_KEYWORDS];
  20. } _kwtuple = {
  21. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  22. .ob_item = { &_Py_ID(sequence), &_Py_ID(dict), },
  23. };
  24. #undef NUM_KEYWORDS
  25. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  26. #else // !Py_BUILD_CORE
  27. # define KWTUPLE NULL
  28. #endif // !Py_BUILD_CORE
  29. static const char * const _keywords[] = {"sequence", "dict", NULL};
  30. static _PyArg_Parser _parser = {
  31. .keywords = _keywords,
  32. .fname = "structseq",
  33. .kwtuple = KWTUPLE,
  34. };
  35. #undef KWTUPLE
  36. PyObject *argsbuf[2];
  37. PyObject * const *fastargs;
  38. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  39. Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
  40. PyObject *arg;
  41. PyObject *dict = NULL;
  42. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
  43. if (!fastargs) {
  44. goto exit;
  45. }
  46. arg = fastargs[0];
  47. if (!noptargs) {
  48. goto skip_optional_pos;
  49. }
  50. dict = fastargs[1];
  51. skip_optional_pos:
  52. return_value = structseq_new_impl(type, arg, dict);
  53. exit:
  54. return return_value;
  55. }
  56. /*[clinic end generated code: output=802d5663c7d01024 input=a9049054013a1b77]*/