Coverage Report

Created: 2026-12-01 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/call.c
Line
Count
Source
1
#include "Python.h"
2
#include "pycore_call.h"          // _PyObject_CallNoArgsTstate()
3
#include "pycore_ceval.h"         // _Py_EnterRecursiveCallTstate()
4
#include "pycore_dict.h"          // _PyDict_FromItems()
5
#include "pycore_function.h"      // _PyFunction_Vectorcall() definition
6
#include "pycore_modsupport.h"    // _Py_VaBuildStack()
7
#include "pycore_object.h"        // _PyCFunctionWithKeywords_TrampolineCall()
8
#include "pycore_pyerrors.h"      // _PyErr_Occurred()
9
#include "pycore_pystate.h"       // _PyThreadState_GET()
10
#include "pycore_tuple.h"         // _PyTuple_ITEMS()
11
12
13
static PyObject *
14
null_error(PyThreadState *tstate)
15
0
{
16
0
    if (!_PyErr_Occurred(tstate)) {
17
0
        _PyErr_SetString(tstate, PyExc_SystemError,
18
0
                         "null argument to internal routine");
19
0
    }
20
0
    return NULL;
21
0
}
22
23
24
PyObject*
25
_Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable,
26
                        PyObject *result, const char *where)
27
795M
{
28
795M
    assert((callable != NULL) ^ (where != NULL));
29
30
795M
    if (result == NULL) {
31
20.7M
        if (!_PyErr_Occurred(tstate)) {
32
0
            if (callable)
33
0
                _PyErr_Format(tstate, PyExc_SystemError,
34
0
                              "%R returned NULL without setting an exception",
35
0
                              callable);
36
0
            else
37
0
                _PyErr_Format(tstate, PyExc_SystemError,
38
0
                              "%s returned NULL without setting an exception",
39
0
                              where);
40
#ifdef Py_DEBUG
41
            /* Ensure that the bug is caught in debug mode.
42
               Py_FatalError() logs the SystemError exception raised above. */
43
            Py_FatalError("a function returned NULL without setting an exception");
44
#endif
45
0
            return NULL;
46
0
        }
47
20.7M
    }
48
774M
    else {
49
774M
        if (_PyErr_Occurred(tstate)) {
50
0
            Py_DECREF(result);
51
52
0
            if (callable) {
53
0
                _PyErr_FormatFromCauseTstate(
54
0
                    tstate, PyExc_SystemError,
55
0
                    "%R returned a result with an exception set", callable);
56
0
            }
57
0
            else {
58
0
                _PyErr_FormatFromCauseTstate(
59
0
                    tstate, PyExc_SystemError,
60
0
                    "%s returned a result with an exception set", where);
61
0
            }
62
#ifdef Py_DEBUG
63
            /* Ensure that the bug is caught in debug mode.
64
               Py_FatalError() logs the SystemError exception raised above. */
65
            Py_FatalError("a function returned a result with an exception set");
66
#endif
67
0
            return NULL;
68
0
        }
69
774M
    }
70
795M
    return result;
71
795M
}
72
73
74
int
75
_Py_CheckSlotResult(PyObject *obj, const char *slot_name, int success)
76
0
{
77
0
    PyThreadState *tstate = _PyThreadState_GET();
78
0
    if (!success) {
79
0
        if (!_PyErr_Occurred(tstate)) {
80
0
            _Py_FatalErrorFormat(__func__,
81
0
                                 "Slot %s of type %s failed "
82
0
                                 "without setting an exception",
83
0
                                 slot_name, Py_TYPE(obj)->tp_name);
84
0
        }
85
0
    }
86
0
    else {
87
0
        if (_PyErr_Occurred(tstate)) {
88
0
            _Py_FatalErrorFormat(__func__,
89
0
                                 "Slot %s of type %s succeeded "
90
0
                                 "with an exception set",
91
0
                                 slot_name, Py_TYPE(obj)->tp_name);
92
0
        }
93
0
    }
94
0
    return 1;
95
0
}
96
97
98
/* --- Core PyObject call functions ------------------------------- */
99
100
/* Call a callable Python object without any arguments */
101
PyObject *
102
PyObject_CallNoArgs(PyObject *func)
103
350
{
104
350
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
105
350
    PyThreadState *tstate = _PyThreadState_GET();
106
350
    return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
107
350
}
108
109
110
PyObject *
111
_PyObject_VectorcallDictTstate(PyThreadState *tstate, PyObject *callable,
112
                               PyObject *const *args, size_t nargsf,
113
                               PyObject *kwargs)
114
70.0M
{
115
70.0M
    assert(callable != NULL);
116
117
    /* PyObject_VectorcallDict() must not be called with an exception set,
118
       because it can clear it (directly or indirectly) and so the
119
       caller loses its exception */
120
70.0M
    assert(!_PyErr_Occurred(tstate));
121
122
70.0M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
123
70.0M
    assert(nargs >= 0);
124
70.0M
    assert(nargs == 0 || args != NULL);
125
70.0M
    assert(kwargs == NULL || PyDict_Check(kwargs));
126
127
70.0M
    vectorcallfunc func = PyVectorcall_Function(callable);
128
70.0M
    if (func == NULL) {
129
        /* Use tp_call instead */
130
5.69k
        return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs);
131
5.69k
    }
132
133
70.0M
    PyObject *res;
134
70.0M
    if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
135
61.4M
        res = func(callable, args, nargsf, NULL);
136
61.4M
    }
137
8.65M
    else {
138
8.65M
        PyObject *kwnames;
139
8.65M
        PyObject *const *newargs;
140
8.65M
        newargs = _PyStack_UnpackDict(tstate,
141
8.65M
                                      args, nargs,
142
8.65M
                                      kwargs, &kwnames);
143
8.65M
        if (newargs == NULL) {
144
0
            return NULL;
145
0
        }
146
8.65M
        res = func(callable, newargs,
147
8.65M
                   nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
148
8.65M
        _PyStack_UnpackDict_Free(newargs, nargs, kwnames);
149
8.65M
    }
150
70.0M
    return _Py_CheckFunctionResult(tstate, callable, res, NULL);
151
70.0M
}
152
153
154
PyObject *
155
PyObject_VectorcallDict(PyObject *callable, PyObject *const *args,
156
                       size_t nargsf, PyObject *kwargs)
