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