Branch data Line data Source code
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 : :
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 *
28 : 0 : _testmultiphase_StateAccessType_get_defining_module(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
29 : : {
30 [ # # ]: 0 : if (nargs) {
31 : 0 : PyErr_SetString(PyExc_TypeError, "get_defining_module() takes no arguments");
32 : 0 : return NULL;
33 : : }
34 : 0 : 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 *
51 : 0 : _testmultiphase_StateAccessType_getmodulebydef_bad_def(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
52 : : {
53 [ # # ]: 0 : if (nargs) {
54 : 0 : PyErr_SetString(PyExc_TypeError, "getmodulebydef_bad_def() takes no arguments");
55 : 0 : return NULL;
56 : : }
57 : 0 : 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 *
79 : 0 : _testmultiphase_StateAccessType_increment_count_clinic(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
80 : : {
81 : 0 : 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_ID(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 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
109 : 0 : int n = 1;
110 : 0 : int twice = 0;
111 : :
112 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
113 [ # # ]: 0 : if (!args) {
114 : 0 : goto exit;
115 : : }
116 [ # # ]: 0 : if (!noptargs) {
117 : 0 : goto skip_optional_pos;
118 : : }
119 [ # # ]: 0 : if (args[0]) {
120 : 0 : n = _PyLong_AsInt(args[0]);
121 [ # # # # ]: 0 : if (n == -1 && PyErr_Occurred()) {
122 : 0 : goto exit;
123 : : }
124 [ # # ]: 0 : if (!--noptargs) {
125 : 0 : goto skip_optional_pos;
126 : : }
127 : : }
128 : 0 : skip_optional_pos:
129 [ # # ]: 0 : if (!noptargs) {
130 : 0 : goto skip_optional_kwonly;
131 : : }
132 : 0 : twice = PyObject_IsTrue(args[1]);
133 [ # # ]: 0 : if (twice < 0) {
134 : 0 : goto exit;
135 : : }
136 : 0 : skip_optional_kwonly:
137 : 0 : return_value = _testmultiphase_StateAccessType_increment_count_clinic_impl(self, cls, n, twice);
138 : :
139 : 0 : exit:
140 : 0 : 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 *
157 : 0 : _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
158 : : {
159 [ # # ]: 0 : if (nargs) {
160 : 0 : PyErr_SetString(PyExc_TypeError, "get_count() takes no arguments");
161 : 0 : return NULL;
162 : : }
163 : 0 : return _testmultiphase_StateAccessType_get_count_impl(self, cls);
164 : : }
165 : : /*[clinic end generated code: output=52ea97ab2f03bb6d input=a9049054013a1b77]*/
|