157
308k
{
158
308k
    PyThreadState *tstate = _PyThreadState_GET();
159
308k
    return _PyObject_VectorcallDictTstate(tstate, callable, args, nargsf, kwargs);
160
308k
}
161
162
static void
163
object_is_not_callable(PyThreadState *tstate, PyObject *callable)
164
0
{
165
0
    if (Py_IS_TYPE(callable, &PyModule_Type)) {
166
        // >>> import pprint
167
        // >>> pprint(thing)
168
        // Traceback (most recent call last):
169
        //   File "<stdin>", line 1, in <module>
170
        // TypeError: 'module' object is not callable. Did you mean: 'pprint.pprint(...)'?
171
0
        PyObject *name = PyModule_GetNameObject(callable);
172
0
        if (name == NULL) {
173
0
            _PyErr_Clear(tstate);
174
0
            goto basic_type_error;
175
0
        }
176
0
        PyObject *attr;
177
0
        int res = PyObject_GetOptionalAttr(callable, name, &attr);
178
0
        if (res < 0) {
179
0
            _PyErr_Clear(tstate);
180
0
        }
181
0
        else if (res > 0 && PyCallable_Check(attr)) {
182
0
            _PyErr_Format(tstate, PyExc_TypeError,
183
0
                          "'%.200s' object is not callable. "
184
0
                          "Did you mean: '%U.%U(...)'?",
185
0
                          Py_TYPE(callable)->tp_name, name, name);
186
0
            Py_DECREF(attr);
187
0
            Py_DECREF(name);
188
0
            return;
189
0
        }
190
0
        Py_XDECREF(attr);
191
0
        Py_DECREF(name);
192
0
    }
193
0
basic_type_error:
194
0
    _PyErr_Format(tstate, PyExc_TypeError, "'%.200s' object is not callable",
195
0
                  Py_TYPE(callable)->tp_name);
196
0
}
197
198
199
PyObject *
200
_PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable,
201
                     PyObject *const *args, Py_ssize_t nargs,
202
                     PyObject *keywords)
203
136M
{
204
136M
    assert(nargs >= 0);
205
136M
    assert(nargs == 0 || args != NULL);
206
136M
    assert(keywords == NULL || PyTuple_Check(keywords) || PyDict_Check(keywords));
207
208
    /* Slow path: build a temporary tuple for positional arguments and a
209
     * temporary dictionary for keyword arguments (if any) */
210
136M
    ternaryfunc call = Py_TYPE(callable)->tp_call;
211
136M
    if (call == NULL) {
212
0
        object_is_not_callable(tstate, callable);
213
0
        return NULL;
214
0
    }
215
216
136M
    PyObject *argstuple = PyTuple_FromArray(args, nargs);
217
136M
    if (argstuple == NULL) {
218
0
        return NULL;
219
0
    }
220
221
136M
    PyObject *kwdict;
222
136M
    if (keywords == NULL || PyDict_Check(keywords)) {
223
127M
        kwdict = keywords;
224
127M
    }
225
8.87M
    else {
226
8.87M
        if (PyTuple_GET_SIZE(keywords)) {
227
8.87M
            assert(args != NULL);
228
8.87M
            kwdict = _PyStack_AsDict(args + nargs, keywords);
229
8.87M
            if (kwdict == NULL) {
230
0
                Py_DECREF(argstuple);
231
0
                return NULL;
232
0
            }
233
8.87M
        }
234
0
        else {
235
0
            keywords = kwdict = NULL;
236
0
        }
237
8.87M
    }
238
239
136M
    PyObject *result = NULL;
240
136M
    if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object") == 0)
241
136M
    {
242
136M
        result = _PyCFunctionWithKeywords_TrampolineCall(
243
136M
            (PyCFunctionWithKeywords)call, callable, argstuple, kwdict);
244
136M
        _Py_LeaveRecursiveCallTstate(tstate);
245
136M
    }
246
247
136M
    Py_DECREF(argstuple);
248
136M
    if (kwdict != keywords) {
249
8.87M
        Py_DECREF(kwdict);
250
8.87M
    }
251
252
136M
    return _Py_CheckFunctionResult(tstate, callable, result, NULL);
253
136M
}
254
255
256
vectorcallfunc
257
PyVectorcall_Function(PyObject *callable)
258
115M
{
259
115M
    return _PyVectorcall_FunctionInline(callable);
260
115M
}
261
262
263
static PyObject *
264
_PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
265
                   PyObject *callable, PyObject *tuple, PyObject *kwargs)
266
34.1M
{
267
34.1M
    assert(func != NULL);
268
269
34.1M
    Py_ssize_t nargs = PyTuple_GET_SIZE(tuple);
270
271
    /* Fast path for no keywords */
272
34.1M
    if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
273
30.6M
        return func(callable, _PyTuple_ITEMS(tuple), nargs, NULL);
274
30.6M
    }
275
276
    /* Convert arguments & call */
277
3.57M
    PyObject *const *args;
278
3.57M
    PyObject *kwnames;
279
3.57M
    args = _PyStack_UnpackDict(tstate,
280
3.57M
                               _PyTuple_ITEMS(tuple), nargs,
281
3.57M
                               kwargs, &kwnames);
282
3.57M
    if (args == NULL) {
283
0
        return NULL;
284
0
    }
