_testmultiphase.c.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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(_testmultiphase_StateAccessType_get_defining_module__doc__,
  9. "get_defining_module($self, /)\n"
  10. "--\n"
  11. "\n"
  12. "Return the module of the defining class.\n"
  13. "\n"
  14. "Also tests that result of PyType_GetModuleByDef matches defining_class\'s\n"
  15. "module.");
  16. #define _TESTMULTIPHASE_STATEACCESSTYPE_GET_DEFINING_MODULE_METHODDEF \
  17. {"get_defining_module", _PyCFunction_CAST(_testmultiphase_StateAccessType_get_defining_module), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _testmultiphase_StateAccessType_get_defining_module__doc__},
  18. static PyObject *
  19. _testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *self,
  20. PyTypeObject *cls);
  21. static PyObject *
  22. _testmultiphase_StateAccessType_get_defining_module(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  23. {
  24. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  25. PyErr_SetString(PyExc_TypeError, "get_defining_module() takes no arguments");
  26. return NULL;
  27. }
  28. return _testmultiphase_StateAccessType_get_defining_module_impl(self, cls);
  29. }
  30. PyDoc_STRVAR(_testmultiphase_StateAccessType_getmodulebydef_bad_def__doc__,
  31. "getmodulebydef_bad_def($self, /)\n"
  32. "--\n"
  33. "\n"
  34. "Test that result of PyType_GetModuleByDef with a bad def is NULL.");
  35. #define _TESTMULTIPHASE_STATEACCESSTYPE_GETMODULEBYDEF_BAD_DEF_METHODDEF \
  36. {"getmodulebydef_bad_def", _PyCFunction_CAST(_testmultiphase_StateAccessType_getmodulebydef_bad_def), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _testmultiphase_StateAccessType_getmodulebydef_bad_def__doc__},
  37. static PyObject *
  38. _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(StateAccessTypeObject *self,
  39. PyTypeObject *cls);
  40. static PyObject *
  41. _testmultiphase_StateAccessType_getmodulebydef_bad_def(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  42. {
  43. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  44. PyErr_SetString(PyExc_TypeError, "getmodulebydef_bad_def() takes no arguments");
  45. return NULL;
  46. }
  47. return _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(self, cls);
  48. }
  49. PyDoc_STRVAR(_testmultiphase_StateAccessType_increment_count_clinic__doc__,
  50. "increment_count_clinic($self, /, n=1, *, twice=False)\n"
  51. "--\n"
  52. "\n"
  53. "Add \'n\' from the module-state counter.\n"
  54. "\n"
  55. "Pass \'twice\' to double that amount.\n"
  56. "\n"
  57. "This tests Argument Clinic support for defining_class.");
  58. #define _TESTMULTIPHASE_STATEACCESSTYPE_INCREMENT_COUNT_CLINIC_METHODDEF \
  59. {"increment_count_clinic", _PyCFunction_CAST(_testmultiphase_StateAccessType_increment_count_clinic), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _testmultiphase_StateAccessType_increment_count_clinic__doc__},
  60. static PyObject *
  61. _testmultiphase_StateAccessType_increment_count_clinic_impl(StateAccessTypeObject *self,
  62. PyTypeObject *cls,
  63. int n, int twice);
  64. static PyObject *
  65. _testmultiphase_StateAccessType_increment_count_clinic(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  66. {
  67. PyObject *return_value = NULL;
  68. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  69. #define NUM_KEYWORDS 2
  70. static struct {
  71. PyGC_Head _this_is_not_used;
  72. PyObject_VAR_HEAD
  73. PyObject *ob_item[NUM_KEYWORDS];
  74. } _kwtuple = {
  75. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  76. .ob_item = { _Py_LATIN1_CHR('n'), &_Py_ID(twice), },
  77. };
  78. #undef NUM_KEYWORDS
  79. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  80. #else // !Py_BUILD_CORE
  81. # define KWTUPLE NULL
  82. #endif // !Py_BUILD_CORE
  83. static const char * const _keywords[] = {"n", "twice", NULL};
  84. static _PyArg_Parser _parser = {
  85. .keywords = _keywords,
  86. .fname = "increment_count_clinic",
  87. .kwtuple = KWTUPLE,
  88. };
  89. #undef KWTUPLE
  90. PyObject *argsbuf[2];
  91. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  92. int n = 1;
  93. int twice = 0;
  94. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  95. if (!args) {
  96. goto exit;
  97. }
  98. if (!noptargs) {
  99. goto skip_optional_pos;
  100. }
  101. if (args[0]) {
  102. n = _PyLong_AsInt(args[0]);
  103. if (n == -1 && PyErr_Occurred()) {
  104. goto exit;
  105. }
  106. if (!--noptargs) {
  107. goto skip_optional_pos;
  108. }
  109. }
  110. skip_optional_pos:
  111. if (!noptargs) {
  112. goto skip_optional_kwonly;
  113. }
  114. twice = PyObject_IsTrue(args[1]);
  115. if (twice < 0) {
  116. goto exit;
  117. }
  118. skip_optional_kwonly:
  119. return_value = _testmultiphase_StateAccessType_increment_count_clinic_impl(self, cls, n, twice);
  120. exit:
  121. return return_value;
  122. }
  123. PyDoc_STRVAR(_testmultiphase_StateAccessType_get_count__doc__,
  124. "get_count($self, /)\n"
  125. "--\n"
  126. "\n"
  127. "Return the value of the module-state counter.");
  128. #define _TESTMULTIPHASE_STATEACCESSTYPE_GET_COUNT_METHODDEF \
  129. {"get_count", _PyCFunction_CAST(_testmultiphase_StateAccessType_get_count), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _testmultiphase_StateAccessType_get_count__doc__},
  130. static PyObject *
  131. _testmultiphase_StateAccessType_get_count_impl(StateAccessTypeObject *self,
  132. PyTypeObject *cls);
  133. static PyObject *
  134. _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  135. {
  136. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  137. PyErr_SetString(PyExc_TypeError, "get_count() takes no arguments");
  138. return NULL;
  139. }
  140. return _testmultiphase_StateAccessType_get_count_impl(self, cls);
  141. }
  142. /*[clinic end generated code: output=0543b54ec62be171 input=a9049054013a1b77]*/