Debian Codegraph @

Objects/clinic/funcobject.c.h

raw
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_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(function___annotate____doc__,
13 "Get the code object for a function.");
14 #if defined(function___annotate___DOCSTR)
15 # undef function___annotate___DOCSTR
16 #endif
17 #define function___annotate___DOCSTR function___annotate____doc__
18
19 #if !defined(function___annotate___DOCSTR)
20 # define function___annotate___DOCSTR NULL
21 #endif
22 #if defined(FUNCTION___ANNOTATE___GETSETDEF)
23 # undef FUNCTION___ANNOTATE___GETSETDEF
24 # define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR},
25 #else
26 # define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, NULL, function___annotate___DOCSTR},
27 #endif
28
29 static PyObject *
30 function___annotate___get_impl(PyFunctionObject *self);
31
32 static PyObject *
33 function___annotate___get(PyObject *self, void *Py_UNUSED(context))
34 {
35 PyObject *return_value = NULL;
36
37 Py_BEGIN_CRITICAL_SECTION(self);
38 return_value = function___annotate___get_impl((PyFunctionObject *)self);
39 Py_END_CRITICAL_SECTION();
40
41 return return_value;
42 }
43
44 #if !defined(function___annotate___DOCSTR)
45 # define function___annotate___DOCSTR NULL
46 #endif
47 #if defined(FUNCTION___ANNOTATE___GETSETDEF)
48 # undef FUNCTION___ANNOTATE___GETSETDEF
49 # define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR},
50 #else
51 # define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", NULL, (setter)function___annotate___set, NULL},
52 #endif
53
54 static int
55 function___annotate___set_impl(PyFunctionObject *self, PyObject *value);
56
57 static int
58 function___annotate___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
59 {
60 int return_value;
61
62 Py_BEGIN_CRITICAL_SECTION(self);
63 return_value = function___annotate___set_impl((PyFunctionObject *)self, value);
64 Py_END_CRITICAL_SECTION();
65
66 return return_value;
67 }
68
69 PyDoc_STRVAR(function___annotations____doc__,
70 "Dict of annotations in a function object.");
71 #if defined(function___annotations___DOCSTR)
72 # undef function___annotations___DOCSTR
73 #endif
74 #define function___annotations___DOCSTR function___annotations____doc__
75
76 #if !defined(function___annotations___DOCSTR)
77 # define function___annotations___DOCSTR NULL
78 #endif
79 #if defined(FUNCTION___ANNOTATIONS___GETSETDEF)
80 # undef FUNCTION___ANNOTATIONS___GETSETDEF
81 # define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR},
82 #else
83 # define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, NULL, function___annotations___DOCSTR},
84 #endif
85
86 static PyObject *
87 function___annotations___get_impl(PyFunctionObject *self);
88
89 static PyObject *
90 function___annotations___get(PyObject *self, void *Py_UNUSED(context))
91 {
92 PyObject *return_value = NULL;
93
94 Py_BEGIN_CRITICAL_SECTION(self);
95 return_value = function___annotations___get_impl((PyFunctionObject *)self);
96 Py_END_CRITICAL_SECTION();
97
98 return return_value;
99 }
100
101 #if !defined(function___annotations___DOCSTR)
102 # define function___annotations___DOCSTR NULL
103 #endif
104 #if defined(FUNCTION___ANNOTATIONS___GETSETDEF)
105 # undef FUNCTION___ANNOTATIONS___GETSETDEF
106 # define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR},
107 #else
108 # define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", NULL, (setter)function___annotations___set, NULL},
109 #endif
110
111 static int
112 function___annotations___set_impl(PyFunctionObject *self, PyObject *value);
113
114 static int
115 function___annotations___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
116 {
117 int return_value;
118
119 Py_BEGIN_CRITICAL_SECTION(self);
120 return_value = function___annotations___set_impl((PyFunctionObject *)self, value);
121 Py_END_CRITICAL_SECTION();
122
123 return return_value;
124 }
125
126 PyDoc_STRVAR(function___type_params____doc__,
127 "Get the declared type parameters for a function.");
128 #if defined(function___type_params___DOCSTR)
129 # undef function___type_params___DOCSTR
130 #endif
131 #define function___type_params___DOCSTR function___type_params____doc__
132
133 #if !defined(function___type_params___DOCSTR)
134 # define function___type_params___DOCSTR NULL
135 #endif
136 #if defined(FUNCTION___TYPE_PARAMS___GETSETDEF)
137 # undef FUNCTION___TYPE_PARAMS___GETSETDEF
138 # define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR},
139 #else
140 # define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, NULL, function___type_params___DOCSTR},
141 #endif
142
143 static PyObject *
144 function___type_params___get_impl(PyFunctionObject *self);
145
146 static PyObject *
147 function___type_params___get(PyObject *self, void *Py_UNUSED(context))
148 {
149 PyObject *return_value = NULL;
150
151 Py_BEGIN_CRITICAL_SECTION(self);
152 return_value = function___type_params___get_impl((PyFunctionObject *)self);
153 Py_END_CRITICAL_SECTION();
154
155 return return_value;
156 }
157
158 #if !defined(function___type_params___DOCSTR)
159 # define function___type_params___DOCSTR NULL
160 #endif
161 #if defined(FUNCTION___TYPE_PARAMS___GETSETDEF)
162 # undef FUNCTION___TYPE_PARAMS___GETSETDEF
163 # define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR},
164 #else
165 # define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", NULL, (setter)function___type_params___set, NULL},
166 #endif
167
168 static int
169 function___type_params___set_impl(PyFunctionObject *self, PyObject *value);
170
171 static int
172 function___type_params___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
173 {
174 int return_value;
175
176 Py_BEGIN_CRITICAL_SECTION(self);
177 return_value = function___type_params___set_impl((PyFunctionObject *)self, value);
178 Py_END_CRITICAL_SECTION();
179
180 return return_value;
181 }
182
183 PyDoc_STRVAR(func_new__doc__,
184 "function(code, globals, name=None, argdefs=None, closure=None,\n"
185 " kwdefaults=None)\n"
186 "--\n"
187 "\n"
188 "Create a function object.\n"
189 "\n"
190 " code\n"
191 " a code object\n"
192 " globals\n"
193 " the globals dictionary\n"
194 " name\n"
195 " a string that overrides the name from the code object\n"
196 " argdefs\n"
197 " a tuple that specifies the default argument values\n"
198 " closure\n"
199 " a tuple that supplies the bindings for free variables\n"
200 " kwdefaults\n"
201 " a dictionary that specifies the default keyword argument values");
202
203 static PyObject *
204 func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
205 PyObject *name, PyObject *defaults, PyObject *closure,
206 PyObject *kwdefaults);
207
208 static PyObject *
209 func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
210 {
211 PyObject *return_value = NULL;
212 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
213
214 #define NUM_KEYWORDS 6
215 static struct {
216 PyGC_Head _this_is_not_used;
217 PyObject_VAR_HEAD
218 Py_hash_t ob_hash;
219 PyObject *ob_item[NUM_KEYWORDS];
220 } _kwtuple = {
221 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
222 .ob_hash = -1,
223 .ob_item = { &_Py_ID(code), &_Py_ID(globals), &_Py_ID(name), &_Py_ID(argdefs), &_Py_ID(closure), &_Py_ID(kwdefaults), },
224 };
225 #undef NUM_KEYWORDS
226 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
227
228 #else // !Py_BUILD_CORE
229 # define KWTUPLE NULL
230 #endif // !Py_BUILD_CORE
231
232 static const char * const _keywords[] = {"code", "globals", "name", "argdefs", "closure", "kwdefaults", NULL};
233 static _PyArg_Parser _parser = {
234 .keywords = _keywords,
235 .fname = "function",
236 .kwtuple = KWTUPLE,
237 };
238 #undef KWTUPLE
239 PyObject *argsbuf[6];
240 PyObject * const *fastargs;
241 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
242 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
243 PyCodeObject *code;
244 PyObject *globals;
245 PyObject *name = Py_None;
246 PyObject *defaults = Py_None;
247 PyObject *closure = Py_None;
248 PyObject *kwdefaults = Py_None;
249
250 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
251 /*minpos*/ 2, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
252 if (!fastargs) {
253 goto exit;
254 }
255 if (!PyObject_TypeCheck(fastargs[0], &PyCode_Type)) {
256 _PyArg_BadArgument("function", "argument 'code'", (&PyCode_Type)->tp_name, fastargs[0]);
257 goto exit;
258 }
259 code = (PyCodeObject *)fastargs[0];
260 if (!PyDict_Check(fastargs[1])) {
261 _PyArg_BadArgument("function", "argument 'globals'", "dict", fastargs[1]);
262 goto exit;
263 }
264 globals = fastargs[1];
265 if (!noptargs) {
266 goto skip_optional_pos;
267 }
268 if (fastargs[2]) {
269 name = fastargs[2];
270 if (!--noptargs) {
271 goto skip_optional_pos;
272 }
273 }
274 if (fastargs[3]) {
275 defaults = fastargs[3];
276 if (!--noptargs) {
277 goto skip_optional_pos;
278 }
279 }
280 if (fastargs[4]) {
281 closure = fastargs[4];
282 if (!--noptargs) {
283 goto skip_optional_pos;
284 }
285 }
286 kwdefaults = fastargs[5];
287 skip_optional_pos:
288 return_value = func_new_impl(type, code, globals, name, defaults, closure, kwdefaults);
289
290 exit:
291 return return_value;
292 }
293 /*[clinic end generated code: output=12cb900088d41bdb input=a9049054013a1b77]*/