/src/cpython/Modules/clinic/_functoolsmodule.c.h
Line | Count | Source (jump to first uncovered line) |
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 | 0 | { |
30 | 0 | PyObject *return_value = NULL; |
31 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
32 | |
|
33 | 0 | #define NUM_KEYWORDS 1 |
34 | 0 | static struct { |
35 | 0 | PyGC_Head _this_is_not_used; |
36 | 0 | PyObject_VAR_HEAD |
37 | 0 | Py_hash_t ob_hash; |
38 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
39 | 0 | } _kwtuple = { |
40 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
41 | 0 | .ob_hash = -1, |
42 | 0 | .ob_item = { &_Py_ID(mycmp), }, |
43 | 0 | }; |
44 | 0 | #undef NUM_KEYWORDS |
45 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
46 | |
|
47 | | #else // !Py_BUILD_CORE |
48 | | # define KWTUPLE NULL |
49 | | #endif // !Py_BUILD_CORE |
50 | |
|
51 | 0 | static const char * const _keywords[] = {"mycmp", NULL}; |
52 | 0 | static _PyArg_Parser _parser = { |
53 | 0 | .keywords = _keywords, |
54 | 0 | .fname = "cmp_to_key", |
55 | 0 | .kwtuple = KWTUPLE, |
56 | 0 | }; |
57 | 0 | #undef KWTUPLE |
58 | 0 | PyObject *argsbuf[1]; |
59 | 0 | PyObject *mycmp; |
60 | |
|
61 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
62 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
63 | 0 | if (!args) { |
64 | 0 | goto exit; |
65 | 0 | } |
66 | 0 | mycmp = args[0]; |
67 | 0 | return_value = _functools_cmp_to_key_impl(module, mycmp); |
68 | |
|
69 | 0 | exit: |
70 | 0 | return return_value; |
71 | 0 | } |
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 present,\n" |
80 | | "it is placed before the items of the iterable in the calculation, and serves as\n" |
81 | | "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 | 0 | { |
96 | 0 | PyObject *return_value = NULL; |
97 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
98 | |
|
99 | 0 | #define NUM_KEYWORDS 1 |
100 | 0 | static struct { |
101 | 0 | PyGC_Head _this_is_not_used; |
102 | 0 | PyObject_VAR_HEAD |
103 | 0 | Py_hash_t ob_hash; |
104 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
105 | 0 | } _kwtuple = { |
106 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
107 | 0 | .ob_hash = -1, |
108 | 0 | .ob_item = { &_Py_ID(initial), }, |
109 | 0 | }; |
110 | 0 | #undef NUM_KEYWORDS |
111 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
112 | |
|
113 | | #else // !Py_BUILD_CORE |
114 | | # define KWTUPLE NULL |
115 | | #endif // !Py_BUILD_CORE |
116 | |
|
117 | 0 | static const char * const _keywords[] = {"", "", "initial", NULL}; |
118 | 0 | static _PyArg_Parser _parser = { |
119 | 0 | .keywords = _keywords, |
120 | 0 | .fname = "reduce", |
121 | 0 | .kwtuple = KWTUPLE, |
122 | 0 | }; |
123 | 0 | #undef KWTUPLE |
124 | 0 | PyObject *argsbuf[3]; |
125 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
126 | 0 | PyObject *func; |
127 | 0 | PyObject *seq; |
128 | 0 | PyObject *result = NULL; |
129 | |
|
130 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
131 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
132 | 0 | if (!args) { |
133 | 0 | goto exit; |
134 | 0 | } |
135 | 0 | func = args[0]; |
136 | 0 | seq = args[1]; |
137 | 0 | if (!noptargs) { |
138 | 0 | goto skip_optional_pos; |
139 | 0 | } |
140 | 0 | result = args[2]; |
141 | 0 | skip_optional_pos: |
142 | 0 | return_value = _functools_reduce_impl(module, func, seq, result); |
143 | |
|
144 | 0 | exit: |
145 | 0 | return return_value; |
146 | 0 | } |
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 | 0 | { |
163 | 0 | PyObject *return_value = NULL; |
164 | |
|
165 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
166 | 0 | return_value = _functools__lru_cache_wrapper_cache_info_impl(self); |
167 | 0 | Py_END_CRITICAL_SECTION(); |
168 | |
|
169 | 0 | return return_value; |
170 | 0 | } |
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 | 0 | { |
187 | 0 | PyObject *return_value = NULL; |
188 | |
|
189 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
190 | 0 | return_value = _functools__lru_cache_wrapper_cache_clear_impl(self); |
191 | 0 | Py_END_CRITICAL_SECTION(); |
192 | |
|
193 | 0 | return return_value; |
194 | 0 | } |
195 | | /*[clinic end generated code: output=7f2abc718fcc35d5 input=a9049054013a1b77]*/ |