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