Debian Codegraph @

Modules/clinic/_functoolsmodule.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(_functools_cmp_to_key__doc__,
13 "cmp_to_key($module, /, mycmp)\n"
14 "--\n"
15 "\n"
16 "Convert a cmp= function into a key= function.\n"
17 "\n"
18 " mycmp\n"
19 " Function that compares two objects.");
20
21 #define _FUNCTOOLS_CMP_TO_KEY_METHODDEF \
22 {"cmp_to_key", _PyCFunction_CAST(_functools_cmp_to_key), METH_FASTCALL|METH_KEYWORDS, _functools_cmp_to_key__doc__},
23
24 static PyObject *
25 _functools_cmp_to_key_impl(PyObject *module, PyObject *mycmp);
26
27 static PyObject *
28 _functools_cmp_to_key(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
29 {
30 PyObject *return_value = NULL;
31 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
32
33 #define NUM_KEYWORDS 1
34 static struct {
35 PyGC_Head _this_is_not_used;
36 PyObject_VAR_HEAD
37 Py_hash_t ob_hash;
38 PyObject *ob_item[NUM_KEYWORDS];
39 } _kwtuple = {
40 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
41 .ob_hash = -1,
42 .ob_item = { &_Py_ID(mycmp), },
43 };
44 #undef NUM_KEYWORDS
45 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
46
47 #else // !Py_BUILD_CORE
48 # define KWTUPLE NULL
49 #endif // !Py_BUILD_CORE
50
51 static const char * const _keywords[] = {"mycmp", NULL};
52 static _PyArg_Parser _parser = {
53 .keywords = _keywords,
54 .fname = "cmp_to_key",
55 .kwtuple = KWTUPLE,
56 };
57 #undef KWTUPLE
58 PyObject *argsbuf[1];
59 PyObject *mycmp;
60
61 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
62 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
63 if (!args) {
64 goto exit;
65 }
66 mycmp = args[0];
67 return_value = _functools_cmp_to_key_impl(module, mycmp);
68
69 exit:
70 return return_value;
71 }
72
73 PyDoc_STRVAR(_functools_reduce__doc__,
74 "reduce($module, function, iterable, /, initial=<unrepresentable>)\n"
75 "--\n"
76 "\n"
77 "Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n"
78 "\n"
79 "This effectively reduces the iterable to a single value. If initial is\n"
80 "present, it is placed before the items of the iterable in the\n"
81 "calculation, and serves as a default when the iterable is empty.\n"
82 "\n"
83 "For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n"
84 "calculates ((((1 + 2) + 3) + 4) + 5).");
85
86 #define _FUNCTOOLS_REDUCE_METHODDEF \
87 {"reduce", _PyCFunction_CAST(_functools_reduce), METH_FASTCALL|METH_KEYWORDS, _functools_reduce__doc__},
88
89 static PyObject *
90 _functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq,
91 PyObject *result);
92
93 static PyObject *
94 _functools_reduce(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
95 {
96 PyObject *return_value = NULL;
97 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
98
99 #define NUM_KEYWORDS 1
100 static struct {
101 PyGC_Head _this_is_not_used;
102 PyObject_VAR_HEAD
103 Py_hash_t ob_hash;
104 PyObject *ob_item[NUM_KEYWORDS];
105 } _kwtuple = {
106 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
107 .ob_hash = -1,
108 .ob_item = { &_Py_ID(initial), },
109 };
110 #undef NUM_KEYWORDS
111 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
112
113 #else // !Py_BUILD_CORE
114 # define KWTUPLE NULL
115 #endif // !Py_BUILD_CORE
116
117 static const char * const _keywords[] = {"", "", "initial", NULL};
118 static _PyArg_Parser _parser = {
119 .keywords = _keywords,
120 .fname = "reduce",
121 .kwtuple = KWTUPLE,
122 };
123 #undef KWTUPLE
124 PyObject *argsbuf[3];
125 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
126 PyObject *func;
127 PyObject *seq;
128 PyObject *result = NULL;
129
130 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
131 /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
132 if (!args) {
133 goto exit;
134 }
135 func = args[0];
136 seq = args[1];
137 if (!noptargs) {
138 goto skip_optional_pos;
139 }
140 result = args[2];
141 skip_optional_pos:
142 return_value = _functools_reduce_impl(module, func, seq, result);
143
144 exit:
145 return return_value;
146 }
147
148 PyDoc_STRVAR(_functools__lru_cache_wrapper_cache_info__doc__,
149 "cache_info($self, /)\n"
150 "--\n"
151 "\n"
152 "Report cache statistics");
153
154 #define _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_INFO_METHODDEF \
155 {"cache_info", (PyCFunction)_functools__lru_cache_wrapper_cache_info, METH_NOARGS, _functools__lru_cache_wrapper_cache_info__doc__},
156
157 static PyObject *
158 _functools__lru_cache_wrapper_cache_info_impl(PyObject *self);
159
160 static PyObject *
161 _functools__lru_cache_wrapper_cache_info(PyObject *self, PyObject *Py_UNUSED(ignored))
162 {
163 PyObject *return_value = NULL;
164
165 Py_BEGIN_CRITICAL_SECTION(self);
166 return_value = _functools__lru_cache_wrapper_cache_info_impl(self);
167 Py_END_CRITICAL_SECTION();
168
169 return return_value;
170 }
171
172 PyDoc_STRVAR(_functools__lru_cache_wrapper_cache_clear__doc__,
173 "cache_clear($self, /)\n"
174 "--\n"
175 "\n"
176 "Clear the cache and cache statistics");
177
178 #define _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_CLEAR_METHODDEF \
179 {"cache_clear", (PyCFunction)_functools__lru_cache_wrapper_cache_clear, METH_NOARGS, _functools__lru_cache_wrapper_cache_clear__doc__},
180
181 static PyObject *
182 _functools__lru_cache_wrapper_cache_clear_impl(PyObject *self);
183
184 static PyObject *
185 _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
186 {
187 PyObject *return_value = NULL;
188
189 Py_BEGIN_CRITICAL_SECTION(self);
190 return_value = _functools__lru_cache_wrapper_cache_clear_impl(self);
191 Py_END_CRITICAL_SECTION();
192
193 return return_value;
194 }
195 /*[clinic end generated code: output=1c44abd7e56118dc input=a9049054013a1b77]*/