285
3.57M
    PyObject *result = func(callable, args,
286
3.57M
                            nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
287
3.57M
    _PyStack_UnpackDict_Free(args, nargs, kwnames);
288
289
3.57M
    return _Py_CheckFunctionResult(tstate, callable, result, NULL);
290
3.57M
}
291
292
293
PyObject *
294
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
295
0
{
296
0
    PyThreadState *tstate = _PyThreadState_GET();
297
298
    /* get vectorcallfunc as in _PyVectorcall_Function, but without
299
     * the Py_TPFLAGS_HAVE_VECTORCALL check */
300
0
    Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset;
301
0
    if (offset <= 0) {
302
0
        _PyErr_Format(tstate, PyExc_TypeError,
303
0
                      "'%.200s' object does not support vectorcall",
304
0
                      Py_TYPE(callable)->tp_name);
305
0
        return NULL;
306
0
    }
307
0
    assert(PyCallable_Check(callable));
308
309
0
    vectorcallfunc func;
310
0
    memcpy(&func, (char *) callable + offset, sizeof(func));
311
0
    if (func == NULL) {
312
0
        _PyErr_Format(tstate, PyExc_TypeError,
313
0
                      "'%.200s' object does not support vectorcall",
314
0
                      Py_TYPE(callable)->tp_name);
315
0
        return NULL;
316
0
    }
317
318
0
    return _PyVectorcall_Call(tstate, func, callable, tuple, kwargs);
319
0
}
320
321
322
PyObject *
323
PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
324
                     size_t nargsf, PyObject *kwnames)
325
250M
{
326
250M
    PyThreadState *tstate = _PyThreadState_GET();
327
250M
    return _PyObject_VectorcallTstate(tstate, callable,
328
250M
                                      args, nargsf, kwnames);
329
250M
}
330
331
332
PyObject *
333
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
334
               PyObject *args, PyObject *kwargs)
335
45.6M
{
336
45.6M
    ternaryfunc call;
337
45.6M
    PyObject *result;
338
339
    /* PyObject_Call() must not be called with an exception set,
340
       because it can clear it (directly or indirectly) and so the
341
       caller loses its exception */
342
45.6M
    assert(!_PyErr_Occurred(tstate));
343
45.6M
    assert(PyTuple_Check(args));
344
45.6M
    assert(kwargs == NULL || PyDict_Check(kwargs));
345
45.6M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
346
45.6M
    vectorcallfunc vector_func = PyVectorcall_Function(callable);
347
45.6M
    if (vector_func != NULL) {
348
34.1M
        return _PyVectorcall_Call(tstate, vector_func, callable, args, kwargs);
349
34.1M
    }
350
11.4M
    else {
351
11.4M
        call = Py_TYPE(callable)->tp_call;
352
11.4M
        if (call == NULL) {
353
0
            object_is_not_callable(tstate, callable);
354
0
            return NULL;
355
0
        }
356
357
11.4M
        if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
358
0
            return NULL;
359
0
        }
360
361
11.4M
        result = (*call)(callable, args, kwargs);
362
363
11.4M
        _Py_LeaveRecursiveCallTstate(tstate);
364
365
11.4M
        return _Py_CheckFunctionResult(tstate, callable, result, NULL);
366
11.4M
    }
367
45.6M
}
368
369
PyObject *
370
PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
371
45.5M
{
372
45.5M
    PyThreadState *tstate = _PyThreadState_GET();
373
45.5M
    return _PyObject_Call(tstate, callable, args, kwargs);
374
45.5M
}
375
376
377
/* Function removed in the Python 3.13 API but kept in the stable ABI. */
378
PyAPI_FUNC(PyObject *)
379
PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
380
0
{
381
0
    return PyObject_Call(callable, args, kwargs);
382
0
}
383
384
385
PyObject *
386
PyObject_CallOneArg(PyObject *func, PyObject *arg)
387
70.2M
{
388
70.2M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
389
70.2M
    assert(arg != NULL);
390
70.2M
    PyObject *_args[2];
391
70.2M
    PyObject **args = _args + 1;  // For PY_VECTORCALL_ARGUMENTS_OFFSET
392
70.2M
    args[0] = arg;
393
70.2M
    PyThreadState *tstate = _PyThreadState_GET();
394
70.2M
    size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
395
70.2M
    return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
396
70.2M
}
397
398
399
/* --- PyFunction call functions ---------------------------------- */
400
401
PyObject *
402
_PyFunction_Vectorcall(PyObject *func, PyObject* const* stack,
403
                       size_t nargsf, PyObject *kwnames)
404
223M
{
405
223M
    assert(PyFunction_Check(func));
406
223M
    PyFunctionObject *f = (PyFunctionObject *)func;
407
223M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
408
223M
    assert(nargs >= 0);
409
223M
    PyThreadState *tstate = _PyThreadState_GET();
410
223M
    assert(nargs == 0 || stack != NULL);
411
223M
    EVAL_CALL_STAT_INC(EVAL_CALL_FUNCTION_VECTORCALL);
412
223M
    if (((PyCodeObject *)f->func_code)->co_flags & CO_OPTIMIZED) {
413
223M
        return _PyEval_Vector(tstate, f, NULL, stack, nargs, kwnames);
414
223M
    }
415
0
    else {
416
0
        return _PyEval_Vector(tstate, f, f->func_globals, stack, nargs, kwnames);
417
0
    }
418
223M
}
419
420
/* --- More complex call functions -------------------------------- */
421
422
/* External interface to call any callable object.
423
   The args must be a tuple or NULL.  The kwargs must be a dict or NULL.
424
   Function removed in Python 3.13 API but kept in the stable ABI. */
425
PyAPI_FUNC(PyObject*)
426
PyEval_CallObjectWithKeywords(PyObject *callable,
427
                              PyObject *args, PyObject *kwargs)
