Coverage Report

Created: 2026-10-17 06:15

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
767M
{
28
767M
    assert((callable != NULL) ^ (where != NULL));
29
30
767M
    if (result == NULL) {
31
19.3M
        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
19.3M
    }
48
747M
    else {
49
747M
        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
747M
    }
70
767M
    return result;
71
767M
}
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
386
{
104
386
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
105
386
    PyThreadState *tstate = _PyThreadState_GET();
106
386
    return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
107
386
}
108
109
110
PyObject *
111
_PyObject_VectorcallDictTstate(PyThreadState *tstate, PyObject *callable,
112
                               PyObject *const *args, size_t nargsf,
113
                               PyObject *kwargs)
114
55.0M
{
115
55.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
55.0M
    assert(!_PyErr_Occurred(tstate));
121
122
55.0M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
123
55.0M
    assert(nargs >= 0);
124
55.0M
    assert(nargs == 0 || args != NULL);
125
55.0M
    assert(kwargs == NULL || PyDict_Check(kwargs));
126
127
55.0M
    vectorcallfunc func = PyVectorcall_Function(callable);
128
55.0M
    if (func == NULL) {
129
        /* Use tp_call instead */
130
5.51k
        return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs);
131
5.51k
    }
132
133
55.0M
    PyObject *res;
134
55.0M
    if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
135
47.0M
        res = func(callable, args, nargsf, NULL);
136
47.0M
    }
137
7.99M
    else {
138
7.99M
        PyObject *kwnames;
139
7.99M
        PyObject *const *newargs;
140
7.99M
        newargs = _PyStack_UnpackDict(tstate,
141
7.99M
                                      args, nargs,
142
7.99M
                                      kwargs, &kwnames);
143
7.99M
        if (newargs == NULL) {
144
0
            return NULL;
145
0
        }
146
7.99M
        res = func(callable, newargs,
147
7.99M
                   nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
148
7.99M
        _PyStack_UnpackDict_Free(newargs, nargs, kwnames);
149
7.99M
    }
150
55.0M
    return _Py_CheckFunctionResult(tstate, callable, res, NULL);
151
55.0M
}
152
153
154
PyObject *
155
PyObject_VectorcallDict(PyObject *callable, PyObject *const *args,
156
                       size_t nargsf, PyObject *kwargs)
157
252k
{
158
252k
    PyThreadState *tstate = _PyThreadState_GET();
159
252k
    return _PyObject_VectorcallDictTstate(tstate, callable, args, nargsf, kwargs);
160
252k
}
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
161M
{
204
161M
    assert(nargs >= 0);
205
161M
    assert(nargs == 0 || args != NULL);
206
161M
    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
161M
    ternaryfunc call = Py_TYPE(callable)->tp_call;
211
161M
    if (call == NULL) {
212
0
        object_is_not_callable(tstate, callable);
213
0
        return NULL;
214
0
    }
215
216
161M
    PyObject *argstuple = PyTuple_FromArray(args, nargs);
217
161M
    if (argstuple == NULL) {
218
0
        return NULL;
219
0
    }
220
221
161M
    PyObject *kwdict;
222
161M
    if (keywords == NULL || PyDict_Check(keywords)) {
223
153M
        kwdict = keywords;
224
153M
    }
225
8.27M
    else {
226
8.27M
        if (PyTuple_GET_SIZE(keywords)) {
227
8.27M
            assert(args != NULL);
228
8.27M
            kwdict = _PyStack_AsDict(args + nargs, keywords);
229
8.27M
            if (kwdict == NULL) {
230
0
                Py_DECREF(argstuple);
231
0
                return NULL;
232
0
            }
233
8.27M
        }
234
0
        else {
235
0
            keywords = kwdict = NULL;
236
0
        }
237
8.27M
    }
238
239
161M
    PyObject *result = NULL;
240
161M
    if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object") == 0)
241
161M
    {
242
161M
        result = _PyCFunctionWithKeywords_TrampolineCall(
243
161M
            (PyCFunctionWithKeywords)call, callable, argstuple, kwdict);
244
161M
        _Py_LeaveRecursiveCallTstate(tstate);
245
161M
    }
246
247
161M
    Py_DECREF(argstuple);
248
161M
    if (kwdict != keywords) {
249
8.27M
        Py_DECREF(kwdict);
250
8.27M
    }
251
252
161M
    return _Py_CheckFunctionResult(tstate, callable, result, NULL);
253
161M
}
254
255
256
vectorcallfunc
257
PyVectorcall_Function(PyObject *callable)
258
96.6M
{
259
96.6M
    return _PyVectorcall_FunctionInline(callable);
260
96.6M
}
261
262
263
static PyObject *
264
_PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
265
                   PyObject *callable, PyObject *tuple, PyObject *kwargs)
