Coverage Report

Created: 2026-05-30 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/clinic/_functoolsmodule.c.h
Line
Count
Source
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, /,\n"
75
"       initial=functools._initial_missing)\n"
76
"--\n"
77
"\n"
78
"Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n"
79
"\n"
80
"This effectively reduces the iterable to a single value.  If initial is\n"
81
"present, it is placed before the items of the iterable in the\n"
82
"calculation, and serves as a default when the iterable is empty.\n"
83
"\n"
84
"For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n"
85
"calculates ((((1 + 2) + 3) + 4) + 5).");
86
87
#define _FUNCTOOLS_REDUCE_METHODDEF    \
88
    {"reduce", _PyCFunction_CAST(_functools_reduce), METH_FASTCALL|METH_KEYWORDS, _functools_reduce__doc__},
89
90
static PyObject *
91
_functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq,
92
                       PyObject *result);
93
94
static PyObject *
95
_functools_reduce(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
96
0
{
97
0
    PyObject *return_value = NULL;
98
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
99
100
0
    #define NUM_KEYWORDS 1
101
0
    static struct {
102
0
        PyGC_Head _this_is_not_used;
103
0
        PyObject_VAR_HEAD
104
0
        Py_hash_t ob_hash;
105
0
        PyObject *ob_item[NUM_KEYWORDS];
106
0
    } _kwtuple = {
107
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
108
0
        .ob_hash = -1,
109
0
        .ob_item = { &_Py_ID(initial), },
110
0
    };
111
0
    #undef NUM_KEYWORDS
112
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
113
114
    #else  // !Py_BUILD_CORE
115
    #  define KWTUPLE NULL
116
    #endif  // !Py_BUILD_CORE
117
118
0
    static const char * const _keywords[] = {"", "", "initial", NULL};
119
0
    static _PyArg_Parser _parser = {
120
0
        .keywords = _keywords,
121
0
        .fname = "reduce",
122
0
        .kwtuple = KWTUPLE,
123
0
    };
124
0
    #undef KWTUPLE
125
0
    PyObject *argsbuf[3];
126
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
127
0
    PyObject *func;
128
0
    PyObject *seq;
129
0
    PyObject *result = NULL;
130
131
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
132
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
133
0
    if (!args) {
134
0
        goto exit;
135
0
    }
136
0
    func = args[0];
137
0
    seq = args[1];
138
0
    if (!noptargs) {
139
0
        goto skip_optional_pos;
140
0
    }
141
0
    result = args[2];
142
0
skip_optional_pos:
143
0
    return_value = _functools_reduce_impl(module, func, seq, result);
144
145
0
exit:
146
0
    return return_value;
147
0
}
148
149
PyDoc_STRVAR(_functools__lru_cache_wrapper_cache_info__doc__,
150
"cache_info($self, /)\n"
151
"--\n"
152
"\n"
153
"Report cache statistics");
154
155
#define _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_INFO_METHODDEF    \
156
    {"cache_info", (PyCFunction)_functools__lru_cache_wrapper_cache_info, METH_NOARGS, _functools__lru_cache_wrapper_cache_info__doc__},
157
158
static PyObject *
159
_functools__lru_cache_wrapper_cache_info_impl(PyObject *self);
160
161
static PyObject *
162
_functools__lru_cache_wrapper_cache_info(PyObject *self, PyObject *Py_UNUSED(ignored))
163
0
{
164
0
    PyObject *return_value = NULL;
165
166
0
    Py_BEGIN_CRITICAL_SECTION(self);
167
0
    return_value = _functools__lru_cache_wrapper_cache_info_impl(self);
168
0
    Py_END_CRITICAL_SECTION();
169
170
0
    return return_value;
171
0
}
172
173
PyDoc_STRVAR(_functools__lru_cache_wrapper_cache_clear__doc__,
174
"cache_clear($self, /)\n"
175
"--\n"
176
"\n"
177
"Clear the cache and cache statistics");
178
179
#define _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_CLEAR_METHODDEF    \
180
    {"cache_clear", (PyCFunction)_functools__lru_cache_wrapper_cache_clear, METH_NOARGS, _functools__lru_cache_wrapper_cache_clear__doc__},
181
182
static PyObject *
183
_functools__lru_cache_wrapper_cache_clear_impl(PyObject *self);
184
185
static PyObject *
186
_functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
187
6.08k
{
188
6.08k
    PyObject *return_value = NULL;
189
190
6.08k
    Py_BEGIN_CRITICAL_SECTION(self);
191
6.08k
    return_value = _functools__lru_cache_wrapper_cache_clear_impl(self);
192
6.08k
    Py_END_CRITICAL_SECTION();
193
194
6.08k
    return return_value;
195
6.08k
}
196
/*[clinic end generated code: output=6d8fdaeba4b520fa input=a9049054013a1b77]*/