428
0
{
429
0
    PyThreadState *tstate = _PyThreadState_GET();
430
#ifdef Py_DEBUG
431
    /* PyEval_CallObjectWithKeywords() must not be called with an exception
432
       set. It raises a new exception if parameters are invalid or if
433
       PyTuple_New() fails, and so the original exception is lost. */
434
    assert(!_PyErr_Occurred(tstate));
435
#endif
436
437
0
    if (args != NULL && !PyTuple_Check(args)) {
438
0
        _PyErr_SetString(tstate, PyExc_TypeError,
439
0
                         "argument list must be a tuple");
440
0
        return NULL;
441
0
    }
442
443
0
    if (kwargs != NULL && !PyDict_Check(kwargs)) {
444
0
        _PyErr_SetString(tstate, PyExc_TypeError,
445
0
                         "keyword list must be a dictionary");
446
0
        return NULL;
447
0
    }
448
449
0
    if (args == NULL) {
450
0
        return _PyObject_VectorcallDictTstate(tstate, callable,
451
0
                                              NULL, 0, kwargs);
452
0
    }
453
0
    else {
454
0
        return _PyObject_Call(tstate, callable, args, kwargs);
455
0
    }
456
0
}
457
458
459
PyObject *
460
PyObject_CallObject(PyObject *callable, PyObject *args)
461
150k
{
462
150k
    PyThreadState *tstate = _PyThreadState_GET();
463
150k
    assert(!_PyErr_Occurred(tstate));
464
150k
    if (args == NULL) {
465
0
        return _PyObject_CallNoArgsTstate(tstate, callable);
466
0
    }
467
150k
    if (!PyTuple_Check(args)) {
468
0
        _PyErr_SetString(tstate, PyExc_TypeError,
469
0
                         "argument list must be a tuple");
470
0
        return NULL;
471
0
    }
472
150k
    return _PyObject_Call(tstate, callable, args, NULL);
473
150k
}
474
475
476
/* Call callable(obj, *args, **kwargs). */
477
PyObject *
478
_PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable,
479
                       PyObject *obj, PyObject *args, PyObject *kwargs)
480
69.7M
{
481
69.7M
    assert(PyTuple_Check(args));
482
483
69.7M
    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
484
69.7M
    PyObject **stack;
485
486
69.7M
    Py_ssize_t argcount = PyTuple_GET_SIZE(args);
487
69.7M
    if (argcount + 1 <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
488
69.5M
        stack = small_stack;
489
69.5M
    }
490
202k
    else {
491
202k
        stack = PyMem_Malloc((argcount + 1) * sizeof(PyObject *));
492
202k
        if (stack == NULL) {
493
0
            PyErr_NoMemory();
494
0
            return NULL;
495
0
        }
496
202k
    }
497
498
    /* use borrowed references */
499
69.7M
    stack[0] = obj;
500
69.7M
    memcpy(&stack[1],
501
69.7M
           _PyTuple_ITEMS(args),
502
69.7M
           argcount * sizeof(PyObject *));
503
504
69.7M
    PyObject *result = _PyObject_VectorcallDictTstate(tstate, callable,
505
69.7M
                                                      stack, argcount + 1,
506
69.7M
                                                      kwargs);
507
69.7M
    if (stack != small_stack) {
508
202k
        PyMem_Free(stack);
509
202k
    }
510
69.7M
    return result;
511
69.7M
}
512
513
514
/* --- Call with a format string ---------------------------------- */
515
516
static PyObject *
517
_PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable,
518
                         const char *format, va_list va)
519
5.70M
{
520
5.70M
    PyObject* small_stack[_PY_FASTCALL_SMALL_STACK];
521
5.70M
    const Py_ssize_t small_stack_len = Py_ARRAY_LENGTH(small_stack);
522
5.70M
    PyObject **stack;
523
5.70M
    Py_ssize_t nargs, i;
524
5.70M
    PyObject *result;
525
526
5.70M
    if (callable == NULL) {
527
0
        return null_error(tstate);
528
0
    }
529
530
5.70M
    if (!format || !*format) {
531
0
        return _PyObject_CallNoArgsTstate(tstate, callable);
532
0
    }
533
534
5.70M
    stack = _Py_VaBuildStack(small_stack, small_stack_len,
535
5.70M
                             format, va, &nargs);
536
5.70M
    if (stack == NULL) {
537
0
        return NULL;
538
0
    }
539
5.70M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
540
5.70M
    if (nargs == 1 && PyTuple_Check(stack[0])) {
541
        /* Special cases for backward compatibility:
542
           - PyObject_CallFunction(func, "O", tuple) calls func(*tuple)
543
           - PyObject_CallFunction(func, "(OOO)", arg1, arg2, arg3) calls
544
             func(*(arg1, arg2, arg3)): func(arg1, arg2, arg3) */
545
648
        PyObject *args = stack[0];
546
648
        result = _PyObject_VectorcallTstate(tstate, callable,
547
648
                                            _PyTuple_ITEMS(args),
548
648
                                            PyTuple_GET_SIZE(args),
549
648
                                            NULL);
550
648
    }
551
5.70M
    else {
552
5.70M
        result = _PyObject_VectorcallTstate(tstate, callable,
553
5.70M
                                            stack, nargs, NULL);
554
5.70M
    }
555
556
33.7M
    for (i = 0; i < nargs; ++i) {
557
28.0M
        Py_DECREF(stack[i]);
558
28.0M
    }
559
5.70M
    if (stack != small_stack) {
560
0
        PyMem_Free(stack);
561
0
    }
562
5.70M
    return result;
563
5.70M
}
564
565
566
PyObject *
567
PyObject_CallFunction(PyObject *callable, const char *format, ...)
568
5.70M
{
569
5.70M
    va_list va;
570
5.70M
    PyObject *result;
571
5.70M
    PyThreadState *tstate = _PyThreadState_GET();
572
573
5.70M
    va_start(va, format);
574
5.70M
    result = _PyObject_CallFunctionVa(tstate, callable, format, va);
575
5.70M
    va_end(va);
576
577
5.70M
    return result;
578
5.70M
}
579
580
581
/* PyEval_CallFunction is exact copy of PyObject_CallFunction.
582
   Function removed in Python 3.13 API but kept in the stable ABI. */