266
30.6M
{
267
30.6M
    assert(func != NULL);
268
269
30.6M
    Py_ssize_t nargs = PyTuple_GET_SIZE(tuple);
270
271
    /* Fast path for no keywords */
272
30.6M
    if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
273
27.2M
        return func(callable, _PyTuple_ITEMS(tuple), nargs, NULL);
274
27.2M
    }
275
276
    /* Convert arguments & call */
277
3.34M
    PyObject *const *args;
278
3.34M
    PyObject *kwnames;
279
3.34M
    args = _PyStack_UnpackDict(tstate,
280
3.34M
                               _PyTuple_ITEMS(tuple), nargs,
281
3.34M
                               kwargs, &kwnames);
282
3.34M
    if (args == NULL) {
283
0
        return NULL;
284
0
    }
285
3.34M
    PyObject *result = func(callable, args,
286
3.34M
                            nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
287
3.34M
    _PyStack_UnpackDict_Free(args, nargs, kwnames);
288
289
3.34M
    return _Py_CheckFunctionResult(tstate, callable, result, NULL);
290
3.34M
}
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
238M
{
326
238M
    PyThreadState *tstate = _PyThreadState_GET();
327
238M
    return _PyObject_VectorcallTstate(tstate, callable,
328
238M
                                      args, nargsf, kwnames);
329
238M
}
330
331
332
PyObject *
333
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
334
               PyObject *args, PyObject *kwargs)
335
41.4M
{
336
41.4M
    ternaryfunc call;
337
41.4M
    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
41.4M
    assert(!_PyErr_Occurred(tstate));
343
41.4M
    assert(PyTuple_Check(args));
344
41.4M
    assert(kwargs == NULL || PyDict_Check(kwargs));
345
41.4M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
346
41.4M
    vectorcallfunc vector_func = PyVectorcall_Function(callable);
347
41.4M
    if (vector_func != NULL) {
348
30.6M
        return _PyVectorcall_Call(tstate, vector_func, callable, args, kwargs);
349
30.6M
    }
350
10.8M
    else {
351
10.8M
        call = Py_TYPE(callable)->tp_call;
352
10.8M
        if (call == NULL) {
353
0
            object_is_not_callable(tstate, callable);
354
0
            return NULL;
355
0
        }
356
357
10.8M
        if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
358
0
            return NULL;
359
0
        }
360
361
10.8M
        result = (*call)(callable, args, kwargs);
362
363
10.8M
        _Py_LeaveRecursiveCallTstate(tstate);
364
365
10.8M
        return _Py_CheckFunctionResult(tstate, callable, result, NULL);
366
10.8M
    }
367
41.4M
}
368
369
PyObject *
370
PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
371
41.3M
{
372
41.3M
    PyThreadState *tstate = _PyThreadState_GET();
373
41.3M
    return _PyObject_Call(tstate, callable, args, kwargs);
374
41.3M
}
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.4M
{
388
70.4M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
389
70.4M
    assert(arg != NULL);
390
70.4M
    PyObject *_args[2];
391
70.4M
    PyObject **args = _args + 1;  // For PY_VECTORCALL_ARGUMENTS_OFFSET
392
70.4M
    args[0] = arg;
393
70.4M
    PyThreadState *tstate = _PyThreadState_GET();
394
70.4M
    size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
395
70.4M
    return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
396
70.4M
}
397
398
399
/* --- PyFunction call functions ---------------------------------- */
400
401
PyObject *
402
_PyFunction_Vectorcall(PyObject *func, PyObject* const* stack,
403
                       size_t nargsf, PyObject *kwnames)
404
196M
{
405
196M
    assert(PyFunction_Check(func));
406
196M
    PyFunctionObject *f = (PyFunctionObject *)func;
407
196M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
408
196M
    assert(nargs >= 0);
409
196M
    PyThreadState *tstate = _PyThreadState_GET();
410
196M
    assert(nargs == 0 || stack != NULL);
411
196M
    EVAL_CALL_STAT_INC(EVAL_CALL_FUNCTION_VECTORCALL);
412
196M
    if (((PyCodeObject *)f->func_code)->co_flags & CO_OPTIMIZED) {
413
196M
        return _PyEval_Vector(tstate, f, NULL, stack, nargs, kwnames);
414
196M
    }
415
0
    else {
416
0
        return _PyEval_Vector(tstate, f, f->func_globals, stack, nargs, kwnames);
417
0
    }
418
196M
}
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
137k
{
462
137k
    PyThreadState *tstate = _PyThreadState_GET();
463
137k
    assert(!_PyErr_Occurred(tstate));
464
137k
    if (args == NULL) {
465
0
        return _PyObject_CallNoArgsTstate(tstate, callable);
466
0
    }
467
137k
    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
137k
    return _PyObject_Call(tstate, callable, args, NULL);
473
137k
}
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
54.7M
{
481
54.7M
    assert(PyTuple_Check(args));
482
483
54.7M
    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
484
54.7M
    PyObject **stack;
485
486
54.7M
    Py_ssize_t argcount = PyTuple_GET_SIZE(args);
487
54.7M
    if (argcount + 1 <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
488
54.5M
        stack = small_stack;
489
54.5M
    }
490
246k
    else {
491
246k
        stack = PyMem_Malloc((argcount + 1) * sizeof(PyObject *));
492
246k
        if (stack == NULL) {
493
0
            PyErr_NoMemory();
494
0
            return NULL;
495
0
        }
496
246k
    }
497
498
    /* use borrowed references */
499
54.7M
    stack[0] = obj;
500
54.7M
    memcpy(&stack[1],
501
54.7M
           _PyTuple_ITEMS(args),
502
54.7M
           argcount * sizeof(PyObject *));
503
504
54.7M
    PyObject *result = _PyObject_VectorcallDictTstate(tstate, callable,
505
54.7M
                                                      stack, argcount + 1,
506
54.7M
                                                      kwargs);
507
54.7M
    if (stack != small_stack) {
508
246k
        PyMem_Free(stack);
509
246k
    }
510
54.7M
    return result;
511
54.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.89M
{
520
5.89M
    PyObject* small_stack[_PY_FASTCALL_SMALL_STACK];
521
5.89M
    const Py_ssize_t small_stack_len = Py_ARRAY_LENGTH(small_stack);
522
5.89M
    PyObject **stack;
523
5.89M
    Py_ssize_t nargs, i;
524
5.89M
    PyObject *result;
525
526
5.89M
    if (callable == NULL) {
527
0
        return null_error(tstate);
528
0
    }
529
530
5.89M
    if (!format || !*format) {
531
0
        return _PyObject_CallNoArgsTstate(tstate, callable);
532
0
    }
533
534
5.89M
    stack = _Py_VaBuildStack(small_stack, small_stack_len,
535
5.89M
                             format, va, &nargs);
536
5.89M
    if (stack == NULL) {
537
0
        return NULL;
538
0
    }
539
5.89M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
540
5.89M
    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
8.78k
        PyObject *args = stack[0];
546
8.78k
        result = _PyObject_VectorcallTstate(tstate, callable,
547
8.78k
                                            _PyTuple_ITEMS(args),
548
8.78k
                                            PyTuple_GET_SIZE(args),
549
8.78k
                                            NULL);
550
8.78k
    }
551
5.88M
    else {
552
5.88M
        result = _PyObject_VectorcallTstate(tstate, callable,
553
5.88M
                                            stack, nargs, NULL);
554
5.88M
    }
555
556
34.8M
    for (i = 0; i < nargs; ++i) {
557
28.9M
        Py_DECREF(stack[i]);
558
28.9M
    }
559
5.89M
    if (stack != small_stack) {
560
0
        PyMem_Free(stack);
561
0
    }
562
5.89M
    return result;
563
5.89M
}
564
565
566
PyObject *
567
PyObject_CallFunction(PyObject *callable, const char *format, ...)
568
5.89M
{
569
5.89M
    va_list va;
570
5.89M
    PyObject *result;
571
5.89M
    PyThreadState *tstate = _PyThreadState_GET();
572
573
5.89M
    va_start(va, format);
574
5.89M
    result = _PyObject_CallFunctionVa(tstate, callable, format, va);
575
5.89M
    va_end(va);
576
577
5.89M
    return result;
578
5.89M
}
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.37M
{
619
1.37M
    PyObject *result = NULL;
620
621
1.37M
    _PyCStackRef self, method;
622
1.37M
    _PyThreadState_PushCStackRef(tstate, &self);
623
1.37M
    _PyThreadState_PushCStackRef(tstate, &method);
624
1.37M
    self.ref = PyStackRef_FromPyObjectBorrow(obj);
625
626
1.37M
    int res = _PyObject_GetMethodStackRef(tstate, &self.ref, name, &method.ref);
627
1.37M
    if (res < 0) {
628
0
        goto exit;
629
0
    }
630
631
1.37M
    PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
632
1.37M
    PyObject *self_obj = PyStackRef_AsPyObjectBorrow(self.ref);
633
634
1.37M
    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.37M
    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
643
1.37M
    Py_ssize_t nargs = 0;
644
1.37M
    PyObject **built = NULL;
645
1.37M
    if (format != NULL && *format != '\0') {
646
1.37M
        built = _Py_VaBuildStack(small_stack, _PY_FASTCALL_SMALL_STACK,
647
1.37M
                                 format, va, &nargs);
648
1.37M
        if (built == NULL) {
649
0
            goto exit;
650
0
        }
651
1.37M
    }
652
653
    /* Backward compat: a single tuple from "O" is unpacked. */
654
1.37M
    PyObject *const *args = built;
655
1.37M
    Py_ssize_t n = nargs;
656
1.37M
    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.37M
    if (self_obj != NULL) {
662
1.37M
        result = _PyObject_VectorcallPrepend(tstate, callable, self_obj, args, n, NULL);
663
1.37M
    }
664
6.16k
    else {
665
6.16k
        result = _PyObject_VectorcallTstate(tstate, callable, args, n, NULL);
666
6.16k
    }
667
668
4.12M
    for (Py_ssize_t i = 0; i < nargs; i++) {
669
2.74M
        Py_DECREF(built[i]);
670
2.74M
    }
671
1.37M
    if (built != small_stack) {
672
2.05k
        PyMem_Free(built);
673
2.05k
    }
674
675
1.37M
exit:
676
1.37M
    _PyThreadState_PopCStackRef(tstate, &method);
677
1.37M
    _PyThreadState_PopCStackRef(tstate, &self);
678
1.37M
    return result;
679
1.37M
}
680
681
PyObject *
682
PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...)
683
6.40k
{
684
6.40k
    PyThreadState *tstate = _PyThreadState_GET();
685
686
6.40k
    if (obj == NULL || name == NULL) {
687
0
        return null_error(tstate);
688
0
    }
689
690
6.40k
    PyObject *name_obj = PyUnicode_FromString(name);
691
6.40k
    if (name_obj == NULL) {
692
0
        return NULL;
693
0
    }
694
695
6.40k
    va_list va;
696
6.40k
    va_start(va, format);
697
6.40k
    PyObject *retval = callmethod(tstate, obj, name_obj, format, va);
698
6.40k
    va_end(va);
699
700
6.40k
    Py_DECREF(name_obj);
701
6.40k
    return retval;
702
6.40k
}
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.37M
{
734
1.37M
    PyThreadState *tstate = _PyThreadState_GET();
735
1.37M
    if (obj == NULL || name == NULL) {
736
0
        return null_error(tstate);
737
0
    }
738
739
1.37M
    va_list va;
740
1.37M
    va_start(va, format);
741
1.37M
    PyObject *retval = callmethod(tstate, obj, name, format, va);
742
1.37M
    va_end(va);
743
744
1.37M
    return retval;
745
1.37M
}
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
305k
{
806
305k
    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
807
305k
    PyObject **stack;
808
305k
    Py_ssize_t nargs;
809
305k
    PyObject *result;
810
305k
    Py_ssize_t i;
811
305k
    va_list countva;
812
813
305k
    if (callable == NULL) {
814
0
        return null_error(tstate);
815
0
    }
816
817
    /* Count the number of arguments */
818
305k
    va_copy(countva, vargs);
819
305k
    nargs = base ? 1 : 0;
820
2.21M
    while (1) {
821
2.21M
        PyObject *arg = va_arg(countva, PyObject *);
822
2.21M
        if (arg == NULL) {
823
305k
            break;
824
305k
        }
825
1.91M
        nargs++;
826
1.91M
    }
827
305k
    va_end(countva);
828
829
    /* Copy arguments */
830
305k
    if (nargs <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
831
84.3k
        stack = small_stack;
832
84.3k
    }
833
221k
    else {
834
221k
        stack = PyMem_Malloc(nargs * sizeof(stack[0]));
835
221k
        if (stack == NULL) {
836
0
            PyErr_NoMemory();
837
0
            return NULL;
838
0
        }
839
221k
    }
840
841
305k
    i = 0;
842
305k
    if (base) {
843
45.3k
        stack[i++] = base;
844
45.3k
    }
845
846
2.21M
    for (; i < nargs; ++i) {
847
1.91M
        stack[i] = va_arg(vargs, PyObject *);
848
1.91M
    }
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
305k
    result = _PyObject_VectorcallTstate(tstate, callable, stack, nargs, NULL);
857
858
305k
    if (stack != small_stack) {
859
221k
        PyMem_Free(stack);
860
221k
    }
861
305k
    return result;
862
305k
}
863
864
PyObject *
865
_PyObject_VectorcallPrepend(PyThreadState *tstate, PyObject *callable,
866
                            PyObject *arg, PyObject *const *args,
867
                            size_t nargsf, PyObject *kwnames)