583
PyAPI_FUNC(PyObject*)
584
PyEval_CallFunction(PyObject *callable, const char *format, ...)
585
0
{
586
0
    va_list va;
587
0
    PyObject *result;
588
0
    PyThreadState *tstate = _PyThreadState_GET();
589
590
0
    va_start(va, format);
591
0
    result = _PyObject_CallFunctionVa(tstate, callable, format, va);
592
0
    va_end(va);
593
594
0
    return result;
595
0
}
596
597
598
/* _PyObject_CallFunction_SizeT is exact copy of PyObject_CallFunction.
599
 * This function must be kept because it is part of the stable ABI.
600
 */
601
PyAPI_FUNC(PyObject *)  /* abi_only */
602
_PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
603
0
{
604
0
    PyThreadState *tstate = _PyThreadState_GET();
605
606
0
    va_list va;
607
0
    va_start(va, format);
608
0
    PyObject *result = _PyObject_CallFunctionVa(tstate, callable, format, va);
609
0
    va_end(va);
610
611
0
    return result;
612
0
}
613
614
615
static PyObject *
616
callmethod(PyThreadState *tstate, PyObject *obj, PyObject *name,
617
           const char *format, va_list va)
618
1.42M
{
619
1.42M
    PyObject *result = NULL;
620
621
1.42M
    _PyCStackRef self, method;
622
1.42M
    _PyThreadState_PushCStackRef(tstate, &self);
623
1.42M
    _PyThreadState_PushCStackRef(tstate, &method);
624
1.42M
    self.ref = PyStackRef_FromPyObjectBorrow(obj);
625
626
1.42M
    int res = _PyObject_GetMethodStackRef(tstate, &self.ref, name, &method.ref);
627
1.42M
    if (res < 0) {
628
0
        goto exit;
629
0
    }
630
631
1.42M
    PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
632
1.42M
    PyObject *self_obj = PyStackRef_AsPyObjectBorrow(self.ref);
633
634
1.42M
    if (!PyCallable_Check(callable)) {
635
0
        _PyErr_Format(tstate, PyExc_TypeError,
636
0
                      "attribute of type '%.200s' is not callable",
637
0
                      Py_TYPE(callable)->tp_name);
638
0
        goto exit;
639
0
    }
640
641
    /* Build the positional arguments from the format string. */
642
1.42M
    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
643
1.42M
    Py_ssize_t nargs = 0;
644
1.42M
    PyObject **built = NULL;
645
1.42M
    if (format != NULL && *format != '\0') {
646
1.42M
        built = _Py_VaBuildStack(small_stack, _PY_FASTCALL_SMALL_STACK,
647
1.42M
                                 format, va, &nargs);
648
1.42M
        if (built == NULL) {
649
0
            goto exit;
650
0
        }
651
1.42M
    }
652
653
    /* Backward compat: a single tuple from "O" is unpacked. */
654
1.42M
    PyObject *const *args = built;
655
1.42M
    Py_ssize_t n = nargs;
656
1.42M
    if (nargs == 1 && PyTuple_Check(built[0])) {
657
0
        args = _PyTuple_ITEMS(built[0]);
658
0
        n = PyTuple_GET_SIZE(built[0]);
659
0
    }
660
661
1.42M
    if (self_obj != NULL) {
662
1.41M
        result = _PyObject_VectorcallPrepend(tstate, callable, self_obj, args, n, NULL);
663
1.41M
    }
664
4.92k
    else {
665
4.92k
        result = _PyObject_VectorcallTstate(tstate, callable, args, n, NULL);
666
4.92k
    }
667
668
4.25M
    for (Py_ssize_t i = 0; i < nargs; i++) {
669
2.83M
        Py_DECREF(built[i]);
670
2.83M
    }
671
1.42M
    if (built != small_stack) {
672
599
        PyMem_Free(built);
673
599
    }
674
675
1.42M
exit:
676
1.42M
    _PyThreadState_PopCStackRef(tstate, &method);
677
1.42M
    _PyThreadState_PopCStackRef(tstate, &self);
678
1.42M
    return result;
679
1.42M
}
680
681
PyObject *
682
PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...)
683
5.04k
{
684
5.04k
    PyThreadState *tstate = _PyThreadState_GET();
685
686
5.04k
    if (obj == NULL || name == NULL) {
687
0
        return null_error(tstate);
688
0
    }
689
690
5.04k
    PyObject *name_obj = PyUnicode_FromString(name);
691
5.04k
    if (name_obj == NULL) {
692
0
        return NULL;
693
0
    }
694
695
5.04k
    va_list va;
696
5.04k
    va_start(va, format);
697
5.04k
    PyObject *retval = callmethod(tstate, obj, name_obj, format, va);
698
5.04k
    va_end(va);
699
700
5.04k
    Py_DECREF(name_obj);
701
5.04k
    return retval;
702
5.04k
}
703
704
705
/* PyEval_CallMethod is exact copy of PyObject_CallMethod.
706
   Function removed in Python 3.13 API but kept in the stable ABI. */
707
PyAPI_FUNC(PyObject*)
708
PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
709
0
{
710
0
    PyThreadState *tstate = _PyThreadState_GET();
711
0
    if (obj == NULL || name == NULL) {
712
0
        return null_error(tstate);
713
0
    }
714
715
0
    PyObject *name_obj = PyUnicode_FromString(name);
716
0
    if (name_obj == NULL) {
717
0
        return NULL;
718
0
    }
719
720
0
    va_list va;
721
0
    va_start(va, format);
722
0
    PyObject *retval = callmethod(tstate, obj, name_obj, format, va);
723
0
    va_end(va);
724
725
0
    Py_DECREF(name_obj);
726
0
    return retval;
727
0
}
728
729
730
PyObject *
731
_PyObject_CallMethod(PyObject *obj, PyObject *name,
732
                     const char *format, ...)