868
38.6M
{
869
38.6M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
870
38.6M
    assert(nargs == 0 || args[nargs-1]);
871
872
38.6M
    PyObject *result;
873
38.6M
    if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) {
874
        /* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */
875
3.37M
        PyObject **newargs = (PyObject**)args - 1;
876
3.37M
        nargs += 1;
877
3.37M
        PyObject *tmp = newargs[0];
878
3.37M
        newargs[0] = arg;
879
3.37M
        assert(newargs[nargs-1]);
880
3.37M
        result = _PyObject_VectorcallTstate(tstate, callable, newargs,
881
3.37M
                                            nargs, kwnames);
882
3.37M
        newargs[0] = tmp;
883
3.37M
    }
884
35.2M
    else {
885
35.2M
        Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
886
35.2M
        Py_ssize_t totalargs = nargs + nkwargs;
887
35.2M
        if (totalargs == 0) {
888
1.02k
            return _PyObject_VectorcallTstate(tstate, callable, &arg, 1, NULL);
889
1.02k
        }
890
891
35.2M
        PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
892
35.2M
        PyObject **newargs;
893
35.2M
        if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
894
35.2M
            newargs = newargs_stack;
895
35.2M
        }
896
2.58k
        else {
897
2.58k
            newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *));
898
2.58k
            if (newargs == NULL) {
899
0
                _PyErr_NoMemory(tstate);
900
0
                return NULL;
901
0
            }
902
2.58k
        }
903
        /* use borrowed references */
904
35.2M
        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
35.2M
        assert(args != NULL);
909
35.2M
        memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
910
35.2M
        result = _PyObject_VectorcallTstate(tstate, callable,
911
35.2M
                                            newargs, nargs+1, kwnames);
912
35.2M
        if (newargs != newargs_stack) {
913
2.58k
            PyMem_Free(newargs);
914
2.58k
        }
915
35.2M
    }
916
38.6M
    return result;
917
38.6M
}
918
919
PyObject *
920
PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
921
                           size_t nargsf, PyObject *kwnames)
922
4.00M
{
923
4.00M
    assert(name != NULL);
924
4.00M
    assert(args != NULL);
925
4.00M
    assert(PyVectorcall_NARGS(nargsf) >= 1);
926
927
4.00M
    PyThreadState *tstate = _PyThreadState_GET();
928
4.00M
    _PyCStackRef self, method;
929
4.00M
    _PyThreadState_PushCStackRef(tstate, &self);
930
4.00M
    _PyThreadState_PushCStackRef(tstate, &method);
931
    /* Use args[0] as "self" argument */
932
4.00M
    self.ref = PyStackRef_FromPyObjectBorrow(args[0]);
933
4.00M
    int unbound = _PyObject_GetMethodStackRef(tstate, &self.ref, name, &method.ref);
934
4.00M
    if (unbound < 0) {
935
5
        _PyThreadState_PopCStackRef(tstate, &method);
936
5
        _PyThreadState_PopCStackRef(tstate, &self);
937
5
        return NULL;
938
5
    }
939
940
4.00M
    PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
941
4.00M
    PyObject *self_obj = PyStackRef_AsPyObjectBorrow(self.ref);
942
4.00M
    PyObject *result;
943
944
4.00M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_METHOD, callable);
945
4.00M
    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