733
1.41M
{
734
1.41M
    PyThreadState *tstate = _PyThreadState_GET();
735
1.41M
    if (obj == NULL || name == NULL) {
736
0
        return null_error(tstate);
737
0
    }
738
739
1.41M
    va_list va;
740
1.41M
    va_start(va, format);
741
1.41M
    PyObject *retval = callmethod(tstate, obj, name, format, va);
742
1.41M
    va_end(va);
743
744
1.41M
    return retval;
745
1.41M
}
746
747
748
PyObject *
749
_PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
750
                       const char *format, ...)
751
0
{
752
0
    PyThreadState *tstate = _PyThreadState_GET();
753
0
    if (obj == NULL || name == NULL) {
754
0
        return null_error(tstate);
755
0
    }
756
757
0
_Py_COMP_DIAG_PUSH
758
0
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
759
0
    PyObject *name_obj = _PyUnicode_FromId(name); /* borrowed */
760
0
_Py_COMP_DIAG_POP
761
0
    if (name_obj == NULL) {
762
0
        return NULL;
763
0
    }
764
765
0
    va_list va;
766
0
    va_start(va, format);
767
0
    PyObject *retval = callmethod(tstate, obj, name_obj, format, va);
768
0
    va_end(va);
769
770
0
    return retval;
771
0
}
772
773
774
// _PyObject_CallMethod_SizeT is exact copy of PyObject_CallMethod.
775
// This function must be kept because it is part of the stable ABI.
776
PyAPI_FUNC(PyObject *)  /* abi_only */
777
_PyObject_CallMethod_SizeT(PyObject *obj, const char *name,
778
                           const char *format, ...)
779
0
{
780
0
    PyThreadState *tstate = _PyThreadState_GET();
781
0
    if (obj == NULL || name == NULL) {
782
0
        return null_error(tstate);
783
0
    }
784
785
0
    PyObject *name_obj = PyUnicode_FromString(name);
786
0
    if (name_obj == NULL) {
787
0
        return NULL;
788
0
    }
789
790
0
    va_list va;
791
0
    va_start(va, format);
792
0
    PyObject *retval = callmethod(tstate, obj, name_obj, format, va);
793
0
    va_end(va);
794
795
0
    Py_DECREF(name_obj);
796
0
    return retval;
797
0
}
798
799
800
/* --- Call with "..." arguments ---------------------------------- */
801
802
static PyObject *
803
object_vacall(PyThreadState *tstate, PyObject *base,
804
              PyObject *callable, va_list vargs)
805
257k
{
806
257k
    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
807
257k
    PyObject **stack;
808
257k
    Py_ssize_t nargs;
809
257k
    PyObject *result;
810
257k
    Py_ssize_t i;
811
257k
    va_list countva;
812
813
257k
    if (callable == NULL) {
814
0
        return null_error(tstate);
815
0
    }
816
817
    /* Count the number of arguments */
818
257k
    va_copy(countva, vargs);
819
257k
    nargs = base ? 1 : 0;
820
1.79M
    while (1) {
821
1.79M
        PyObject *arg = va_arg(countva, PyObject *);
822
1.79M
        if (arg == NULL) {
823
257k
            break;
824
257k
        }
825
1.53M
        nargs++;
826
1.53M
    }
827
257k
    va_end(countva);
828
829
    /* Copy arguments */
830
257k
    if (nargs <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
831
81.5k
        stack = small_stack;
832
81.5k
    }
833
175k
    else {
834
175k
        stack = PyMem_Malloc(nargs * sizeof(stack[0]));
835
175k
        if (stack == NULL) {
836
0
            PyErr_NoMemory();
837
0
            return NULL;
838
0
        }
839
175k
    }
840
841
257k
    i = 0;
842
257k
    if (base) {
843
47.4k
        stack[i++] = base;
844
47.4k
    }
845
846
1.79M
    for (; i < nargs; ++i) {
847
1.53M
        stack[i] = va_arg(vargs, PyObject *);
848
1.53M
    }
849
850
#ifdef Py_STATS
851
    if (PyFunction_Check(callable)) {
852
        EVAL_CALL_STAT_INC(EVAL_CALL_API);
853
    }
854
#endif
855
    /* Call the function */
856
257k
    result = _PyObject_VectorcallTstate(tstate, callable, stack, nargs, NULL);
857
858
257k
    if (stack != small_stack) {
859
175k
        PyMem_Free(stack);
860
175k
    }
861
257k
    return result;
862
257k
}
863
864
PyObject *
865
_PyObject_VectorcallPrepend(PyThreadState *tstate, PyObject *callable,
866
                            PyObject *arg, PyObject *const *args,
867
                            size_t nargsf, PyObject *kwnames)
868
45.9M
{
869
45.9M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
870
45.9M
    assert(nargs == 0 || args[nargs-1]);
871
872
45.9M
    PyObject *result;
873
45.9M
    if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) {
874
        /* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */
875
3.57M
        PyObject **newargs = (PyObject**)args - 1;
876
3.57M
        nargs += 1;
877
3.57M
        PyObject *tmp = newargs[0];
878
3.57M
        newargs[0] = arg;
879
3.57M
        assert(newargs[nargs-1]);
880
3.57M
        result = _PyObject_VectorcallTstate(tstate, callable, newargs,
881
3.57M
                                            nargs, kwnames);
882
3.57M
        newargs[0] = tmp;
883
3.57M
    }
884
42.4M
    else {
885
42.4M
        Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
886
42.4M
        Py_ssize_t totalargs = nargs + nkwargs;
887
42.4M
        if (totalargs == 0) {
888
852
            return _PyObject_VectorcallTstate(tstate, callable, &arg, 1, NULL);
889
852
        }
890
891
42.4M
        PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
892
42.4M
        PyObject **newargs;
893
42.4M
        if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
894
42.4M
            newargs = newargs_stack;
895
42.4M
        }
896
2.80k
        else {
897
2.80k
            newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *));