63.1k
        result = _PyObject_VectorcallTstate(tstate, callable,
949
63.1k
                                            args + 1, nargsf - 1, kwnames);
950
63.1k
    }
951
3.94M
    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.94M
        result = _PyObject_VectorcallTstate(tstate, callable, args,
955
3.94M
                                            nargsf & ~PY_VECTORCALL_ARGUMENTS_OFFSET,
956
3.94M
                                            kwnames);
957
3.94M
    }
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
4.00M
    _PyThreadState_PopCStackRef(tstate, &method);
965
4.00M
    _PyThreadState_PopCStackRef(tstate, &self);
966
4.00M
    return result;
967
4.00M
}
968
969
970
PyObject *
971
PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...)
972
64.5k
{
973
64.5k
    PyThreadState *tstate = _PyThreadState_GET();
974
64.5k
    if (obj == NULL || name == NULL) {
975
0
        return null_error(tstate);
976
0
    }
977
978
64.5k
    _PyCStackRef self, method;
979
64.5k
    _PyThreadState_PushCStackRef(tstate, &self);
980
64.5k
    _PyThreadState_PushCStackRef(tstate, &method);
981
64.5k
    self.ref = PyStackRef_FromPyObjectBorrow(obj);
982
64.5k
    int res = _PyObject_GetMethodStackRef(tstate, &self.ref, name, &method.ref);
983
64.5k
    if (res < 0) {
984
0
        _PyThreadState_PopCStackRef(tstate, &method);
985
0
        _PyThreadState_PopCStackRef(tstate, &self);
986
0
        return NULL;
987
0
    }
988
64.5k
    PyObject *callable = PyStackRef_AsPyObjectBorrow(method.ref);
989
64.5k
    PyObject *self_obj = PyStackRef_AsPyObjectBorrow(self.ref);
990
991
64.5k
    va_list vargs;
992
64.5k
    va_start(vargs, name);
993
64.5k
    PyObject *result = object_vacall(tstate, self_obj, callable, vargs);
994
64.5k
    va_end(vargs);
995
996
64.5k
    _PyThreadState_PopCStackRef(tstate, &method);
997
64.5k
    _PyThreadState_PopCStackRef(tstate, &self);
998
64.5k
    return result;
999
64.5k
}
1000
1001
1002
PyObject *
1003
PyObject_CallFunctionObjArgs(PyObject *callable, ...)
1004
241k
{
1005
241k
    PyThreadState *tstate = _PyThreadState_GET();
1006
241k
    va_list vargs;
1007
241k
    PyObject *result;
1008
1009
241k
    va_start(vargs, callable);
1010
241k
    result = object_vacall(tstate, NULL, callable, vargs);
1011
241k
    va_end(vargs);
1012
1013
241k
    return result;
1014
241k
}
1015
1016
1017
/* --- PyStack functions ------------------------------------------ */
1018
1019
PyObject *
1020
_PyStack_AsDict(PyObject *const *values, PyObject *kwnames)
1021
8.28M
{
1022
8.28M
    Py_ssize_t nkwargs;
1023
1024
8.28M
    assert(kwnames != NULL);
1025
8.28M
    nkwargs = PyTuple_GET_SIZE(kwnames);
1026
8.28M
    return _PyDict_FromItems(&PyTuple_GET_ITEM(kwnames, 0), 1,
1027
8.28M
                             values, 1, nkwargs);
1028
8.28M
}
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
11.3M
{
1052
11.3M
    assert(nargs >= 0);
1053
11.3M
    assert(kwargs != NULL);
1054
11.3M
    assert(PyDict_Check(kwargs));
1055
1056
11.3M
    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
11.3M
    Py_ssize_t maxnargs = PY_SSIZE_T_MAX / sizeof(args[0]) - 1;
1061
11.3M
    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
11.3M
    PyObject **stack = PyMem_Malloc((1 + nargs + nkwargs) * sizeof(args[0]));
1068
11.3M
    if (stack == NULL) {
1069
0
        _PyErr_NoMemory(tstate);
1070
0
        return NULL;
1071
0
    }
1072
1073
11.3M
    PyObject *kwnames = PyTuple_New(nkwargs);
1074
11.3M
    if (kwnames == NULL) {
1075
0
        PyMem_Free(stack);
1076
0
        return NULL;
1077
0
    }
1078
1079
11.3M
    stack++;  /* For PY_VECTORCALL_ARGUMENTS_OFFSET */
1080
1081
    /* Copy positional arguments (borrowed references) */
1082
20.5M
    for (Py_ssize_t i = 0; i < nargs; i++) {
1083
9.15M
        stack[i] = args[i];
1084
9.15M
    }
1085
1086
11.3M
    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
11.3M
    Py_ssize_t pos = 0, i = 0;
1091
11.3M
    PyObject *key, *value;
1092
11.3M
    unsigned long keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS;
1093
24.9M
    while (PyDict_Next(kwargs, &pos, &key, &value)) {
1094
13.5M
        keys_are_strings &= Py_TYPE(key)->tp_flags;
1095
13.5M
        PyTuple_SET_ITEM(kwnames, i, Py_NewRef(key));
1096
13.5M
        kwstack[i] = Py_NewRef(value);
1097
13.5M
        i++;
1098
13.5M
    }
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
11.3M
    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
11.3M
    *p_kwnames = kwnames;
1113
11.3M
    return stack;
1114
11.3M
}
1115
1116
void
1117
_PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs,
1118
                         PyObject *kwnames)
1119
11.3M
{
1120
    /* Only decref kwargs values, positional args are borrowed */
1121
11.3M
    Py_ssize_t nkwargs = PyTuple_GET_SIZE(kwnames);
1122
24.8M
    for (Py_ssize_t i = 0; i < nkwargs; i++) {
1123
13.4M
        Py_DECREF(stack[nargs + i]);
1124
13.4M
    }
1125
11.3M
    _PyStack_UnpackDict_FreeNoDecRef(stack, kwnames);
1126
11.3M
}
1127
1128
void
1129
_PyStack_UnpackDict_FreeNoDecRef(PyObject *const *stack, PyObject *kwnames)
1130
11.3M
{
1131
11.3M
    PyMem_Free((PyObject **)stack - 1);
1132
11.3M
    Py_DECREF(kwnames);
1133
11.3M
}
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
}