898
2.80k
            if (newargs == NULL) {
899
0
                _PyErr_NoMemory(tstate);
900
0
                return NULL;
901
0
            }
902
2.80k
        }
903
        /* use borrowed references */
904
42.4M
        newargs[0] = arg;
905
        /* bpo-37138: since totalargs > 0, it's impossible that args is NULL.
906
         * We need this, since calling memcpy() with a NULL pointer is
907
         * undefined behaviour. */
908
42.4M
        assert(args != NULL);
909
42.4M
        memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
910
42.4M
        result = _PyObject_VectorcallTstate(tstate, callable,
911
42.4M
                                            newargs, nargs+1, kwnames);
912
42.4M
        if (newargs != newargs_stack) {
913
2.80k
            PyMem_Free(newargs);
914
2.80k
        }
915
42.4M
    }
916
45.9M
    return result;
917
45.9M
}
918
919
PyObject *
920
PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
921
                           size_t nargsf, PyObject *kwnames)
922
3.88M
{
923
3.88M
    assert(name != NULL);
924
3.88M
    assert(args != NULL);
925
3.88M
    assert(PyVectorcall_NARGS(nargsf) >= 1);
926
927
3.88M
    PyThreadState *tstate = _PyThreadState_GET();
928
3.88M
    _PyCStackRef self, method;
929
3.88M
    _PyThreadState_PushCStackRef(tstate, &self);
930
3.88M
    _PyThreadState_PushCStackRef(tstate, &method);
931
    /* Use args[0] as "self" argument */
932
3.88M
    self.ref = PyStackRef_FromPyObjectBorrow(args[0]);
933
3.88M
    int unbound = _PyObject_GetMethodStackRef(tstate, &self.ref, name, &method.ref);
934
3.88M
    if (unbound < 0) {
935
5
        _PyThreadState_PopCStackRef(tstate, &method);
936
5
        _PyThreadState_PopCStackRef(tstate, &self);
937
5
        return NULL;
938
5
    }
939
940
3.88M
    PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
941
3.88M
    PyObject *self_obj = PyStackRef_AsPyObjectBorrow(self.ref);
942
3.88M
    PyObject *result;
943
944
3.88M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_METHOD, callable);
945
3.88M
    if (self_obj == NULL) {
946
        /* Skip "self". We can keep PY_VECTORCALL_ARGUMENTS_OFFSET since
947
         * args[-1] in the onward call is args[0] here. */
948
25.4k
        result = _PyObject_VectorcallTstate(tstate, callable,
949
25.4k
                                            args + 1, nargsf - 1, kwnames);
950
25.4k
    }
951
3.85M
    else if (self_obj == args[0]) {
952
        /* We must remove PY_VECTORCALL_ARGUMENTS_OFFSET since
953
         * that would be interpreted as allowing to change args[-1] */
954
3.85M
        result = _PyObject_VectorcallTstate(tstate, callable, args,
955
3.85M
                                            nargsf & ~PY_VECTORCALL_ARGUMENTS_OFFSET,
956
3.85M
                                            kwnames);
957
3.85M
    }
958
0
    else {
959
        /* classmethod: self_obj is the type, not args[0]. Replace
960
         * args[0] with self_obj and call the underlying callable. */
961
0
        result = _PyObject_VectorcallPrepend(tstate, callable, self_obj,
962
0
                                             args + 1, nargsf - 1, kwnames);
963
0
    }
964
3.88M
    _PyThreadState_PopCStackRef(tstate, &method);
965
3.88M
    _PyThreadState_PopCStackRef(tstate, &self);
966
3.88M
    return result;
967
3.88M
}
968
969
970
PyObject *
971
PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...)
972
60.9k
{
973
60.9k
    PyThreadState *tstate = _PyThreadState_GET();
974
60.9k
    if (obj == NULL || name == NULL) {
975
0
        return null_error(tstate);
976
0
    }
977
978
60.9k
    _PyCStackRef self, method;
979
60.9k
    _PyThreadState_PushCStackRef(tstate, &self);
980
60.9k
    _PyThreadState_PushCStackRef(tstate, &method);
981
60.9k
    self.ref = PyStackRef_FromPyObjectBorrow(obj);
982
60.9k
    int res = _PyObject_GetMethodStackRef(tstate, &self.ref, name, &method.ref);
983
60.9k
    if (res < 0) {
984
0
        _PyThreadState_PopCStackRef(tstate, &method);
985
0
        _PyThreadState_PopCStackRef(tstate, &self);
986
0
        return NULL;
987
0
    }
988
60.9k
    PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
989
60.9k
    PyObject *self_obj = PyStackRef_AsPyObjectBorrow(self.ref);
990
991
60.9k
    va_list vargs;
992
60.9k
    va_start(vargs, name);
993
60.9k
    PyObject *result = object_vacall(tstate, self_obj, callable, vargs);
994
60.9k
    va_end(vargs);
995
996
60.9k
    _PyThreadState_PopCStackRef(tstate, &method);
997
60.9k
    _PyThreadState_PopCStackRef(tstate, &self);
998
60.9k
    return result;
999
60.9k
}
1000
1001
1002
PyObject *
1003
PyObject_CallFunctionObjArgs(PyObject *callable, ...)
1004
196k
{
1005
196k
    PyThreadState *tstate = _PyThreadState_GET();
1006
196k
    va_list vargs;
1007
196k
    PyObject *result;
1008
1009
196k
    va_start(vargs, callable);
1010
196k
    result = object_vacall(tstate, NULL, callable, vargs);
1011
196k
    va_end(vargs);
1012
1013
196k
    return result;
1014
196k
}
1015
1016
1017
/* --- PyStack functions ------------------------------------------ */
1018
1019
PyObject *
1020
_PyStack_AsDict(PyObject *const *values, PyObject *kwnames)
1021
8.87M
{
1022
8.87M
    Py_ssize_t nkwargs;
1023
1024
8.87M
    assert(kwnames != NULL);
1025
8.87M
    nkwargs = PyTuple_GET_SIZE(kwnames);
1026
8.87M
    return _PyDict_FromItems(&PyTuple_GET_ITEM(kwnames, 0), 1,
1027
8.87M
                             values, 1, nkwargs);
1028
8.87M
}
1029
1030
1031
/* Convert (args, nargs, kwargs: dict) into a (stack, nargs, kwnames: tuple).
1032
1033
   Allocate a new argument vector and keyword names tuple. Return the argument
1034
   vector; return NULL with exception set on error. Return the keyword names
1035
   tuple in *p_kwnames.
1036
1037
   This also checks that all keyword names are strings. If not, a TypeError is
1038
   raised.
1039
1040
   The newly allocated argument vector supports PY_VECTORCALL_ARGUMENTS_OFFSET.
1041
1042
   The positional arguments are borrowed references from the input array
1043
   (which must be kept alive by the caller). The keyword argument values
1044
   are new references.
1045
1046
   When done, you must call _PyStack_UnpackDict_Free(stack, nargs, kwnames) */
1047
PyObject *const *
1048
_PyStack_UnpackDict(PyThreadState *tstate,
1049
                    PyObject *const *args, Py_ssize_t nargs,
1050
                    PyObject *kwargs, PyObject **p_kwnames)
1051
12.2M
{
1052
12.2M
    assert(nargs >= 0);
1053
12.2M
    assert(kwargs != NULL);
1054
12.2M
    assert(PyDict_Check(kwargs));
1055
1056
12.2M
    Py_ssize_t nkwargs = PyDict_GET_SIZE(kwargs);
1057
    /* Check for overflow in the PyMem_Malloc() call below. The subtraction
1058
     * in this check cannot overflow: both maxnargs and nkwargs are
1059
     * non-negative signed integers, so their difference fits in the type. */
1060
12.2M
    Py_ssize_t maxnargs = PY_SSIZE_T_MAX / sizeof(args[0]) - 1;
1061
12.2M
    if (nargs > maxnargs - nkwargs) {
1062
0
        _PyErr_NoMemory(tstate);
1063
0
        return NULL;
1064
0
    }
1065
1066
    /* Add 1 to support PY_VECTORCALL_ARGUMENTS_OFFSET */
1067
12.2M
    PyObject **stack = PyMem_Malloc((1 + nargs + nkwargs) * sizeof(args[0]));
1068
12.2M
    if (stack == NULL) {
1069
0
        _PyErr_NoMemory(tstate);
1070
0
        return NULL;
1071
0
    }
1072
1073
12.2M
    PyObject *kwnames = PyTuple_New(nkwargs);
1074
12.2M
    if (kwnames == NULL) {
1075
0
        PyMem_Free(stack);
1076
0
        return NULL;
1077
0
    }
1078
1079
12.2M
    stack++;  /* For PY_VECTORCALL_ARGUMENTS_OFFSET */
1080
1081
    /* Copy positional arguments (borrowed references) */
1082
22.1M
    for (Py_ssize_t i = 0; i < nargs; i++) {
1083
9.92M
        stack[i] = args[i];
1084
9.92M
    }
1085
1086
12.2M
    PyObject **kwstack = stack + nargs;
1087
    /* This loop doesn't support lookup function mutating the dictionary
1088
       to change its size. It's a deliberate choice for speed, this function is
1089
       called in the performance critical hot code. */
1090
12.2M
    Py_ssize_t pos = 0, i = 0;
1091
12.2M
    PyObject *key, *value;
1092
12.2M
    unsigned long keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS;
1093
26.9M
    while (PyDict_Next(kwargs, &pos, &key, &value)) {
1094
14.7M
        keys_are_strings &= Py_TYPE(key)->tp_flags;
1095
14.7M
        PyTuple_SET_ITEM(kwnames, i, Py_NewRef(key));
1096
14.7M
        kwstack[i] = Py_NewRef(value);
1097
14.7M
        i++;
1098
14.7M
    }
1099
1100
    /* keys_are_strings has the value Py_TPFLAGS_UNICODE_SUBCLASS if that
1101
     * flag is set for all keys. Otherwise, keys_are_strings equals 0.
1102
     * We do this check once at the end instead of inside the loop above
1103
     * because it simplifies the deallocation in the failing case.
1104
     * It happens to also make the loop above slightly more efficient. */
1105
12.2M
    if (!keys_are_strings) {
1106
0
        _PyErr_SetString(tstate, PyExc_TypeError,
1107
0
                         "keywords must be strings");
1108
0
        _PyStack_UnpackDict_Free(stack, nargs, kwnames);
1109
0
        return NULL;
1110
0
    }
1111
1112
12.2M
    *p_kwnames = kwnames;
1113
12.2M
    return stack;
1114
12.2M
}
1115
1116
void
1117
_PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs,
1118
                         PyObject *kwnames)
1119
12.2M
{
1120
    /* Only decref kwargs values, positional args are borrowed */
1121
12.2M
    Py_ssize_t nkwargs = PyTuple_GET_SIZE(kwnames);
1122
26.8M
    for (Py_ssize_t i = 0; i < nkwargs; i++) {
1123
14.6M
        Py_DECREF(stack[nargs + i]);
1124
14.6M
    }
1125
12.2M
    _PyStack_UnpackDict_FreeNoDecRef(stack, kwnames);
1126
12.2M
}
1127
1128
void
1129
_PyStack_UnpackDict_FreeNoDecRef(PyObject *const *stack, PyObject *kwnames)
1130
12.2M
{
1131
12.2M
    PyMem_Free((PyObject **)stack - 1);
1132
12.2M
    Py_DECREF(kwnames);
1133
12.2M
}
1134
1135
// Export for the stable ABI
1136
#undef PyVectorcall_NARGS
1137
Py_ssize_t
1138
PyVectorcall_NARGS(size_t n)
1139
0
{
1140
0
    return _PyVectorcall_NARGS(n);
1141
0
}