Coverage Report

Created: 2022-07-08 09:39

/home/mdboom/Work/builds/cpython/Python/ceval.c
Line
Count
Source (jump to first uncovered line)
1
/* Execute compiled code */
2
3
/* XXX TO DO:
4
   XXX speed up searching for keywords by using a dictionary
5
   XXX document it!
6
   */
7
8
#define _PY_INTERPRETER
9
10
#include "Python.h"
11
#include "pycore_abstract.h"      // _PyIndex_Check()
12
#include "pycore_call.h"          // _PyObject_FastCallDictTstate()
13
#include "pycore_ceval.h"         // _PyEval_SignalAsyncExc()
14
#include "pycore_code.h"
15
#include "pycore_function.h"
16
#include "pycore_initconfig.h"    // _PyStatus_OK()
17
#include "pycore_long.h"          // _PyLong_GetZero()
18
#include "pycore_object.h"        // _PyObject_GC_TRACK()
19
#include "pycore_moduleobject.h"  // PyModuleObject
20
#include "pycore_opcode.h"        // EXTRA_CASES
21
#include "pycore_pyerrors.h"      // _PyErr_Fetch()
22
#include "pycore_pylifecycle.h"   // _PyErr_Print()
23
#include "pycore_pymem.h"         // _PyMem_IsPtrFreed()
24
#include "pycore_pystate.h"       // _PyInterpreterState_GET()
25
#include "pycore_range.h"         // _PyRangeIterObject
26
#include "pycore_sliceobject.h"   // _PyBuildSlice_ConsumeRefs
27
#include "pycore_sysmodule.h"     // _PySys_Audit()
28
#include "pycore_tuple.h"         // _PyTuple_ITEMS()
29
#include "pycore_emscripten_signal.h"  // _Py_CHECK_EMSCRIPTEN_SIGNALS
30
31
#include "pycore_dict.h"
32
#include "dictobject.h"
33
#include "pycore_frame.h"
34
#include "opcode.h"
35
#include "pydtrace.h"
36
#include "setobject.h"
37
#include "structmember.h"         // struct PyMemberDef, T_OFFSET_EX
38
39
#include <ctype.h>
40
#include <stdbool.h>
41
42
#ifdef Py_DEBUG
43
   /* For debugging the interpreter: */
44
#  define LLTRACE  1      /* Low-level trace feature */
45
#endif
46
47
#if !defined(Py_BUILD_CORE)
48
#  error "ceval.c must be build with Py_BUILD_CORE define for best performance"
49
#endif
50
51
#ifndef Py_DEBUG
52
// GH-89279: The MSVC compiler does not inline these static inline functions
53
// in PGO build in _PyEval_EvalFrameDefault(), because this function is over
54
// the limit of PGO, and that limit cannot be configured.
55
// Define them as macros to make sure that they are always inlined by the
56
// preprocessor.
57
58
#undef Py_DECREF
59
#define Py_DECREF(arg) \
60
    do { \
61
        _Py_DECREF_STAT_INC(); \
62
        PyObject *op = _PyObject_CAST(arg); \
63
        if (--op->ob_refcnt == 0) { \
64
            destructor dealloc = Py_TYPE(op)->tp_dealloc; \
65
            (*dealloc)(op); \
66
        } \
67
    } while (0)
68
69
#undef Py_XDECREF
70
#define Py_XDECREF(arg) \
71
    do { \
72
        PyObject *xop = _PyObject_CAST(arg); \
73
        if (xop != NULL) { \
74
            Py_DECREF(xop); \
75
        } \
76
    } while (0)
77
78
#undef Py_IS_TYPE
79
#define Py_IS_TYPE(ob, type) \
80
    (
_PyObject_CAST65.6M
(ob)->ob_type == (type))
81
82
#undef _Py_DECREF_SPECIALIZED
83
#define _Py_DECREF_SPECIALIZED(arg, dealloc) \
84
    do { \
85
        _Py_DECREF_STAT_INC(); \
86
        PyObject *op = _PyObject_CAST(arg); \
87
        if (--op->ob_refcnt == 0) { \
88
            destructor d = (destructor)(dealloc); \
89
            d(op); \
90
        } \
91
    } while (0)
92
#endif
93
94
// GH-89279: Similar to above, force inlining by using a macro.
95
#if defined(_MSC_VER) && SIZEOF_INT == 4
96
#define _Py_atomic_load_relaxed_int32(ATOMIC_VAL) (assert(sizeof((ATOMIC_VAL)->_value) == 4), *((volatile int*)&((ATOMIC_VAL)->_value)))
97
#else
98
#define _Py_atomic_load_relaxed_int32(ATOMIC_VAL) _Py_atomic_load_relaxed(ATOMIC_VAL)
99
#endif
100
101
102
/* Forward declarations */
103
static PyObject *trace_call_function(
104
    PyThreadState *tstate, PyObject *callable, PyObject **stack,
105
    Py_ssize_t oparg, PyObject *kwnames);
106
static PyObject * do_call_core(
107
    PyThreadState *tstate, PyObject *func,
108
    PyObject *callargs, PyObject *kwdict, int use_tracing);
109
110
#ifdef LLTRACE
111
static void
112
dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
113
{
114
    PyObject **stack_base = _PyFrame_Stackbase(frame);
115
    PyObject *type, *value, *traceback;
116
    PyErr_Fetch(&type, &value, &traceback);
117
    printf("    stack=[");
118
    for (PyObject **ptr = stack_base; ptr < stack_pointer; ptr++) {
119
        if (ptr != stack_base) {
120
            printf(", ");
121
        }
122
        if (PyObject_Print(*ptr, stdout, 0) != 0) {
123
            PyErr_Clear();
124
            printf("<%s object at %p>",
125
                   Py_TYPE(*ptr)->tp_name, (void *)(*ptr));
126
        }
127
    }
128
    printf("]\n");
129
    fflush(stdout);
130
    PyErr_Restore(type, value, traceback);
131
}
132
133
static void
134
lltrace_instruction(_PyInterpreterFrame *frame,
135
                    PyObject **stack_pointer,
136
                    _Py_CODEUNIT *next_instr)
137
{
138
    dump_stack(frame, stack_pointer);
139
    int oparg = _Py_OPARG(*next_instr);
140
    int opcode = _Py_OPCODE(*next_instr);
141
    const char *opname = _PyOpcode_OpName[opcode];
142
    assert(opname != NULL);
143
    int offset = (int)(next_instr - _PyCode_CODE(frame->f_code));
144
    if (HAS_ARG(opcode)) {
145
        printf("%d: %s %d\n", offset * 2, opname, oparg);
146
    }
147
    else {
148
        printf("%d: %s\n", offset * 2, opname);
149
    }
150
    fflush(stdout);
151
}
152
static void
153
lltrace_resume_frame(_PyInterpreterFrame *frame)
154
{
155
    PyFunctionObject *f = frame->f_func;
156
    if (f == NULL) {
157
        printf("\nResuming frame.");
158
        return;
159
    }
160
    PyObject *type, *value, *traceback;
161
    PyErr_Fetch(&type, &value, &traceback);
162
    PyObject *name = f->func_qualname;
163
    if (name == NULL) {
164
        name = f->func_name;
165
    }
166
    printf("\nResuming frame");
167
    if (name) {
168
        printf(" for ");
169
        if (PyObject_Print(name, stdout, 0) < 0) {
170
            PyErr_Clear();
171
        }
172
    }
173
    if (f->func_module) {
174
        printf(" in module ");
175
        if (PyObject_Print(f->func_module, stdout, 0) < 0) {
176
            PyErr_Clear();
177
        }
178
    }
179
    printf("\n");
180
    fflush(stdout);
181
    PyErr_Restore(type, value, traceback);
182
}
183
#endif
184
static int call_trace(Py_tracefunc, PyObject *,
185
                      PyThreadState *, _PyInterpreterFrame *,
186
                      int, PyObject *);
187
static int call_trace_protected(Py_tracefunc, PyObject *,
188
                                PyThreadState *, _PyInterpreterFrame *,
189
                                int, PyObject *);
190
static void call_exc_trace(Py_tracefunc, PyObject *,
191
                           PyThreadState *, _PyInterpreterFrame *);
192
static int maybe_call_line_trace(Py_tracefunc, PyObject *,
193
                                 PyThreadState *, _PyInterpreterFrame *, int);
194
static void maybe_dtrace_line(_PyInterpreterFrame *, PyTraceInfo *, int);
195
static void dtrace_function_entry(_PyInterpreterFrame *);
196
static void dtrace_function_return(_PyInterpreterFrame *);
197
198
static PyObject * import_name(PyThreadState *, _PyInterpreterFrame *,
199
                              PyObject *, PyObject *, PyObject *);
200
static PyObject * import_from(PyThreadState *, PyObject *, PyObject *);
201
static int import_all_from(PyThreadState *, PyObject *, PyObject *);
202
static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *);
203
static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
204
static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
205
static int check_except_type_valid(PyThreadState *tstate, PyObject* right);
206
static int check_except_star_type_valid(PyThreadState *tstate, PyObject* right);
207
static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs);
208
static void format_awaitable_error(PyThreadState *, PyTypeObject *, int);
209
static int get_exception_handler(PyCodeObject *, int, int*, int*, int*);
210
static _PyInterpreterFrame *
211
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
212
                        PyObject *locals, PyObject* const* args,
213
                        size_t argcount, PyObject *kwnames);
214
static void
215
_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
216
217
#define NAME_ERROR_MSG \
218
    "name '%.200s' is not defined"
219
#define UNBOUNDLOCAL_ERROR_MSG \
220
    "cannot access local variable '%s' where it is not associated with a value"
221
#define UNBOUNDFREE_ERROR_MSG \
222
    "cannot access free variable '%s' where it is not associated with a" \
223
    " value in enclosing scope"
224
225
#ifndef NDEBUG
226
/* Ensure that tstate is valid: sanity check for PyEval_AcquireThread() and
227
   PyEval_RestoreThread(). Detect if tstate memory was freed. It can happen
228
   when a thread continues to run after Python finalization, especially
229
   daemon threads. */
230
static int
231
is_tstate_valid(PyThreadState *tstate)
232
{
233
    assert(!_PyMem_IsPtrFreed(tstate));
234
    assert(!_PyMem_IsPtrFreed(tstate->interp));
235
    return 1;
236
}
237
#endif
238
239
240
/* This can set eval_breaker to 0 even though gil_drop_request became
241
   1.  We believe this is all right because the eval loop will release
242
   the GIL eventually anyway. */
243
static inline void
244
COMPUTE_EVAL_BREAKER(PyInterpreterState *interp,
245
                     struct _ceval_runtime_state *ceval,
246
                     struct _ceval_state *ceval2)
247
{
248
    _Py_atomic_store_relaxed(&ceval2->eval_breaker,
249
        _Py_atomic_load_relaxed_int32(&ceval2->gil_drop_request)
250
        | (_Py_atomic_load_relaxed_int32(&ceval->signals_pending)
251
           && _Py_ThreadCanHandleSignals(interp))
252
        | (_Py_atomic_load_relaxed_int32(&ceval2->pending.calls_to_do)
253
           && _Py_ThreadCanHandlePendingCalls())
254
        | ceval2->pending.async_exc);
255
}
256
257
258
static inline void
259
SET_GIL_DROP_REQUEST(PyInterpreterState *interp)
260
{
261
    struct _ceval_state *ceval2 = &interp->ceval;
262
    _Py_atomic_store_relaxed(&ceval2->gil_drop_request, 1);
263
    _Py_atomic_store_relaxed(&ceval2->eval_breaker, 1);
264
}
265
266
267
static inline void
268
RESET_GIL_DROP_REQUEST(PyInterpreterState *interp)
269
{
270
    struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
271
    struct _ceval_state *ceval2 = &interp->ceval;
272
    _Py_atomic_store_relaxed(&ceval2->gil_drop_request, 0);
273
    COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
274
}
275
276
277
static inline void
278
SIGNAL_PENDING_CALLS(PyInterpreterState *interp)
279
{
280
    struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
281
    struct _ceval_state *ceval2 = &interp->ceval;
282
    _Py_atomic_store_relaxed(&ceval2->pending.calls_to_do, 1);
283
    COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
284
}
285
286
287
static inline void
288
UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
289
{
290
    struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
291
    struct _ceval_state *ceval2 = &interp->ceval;
292
    _Py_atomic_store_relaxed(&ceval2->pending.calls_to_do, 0);
293
    COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
294
}
295
296
297
static inline void
298
SIGNAL_PENDING_SIGNALS(PyInterpreterState *interp, int force)
299
{
300
    struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
301
    struct _ceval_state *ceval2 = &interp->ceval;
302
    _Py_atomic_store_relaxed(&ceval->signals_pending, 1);
303
    if (force) {
  Branch (303:9): [True: 0, False: 30.7k]
304
        _Py_atomic_store_relaxed(&ceval2->eval_breaker, 1);
305
    }
306
    else {
307
        /* eval_breaker is not set to 1 if thread_can_handle_signals() is false */
308
        COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
309
    }
310
}
311
312
313
static inline void
314
UNSIGNAL_PENDING_SIGNALS(PyInterpreterState *interp)
315
{
316
    struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
317
    struct _ceval_state *ceval2 = &interp->ceval;
318
    _Py_atomic_store_relaxed(&ceval->signals_pending, 0);
319
    COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
320
}
321
322
323
static inline void
324
SIGNAL_ASYNC_EXC(PyInterpreterState *interp)
325
{
326
    struct _ceval_state *ceval2 = &interp->ceval;
327
    ceval2->pending.async_exc = 1;
328
    _Py_atomic_store_relaxed(&ceval2->eval_breaker, 1);
329
}
330
331
332
static inline void
333
UNSIGNAL_ASYNC_EXC(PyInterpreterState *interp)
334
{
335
    struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
336
    struct _ceval_state *ceval2 = &interp->ceval;
337
    ceval2->pending.async_exc = 0;
338
    COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
339
}
340
341
342
#ifdef HAVE_ERRNO_H
343
#include <errno.h>
344
#endif
345
#include "ceval_gil.h"
346
347
void _Py_NO_RETURN
348
_Py_FatalError_TstateNULL(const char *func)
349
{
350
    _Py_FatalErrorFunc(func,
351
        "the function must be called with the GIL held, "
352
        "after Python initialization and before Python finalization, "
353
        "but the GIL is released (the current Python thread state is NULL)");
354
}
355
356
int
357
_PyEval_ThreadsInitialized(_PyRuntimeState *runtime)
358
{
359
    return gil_created(&runtime->ceval.gil);
360
}
361
362
int
363
PyEval_ThreadsInitialized(void)
364
{
365
    _PyRuntimeState *runtime = &_PyRuntime;
366
    return _PyEval_ThreadsInitialized(runtime);
367
}
368
369
PyStatus
370
_PyEval_InitGIL(PyThreadState *tstate)
371
{
372
    if (!_Py_IsMainInterpreter(tstate->interp)) {
  Branch (372:9): [True: 171, False: 107]
373
        /* Currently, the GIL is shared by all interpreters,
374
           and only the main interpreter is responsible to create
375
           and destroy it. */
376
        return _PyStatus_OK();
377
    }
378
379
    struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
380
    assert(!gil_created(gil));
381
382
    PyThread_init_thread();
383
    create_gil(gil);
384
385
    take_gil(tstate);
386
387
    assert(gil_created(gil));
388
    return _PyStatus_OK();
389
}
390
391
void
392
_PyEval_FiniGIL(PyInterpreterState *interp)
393
{
394
    if (!_Py_IsMainInterpreter(interp)) {
  Branch (394:9): [True: 171, False: 107]
395
        /* Currently, the GIL is shared by all interpreters,
396
           and only the main interpreter is responsible to create
397
           and destroy it. */
398
        return;
399
    }
400
401
    struct _gil_runtime_state *gil = &interp->runtime->ceval.gil;
402
    if (!gil_created(gil)) {
  Branch (402:9): [True: 107, False: 0]
403
        /* First Py_InitializeFromConfig() call: the GIL doesn't exist
404
           yet: do nothing. */
405
        return;
406
    }
407
408
    destroy_gil(gil);
409
    assert(!gil_created(gil));
410
}
411
412
void
413
PyEval_InitThreads(void)
414
{
415
    /* Do nothing: kept for backward compatibility */
416
}
417
418
void
419
_PyEval_Fini(void)
420
{
421
#ifdef Py_STATS
422
    _Py_PrintSpecializationStats(1);
423
#endif
424
}
425
426
void
427
PyEval_AcquireLock(void)
428
{
429
    _PyRuntimeState *runtime = &_PyRuntime;
430
    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
431
    _Py_EnsureTstateNotNULL(tstate);
432
433
    take_gil(tstate);
434
}
435
436
void
437
PyEval_ReleaseLock(void)
438
{
439
    _PyRuntimeState *runtime = &_PyRuntime;
440
    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
441
    /* This function must succeed when the current thread state is NULL.
442
       We therefore avoid PyThreadState_Get() which dumps a fatal error
443
       in debug mode. */
444
    struct _ceval_runtime_state *ceval = &runtime->ceval;
445
    struct _ceval_state *ceval2 = &tstate->interp->ceval;
446
    drop_gil(ceval, ceval2, tstate);
447
}
448
449
void
450
_PyEval_ReleaseLock(PyThreadState *tstate)
451
{
452
    struct _ceval_runtime_state *ceval = &tstate->interp->runtime->ceval;
453
    struct _ceval_state *ceval2 = &tstate->interp->ceval;
454
    drop_gil(ceval, ceval2, tstate);
455
}
456
457
void
458
PyEval_AcquireThread(PyThreadState *tstate)
459
{
460
    _Py_EnsureTstateNotNULL(tstate);
461
462
    take_gil(tstate);
463
464
    struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
465
    if (_PyThreadState_Swap(gilstate, tstate) != NULL) {
  Branch (465:9): [True: 0, False: 5.69k]
466
        Py_FatalError("non-NULL old thread state");
467
    }
468
}
469
470
void
471
PyEval_ReleaseThread(PyThreadState *tstate)
472
{
473
    assert(is_tstate_valid(tstate));
474
475
    _PyRuntimeState *runtime = tstate->interp->runtime;
476
    PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
477
    if (new_tstate != tstate) {
  Branch (477:9): [True: 0, False: 12]
478
        Py_FatalError("wrong thread state");
479
    }
480
    struct _ceval_runtime_state *ceval = &runtime->ceval;
481
    struct _ceval_state *ceval2 = &tstate->interp->ceval;
482
    drop_gil(ceval, ceval2, tstate);
483
}
484
485
#ifdef HAVE_FORK
486
/* This function is called from PyOS_AfterFork_Child to destroy all threads
487
   which are not running in the child process, and clear internal locks
488
   which might be held by those threads. */
489
PyStatus
490
_PyEval_ReInitThreads(PyThreadState *tstate)
491
{
492
    _PyRuntimeState *runtime = tstate->interp->runtime;
493
494
    struct _gil_runtime_state *gil = &runtime->ceval.gil;
495
    if (!gil_created(gil)) {
  Branch (495:9): [True: 0, False: 0]
496
        return _PyStatus_OK();
497
    }
498
    recreate_gil(gil);
499
500
    take_gil(tstate);
501
502
    struct _pending_calls *pending = &tstate->interp->ceval.pending;
503
    if (_PyThread_at_fork_reinit(&pending->lock) < 0) {
  Branch (503:9): [True: 0, False: 0]
504
        return _PyStatus_ERR("Can't reinitialize pending calls lock");
505
    }
506
507
    /* Destroy all threads except the current one */
508
    _PyThreadState_DeleteExcept(runtime, tstate);
509
    return _PyStatus_OK();
510
}
511
#endif
512
513
/* This function is used to signal that async exceptions are waiting to be
514
   raised. */
515
516
void
517
_PyEval_SignalAsyncExc(PyInterpreterState *interp)
518
{
519
    SIGNAL_ASYNC_EXC(interp);
520
}
521
522
PyThreadState *
523
PyEval_SaveThread(void)
524
{
525
    _PyRuntimeState *runtime = &_PyRuntime;
526
    PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
527
    _Py_EnsureTstateNotNULL(tstate);
528
529
    struct _ceval_runtime_state *ceval = &runtime->ceval;
530
    struct _ceval_state *ceval2 = &tstate->interp->ceval;
531
    assert(gil_created(&ceval->gil));
532
    drop_gil(ceval, ceval2, tstate);
533
    return tstate;
534
}
535
536
void
537
PyEval_RestoreThread(PyThreadState *tstate)
538
{
539
    _Py_EnsureTstateNotNULL(tstate);
540
541
    take_gil(tstate);
542
543
    struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
544
    _PyThreadState_Swap(gilstate, tstate);
545
}
546
547
548
/* Mechanism whereby asynchronously executing callbacks (e.g. UNIX
549
   signal handlers or Mac I/O completion routines) can schedule calls
550
   to a function to be called synchronously.
551
   The synchronous function is called with one void* argument.
552
   It should return 0 for success or -1 for failure -- failure should
553
   be accompanied by an exception.
554
555
   If registry succeeds, the registry function returns 0; if it fails
556
   (e.g. due to too many pending calls) it returns -1 (without setting
557
   an exception condition).
558
559
   Note that because registry may occur from within signal handlers,
560
   or other asynchronous events, calling malloc() is unsafe!
561
562
   Any thread can schedule pending calls, but only the main thread
563
   will execute them.
564
   There is no facility to schedule calls to a particular thread, but
565
   that should be easy to change, should that ever be required.  In
566
   that case, the static variables here should go into the python
567
   threadstate.
568
*/
569
570
void
571
_PyEval_SignalReceived(PyInterpreterState *interp)
572
{
573
#ifdef MS_WINDOWS
574
    // bpo-42296: On Windows, _PyEval_SignalReceived() is called from a signal
575
    // handler which can run in a thread different than the Python thread, in
576
    // which case _Py_ThreadCanHandleSignals() is wrong. Ignore
577
    // _Py_ThreadCanHandleSignals() and always set eval_breaker to 1.
578
    //
579
    // The next eval_frame_handle_pending() call will call
580
    // _Py_ThreadCanHandleSignals() to recompute eval_breaker.
581
    int force = 1;
582
#else
583
    int force = 0;
584
#endif
585
    /* bpo-30703: Function called when the C signal handler of Python gets a
586
       signal. We cannot queue a callback using _PyEval_AddPendingCall() since
587
       that function is not async-signal-safe. */
588
    SIGNAL_PENDING_SIGNALS(interp, force);
589
}
590
591
/* Push one item onto the queue while holding the lock. */
592
static int
593
_push_pending_call(struct _pending_calls *pending,
594
                   int (*func)(void *), void *arg)
595
{
596
    int i = pending->last;
597
    int j = (i + 1) % NPENDINGCALLS;
598
    if (j == pending->first) {
  Branch (598:9): [True: 0, False: 96]
599
        return -1; /* Queue full */
600
    }
601
    pending->calls[i].func = func;
602
    pending->calls[i].arg = arg;
603
    pending->last = j;
604
    return 0;
605
}
606
607
/* Pop one item off the queue while holding the lock. */
608
static void
609
_pop_pending_call(struct _pending_calls *pending,
610
                  int (**func)(void *), void **arg)
611
{
612
    int i = pending->first;
613
    if (i == pending->last) {
  Branch (613:9): [True: 114, False: 96]
614
        return; /* Queue empty */
615
    }
616
617
    *func = pending->calls[i].func;
618
    *arg = pending->calls[i].arg;
619
    pending->first = (i + 1) % NPENDINGCALLS;
620
}
621
622
/* This implementation is thread-safe.  It allows
623
   scheduling to be made from any thread, and even from an executing
624
   callback.
625
 */
626
627
int
628
_PyEval_AddPendingCall(PyInterpreterState *interp,
629
                       int (*func)(void *), void *arg)
630
{
631
    struct _pending_calls *pending = &interp->ceval.pending;
632
633
    /* Ensure that _PyEval_InitPendingCalls() was called
634
       and that _PyEval_FiniPendingCalls() is not called yet. */
635
    assert(pending->lock != NULL);
636
637
    PyThread_acquire_lock(pending->lock, WAIT_LOCK);
638
    int result = _push_pending_call(pending, func, arg);
639
    PyThread_release_lock(pending->lock);
640
641
    /* signal main loop */
642
    SIGNAL_PENDING_CALLS(interp);
643
    return result;
644
}
645
646
int
647
Py_AddPendingCall(int (*func)(void *), void *arg)
648
{
649
    /* Best-effort to support subinterpreters and calls with the GIL released.
650
651
       First attempt _PyThreadState_GET() since it supports subinterpreters.
652
653
       If the GIL is released, _PyThreadState_GET() returns NULL . In this
654
       case, use PyGILState_GetThisThreadState() which works even if the GIL
655
       is released.
656
657
       Sadly, PyGILState_GetThisThreadState() doesn't support subinterpreters:
658
       see bpo-10915 and bpo-15751.
659
660
       Py_AddPendingCall() doesn't require the caller to hold the GIL. */
661
    PyThreadState *tstate = _PyThreadState_GET();
662
    if (tstate == NULL) {
  Branch (662:9): [True: 93, False: 3]
663
        tstate = PyGILState_GetThisThreadState();
664
    }
665
666
    PyInterpreterState *interp;
667
    if (tstate != NULL) {
  Branch (667:9): [True: 96, False: 0]
668
        interp = tstate->interp;
669
    }
670
    else {
671
        /* Last resort: use the main interpreter */
672
        interp = _PyInterpreterState_Main();
673
    }
674
    return _PyEval_AddPendingCall(interp, func, arg);
675
}
676
677
static int
678
handle_signals(PyThreadState *tstate)
679
{
680
    assert(is_tstate_valid(tstate));
681
    if (!_Py_ThreadCanHandleSignals(tstate->interp)) {
  Branch (681:9): [True: 7, False: 29.4k]
682
        return 0;
683
    }
684
685
    UNSIGNAL_PENDING_SIGNALS(tstate->interp);
686
    if (_PyErr_CheckSignalsTstate(tstate) < 0) {
  Branch (686:9): [True: 14, False: 29.4k]
687
        /* On failure, re-schedule a call to handle_signals(). */
688
        SIGNAL_PENDING_SIGNALS(tstate->interp, 0);
689
        return -1;
690
    }
691
    return 0;
692
}
693
694
static int
695
make_pending_calls(PyInterpreterState *interp)
696
{
697
    /* only execute pending calls on main thread */
698
    if (!_Py_ThreadCanHandlePendingCalls()) {
  Branch (698:9): [True: 0, False: 114]
699
        return 0;
700
    }
701
702
    /* don't perform recursive pending calls */
703
    static int busy = 0;
704
    if (busy) {
  Branch (704:9): [True: 0, False: 114]
705
        return 0;
706
    }
707
    busy = 1;
708
709
    /* unsignal before starting to call callbacks, so that any callback
710
       added in-between re-signals */
711
    UNSIGNAL_PENDING_CALLS(interp);
712
    int res = 0;
713
714
    /* perform a bounded number of calls, in case of recursion */
715
    struct _pending_calls *pending = &interp->ceval.pending;
716
    for (int i=0; i<NPENDINGCALLS; 
i++96
) {
  Branch (716:19): [True: 210, False: 0]
717
        int (*func)(void *) = NULL;
718
        void *arg = NULL;
719
720
        /* pop one item off the queue while holding the lock */
721
        PyThread_acquire_lock(pending->lock, WAIT_LOCK);
722
        _pop_pending_call(pending, &func, &arg);
723
        PyThread_release_lock(pending->lock);
724
725
        /* having released the lock, perform the callback */
726
        if (func == NULL) {
  Branch (726:13): [True: 114, False: 96]
727
            break;
728
        }
729
        res = func(arg);
730
        if (res) {
  Branch (730:13): [True: 0, False: 96]
731
            goto error;
732
        }
733
    }
734
735
    busy = 0;
736
    return res;
737
738
error:
739
    busy = 0;
740
    SIGNAL_PENDING_CALLS(interp);
741
    return res;
742
}
743
744
void
745
_Py_FinishPendingCalls(PyThreadState *tstate)
746
{
747
    assert(PyGILState_Check());
748
    assert(is_tstate_valid(tstate));
749
750
    struct _pending_calls *pending = &tstate->interp->ceval.pending;
751
752
    if (!_Py_atomic_load_relaxed_int32(&(pending->calls_to_do))) {
  Branch (752:9): [True: 104, False: 0]
753
        return;
754
    }
755
756
    if (make_pending_calls(tstate->interp) < 0) {
  Branch (756:9): [True: 0, False: 0]
757
        PyObject *exc, *val, *tb;
758
        _PyErr_Fetch(tstate, &exc, &val, &tb);
759
        PyErr_BadInternalCall();
760
        _PyErr_ChainExceptions(exc, val, tb);
761
        _PyErr_Print(tstate);
762
    }
763
}
764
765
/* Py_MakePendingCalls() is a simple wrapper for the sake
766
   of backward-compatibility. */
767
int
768
Py_MakePendingCalls(void)
769
{
770
    assert(PyGILState_Check());
771
772
    PyThreadState *tstate = _PyThreadState_GET();
773
    assert(is_tstate_valid(tstate));
774
775
    /* Python signal handler doesn't really queue a callback: it only signals
776
       that a signal was received, see _PyEval_SignalReceived(). */
777
    int res = handle_signals(tstate);
778
    if (res != 0) {
  Branch (778:9): [True: 2, False: 42]
779
        return res;
780
    }
781
782
    res = make_pending_calls(tstate->interp);
783
    if (res != 0) {
  Branch (783:9): [True: 0, False: 42]
784
        return res;
785
    }
786
787
    return 0;
788
}
789
790
/* The interpreter's recursion limit */
791
792
void
793
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
794
{
795
    _gil_initialize(&ceval->gil);
796
}
797
798
void
799
_PyEval_InitState(struct _ceval_state *ceval, PyThread_type_lock pending_lock)
800
{
801
    struct _pending_calls *pending = &ceval->pending;
802
    assert(pending->lock == NULL);
803
804
    pending->lock = pending_lock;
805
}
806
807
void
808
_PyEval_FiniState(struct _ceval_state *ceval)
809
{
810
    struct _pending_calls *pending = &ceval->pending;
811
    if (pending->lock != NULL) {
  Branch (811:9): [True: 272, False: 0]
812
        PyThread_free_lock(pending->lock);
813
        pending->lock = NULL;
814
    }
815
}
816
817
int
818
Py_GetRecursionLimit(void)
819
{
820
    PyInterpreterState *interp = _PyInterpreterState_GET();
821
    return interp->ceval.recursion_limit;
822
}
823
824
void
825
Py_SetRecursionLimit(int new_limit)
826
{
827
    PyInterpreterState *interp = _PyInterpreterState_GET();
828
    interp->ceval.recursion_limit = new_limit;
829
    for (PyThreadState *p = interp->threads.head; p != NULL; 
p = p->next91
) {
  Branch (829:51): [True: 91, False: 91]
830
        int depth = p->recursion_limit - p->recursion_remaining;
831
        p->recursion_limit = new_limit;
832
        p->recursion_remaining = new_limit - depth;
833
    }
834
}
835
836
/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
837
   if the recursion_depth reaches recursion_limit. */
838
int
839
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
840
{
841
    /* Check against global limit first. */
842
    int depth = tstate->recursion_limit - tstate->recursion_remaining;
843
    if (depth < tstate->interp->ceval.recursion_limit) {
  Branch (843:9): [True: 0, False: 16.5k]
844
        tstate->recursion_limit = tstate->interp->ceval.recursion_limit;
845
        tstate->recursion_remaining = tstate->recursion_limit - depth;
846
        assert(tstate->recursion_remaining > 0);
847
        return 0;
848
    }
849
#ifdef USE_STACKCHECK
850
    if (PyOS_CheckStack()) {
851
        ++tstate->recursion_remaining;
852
        _PyErr_SetString(tstate, PyExc_MemoryError, "Stack overflow");
853
        return -1;
854
    }
855
#endif
856
    if (tstate->recursion_headroom) {
  Branch (856:9): [True: 8.20k, False: 8.32k]
857
        if (tstate->recursion_remaining < -50) {
  Branch (857:13): [True: 0, False: 8.20k]
858
            /* Overflowing while handling an overflow. Give up. */
859
            Py_FatalError("Cannot recover from stack overflow.");
860
        }
861
    }
862
    else {
863
        if (tstate->recursion_remaining <= 0) {
  Branch (863:13): [True: 8.32k, False: 0]
864
            tstate->recursion_headroom++;
865
            _PyErr_Format(tstate, PyExc_RecursionError,
866
                        "maximum recursion depth exceeded%s",
867
                        where);
868
            tstate->recursion_headroom--;
869
            ++tstate->recursion_remaining;
870
            return -1;
871
        }
872
    }
873
    return 0;
874
}
875
876
877
static const binaryfunc binary_ops[] = {
878
    [NB_ADD] = PyNumber_Add,
879
    [NB_AND] = PyNumber_And,
880
    [NB_FLOOR_DIVIDE] = PyNumber_FloorDivide,
881
    [NB_LSHIFT] = PyNumber_Lshift,
882
    [NB_MATRIX_MULTIPLY] = PyNumber_MatrixMultiply,
883
    [NB_MULTIPLY] = PyNumber_Multiply,
884
    [NB_REMAINDER] = PyNumber_Remainder,
885
    [NB_OR] = PyNumber_Or,
886
    [NB_POWER] = _PyNumber_PowerNoMod,
887
    [NB_RSHIFT] = PyNumber_Rshift,
888
    [NB_SUBTRACT] = PyNumber_Subtract,
889
    [NB_TRUE_DIVIDE] = PyNumber_TrueDivide,
890
    [NB_XOR] = PyNumber_Xor,
891
    [NB_INPLACE_ADD] = PyNumber_InPlaceAdd,
892
    [NB_INPLACE_AND] = PyNumber_InPlaceAnd,
893
    [NB_INPLACE_FLOOR_DIVIDE] = PyNumber_InPlaceFloorDivide,
894
    [NB_INPLACE_LSHIFT] = PyNumber_InPlaceLshift,
895
    [NB_INPLACE_MATRIX_MULTIPLY] = PyNumber_InPlaceMatrixMultiply,
896
    [NB_INPLACE_MULTIPLY] = PyNumber_InPlaceMultiply,
897
    [NB_INPLACE_REMAINDER] = PyNumber_InPlaceRemainder,
898
    [NB_INPLACE_OR] = PyNumber_InPlaceOr,
899
    [NB_INPLACE_POWER] = _PyNumber_InPlacePowerNoMod,
900
    [NB_INPLACE_RSHIFT] = PyNumber_InPlaceRshift,
901
    [NB_INPLACE_SUBTRACT] = PyNumber_InPlaceSubtract,
902
    [NB_INPLACE_TRUE_DIVIDE] = PyNumber_InPlaceTrueDivide,
903
    [NB_INPLACE_XOR] = PyNumber_InPlaceXor,
904
};
905
906
907
// PEP 634: Structural Pattern Matching
908
909
910
// Return a tuple of values corresponding to keys, with error checks for
911
// duplicate/missing keys.
912
static PyObject*
913
match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
914
{
915
    assert(PyTuple_CheckExact(keys));
916
    Py_ssize_t nkeys = PyTuple_GET_SIZE(keys);
917
    if (!nkeys) {
  Branch (917:9): [True: 3, False: 44]
918
        // No keys means no items.
919
        return PyTuple_New(0);
920
    }
921
    PyObject *seen = NULL;
922
    PyObject *dummy = NULL;
923
    PyObject *values = NULL;
924
    PyObject *get = NULL;
925
    // We use the two argument form of map.get(key, default) for two reasons:
926
    // - Atomically check for a key and get its value without error handling.
927
    // - Don't cause key creation or resizing in dict subclasses like
928
    //   collections.defaultdict that define __missing__ (or similar).
929
    int meth_found = _PyObject_GetMethod(map, &_Py_ID(get), &get);
930
    if (get == NULL) {
  Branch (930:9): [True: 0, False: 44]
931
        goto fail;
932
    }
933
    seen = PySet_New(NULL);
934
    if (seen == NULL) {
  Branch (934:9): [True: 0, False: 44]
935
        goto fail;
936
    }
937
    // dummy = object()
938
    dummy = _PyObject_CallNoArgs((PyObject *)&PyBaseObject_Type);
939
    if (dummy == NULL) {
  Branch (939:9): [True: 0, False: 44]
940
        goto fail;
941
    }
942
    values = PyTuple_New(nkeys);
943
    if (values == NULL) {
  Branch (943:9): [True: 0, False: 44]
944
        goto fail;
945
    }
946
    
for (Py_ssize_t i = 0; 44
i < nkeys;
i++48
) {
  Branch (946:28): [True: 57, False: 35]
947
        PyObject *key = PyTuple_GET_ITEM(keys, i);
948
        if (PySet_Contains(seen, key) || 
PySet_Add(seen, key)56
) {
  Branch (948:13): [True: 1, False: 56]
  Branch (948:42): [True: 0, False: 56]
949
            if (!_PyErr_Occurred(tstate)) {
  Branch (949:17): [True: 1, False: 0]
950
                // Seen it before!
951
                _PyErr_Format(tstate, PyExc_ValueError,
952
                              "mapping pattern checks duplicate key (%R)", key);
953
            }
954
            goto fail;
955
        }
956
        PyObject *args[] = { map, key, dummy };
957
        PyObject *value = NULL;
958
        if (meth_found) {
  Branch (958:13): [True: 55, False: 1]
959
            value = PyObject_Vectorcall(get, args, 3, NULL);
960
        }
961
        else {
962
            value = PyObject_Vectorcall(get, &args[1], 2, NULL);
963
        }
964
        if (value == NULL) {
  Branch (964:13): [True: 0, False: 56]
965
            goto fail;
966
        }
967
        if (value == dummy) {
  Branch (967:13): [True: 8, False: 48]
968
            // key not in map!
969
            Py_DECREF(value);
970
            Py_DECREF(values);
971
            // Return None:
972
            Py_INCREF(Py_None);
973
            values = Py_None;
974
            goto done;
975
        }
976
        PyTuple_SET_ITEM(values, i, value);
977
    }
978
    // Success:
979
done:
980
    Py_DECREF(get);
981
    Py_DECREF(seen);
982
    Py_DECREF(dummy);
983
    return values;
984
fail:
985
    Py_XDECREF(get);
986
    Py_XDECREF(seen);
987
    Py_XDECREF(dummy);
988
    Py_XDECREF(values);
989
    return NULL;
990
}
991
992
// Extract a named attribute from the subject, with additional bookkeeping to
993
// raise TypeErrors for repeated lookups. On failure, return NULL (with no
994
// error set). Use _PyErr_Occurred(tstate) to disambiguate.
995
static PyObject*
996
match_class_attr(PyThreadState *tstate, PyObject *subject, PyObject *type,
997
                 PyObject *name, PyObject *seen)
998
{
999
    assert(PyUnicode_CheckExact(name));
1000
    assert(PySet_CheckExact(seen));
1001
    if (PySet_Contains(seen, name) || 
PySet_Add(seen, name)4.50k
) {
  Branch (1001:9): [True: 2, False: 4.50k]
  Branch (1001:39): [True: 0, False: 4.50k]
1002
        if (!_PyErr_Occurred(tstate)) {
  Branch (1002:13): [True: 2, False: 0]
1003
            // Seen it before!
1004
            _PyErr_Format(tstate, PyExc_TypeError,
1005
                          "%s() got multiple sub-patterns for attribute %R",
1006
                          ((PyTypeObject*)type)->tp_name, name);
1007
        }
1008
        return NULL;
1009
    }
1010
    PyObject *attr = PyObject_GetAttr(subject, name);
1011
    if (attr == NULL && 
_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)0
) {
  Branch (1011:9): [True: 0, False: 4.50k]
  Branch (1011:25): [True: 0, False: 0]
1012
        _PyErr_Clear(tstate);
1013
    }
1014
    return attr;
1015
}
1016
1017
// On success (match), return a tuple of extracted attributes. On failure (no
1018
// match), return NULL. Use _PyErr_Occurred(tstate) to disambiguate.
1019
static PyObject*
1020
match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
1021
            Py_ssize_t nargs, PyObject *kwargs)
1022
{
1023
    if (!PyType_Check(type)) {
  Branch (1023:9): [True: 0, False: 12.7k]
1024
        const char *e = "called match pattern must be a type";
1025
        _PyErr_Format(tstate, PyExc_TypeError, e);
1026
        return NULL;
1027
    }
1028
    assert(PyTuple_CheckExact(kwargs));
1029
    // First, an isinstance check:
1030
    if (PyObject_IsInstance(subject, type) <= 0) {
  Branch (1030:9): [True: 7.19k, False: 5.51k]
1031
        return NULL;
1032
    }
1033
    // So far so good:
1034
    PyObject *seen = PySet_New(NULL);
1035
    if (seen == NULL) {
  Branch (1035:9): [True: 0, False: 5.51k]
1036
        return NULL;
1037
    }
1038
    PyObject *attrs = PyList_New(0);
1039
    if (attrs == NULL) {
  Branch (1039:9): [True: 0, False: 5.51k]
1040
        Py_DECREF(seen);
1041
        return NULL;
1042
    }
1043
    // NOTE: From this point on, goto fail on failure:
1044
    PyObject *match_args = NULL;
1045
    // First, the positional subpatterns:
1046
    if (nargs) {
  Branch (1046:9): [True: 4.47k, False: 1.04k]
1047
        int match_self = 0;
1048
        match_args = PyObject_GetAttrString(type, "__match_args__");
1049
        if (match_args) {
  Branch (1049:13): [True: 4.45k, False: 18]
1050
            if (!PyTuple_CheckExact(match_args)) {
  Branch (1050:17): [True: 3, False: 4.45k]
1051
                const char *e = "%s.__match_args__ must be a tuple (got %s)";
1052
                _PyErr_Format(tstate, PyExc_TypeError, e,
1053
                              ((PyTypeObject *)type)->tp_name,
1054
                              Py_TYPE(match_args)->tp_name);
1055
                goto fail;
1056
            }
1057
        }
1058
        else if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
  Branch (1058:18): [True: 18, False: 0]
1059
            _PyErr_Clear(tstate);
1060
            // _Py_TPFLAGS_MATCH_SELF is only acknowledged if the type does not
1061
            // define __match_args__. This is natural behavior for subclasses:
1062
            // it's as if __match_args__ is some "magic" value that is lost as
1063
            // soon as they redefine it.
1064
            match_args = PyTuple_New(0);
1065
            match_self = PyType_HasFeature((PyTypeObject*)type,
1066
                                            _Py_TPFLAGS_MATCH_SELF);
1067
        }
1068
        else {
1069
            goto fail;
1070
        }
1071
        assert(PyTuple_CheckExact(match_args));
1072
        Py_ssize_t allowed = match_self ? 
117
:
PyTuple_GET_SIZE4.45k
(match_args);
  Branch (1072:30): [True: 17, False: 4.45k]
1073
        if (allowed < nargs) {
  Branch (1073:13): [True: 2, False: 4.47k]
1074
            const char *plural = (allowed == 1) ? 
""0
: "s";
  Branch (1074:34): [True: 0, False: 2]
1075
            _PyErr_Format(tstate, PyExc_TypeError,
1076
                          "%s() accepts %d positional sub-pattern%s (%d given)",
1077
                          ((PyTypeObject*)type)->tp_name,
1078
                          allowed, plural, nargs);
1079
            goto fail;
1080
        }
1081
        if (match_self) {
  Branch (1081:13): [True: 17, False: 4.45k]
1082
            // Easy. Copy the subject itself, and move on to kwargs.
1083
            PyList_Append(attrs, subject);
1084
        }
1085
        else {
1086
            for (Py_ssize_t i = 0; i < nargs; 
i++4.48k
) {
  Branch (1086:36): [True: 4.49k, False: 4.45k]
1087
                PyObject *name = PyTuple_GET_ITEM(match_args, i);
1088
                if (!PyUnicode_CheckExact(name)) {
  Branch (1088:21): [True: 1, False: 4.48k]
1089
                    _PyErr_Format(tstate, PyExc_TypeError,
1090
                                  "__match_args__ elements must be strings "
1091
                                  "(got %s)", Py_TYPE(name)->tp_name);
1092
                    goto fail;
1093
                }
1094
                PyObject *attr = match_class_attr(tstate, subject, type, name,
1095
                                                  seen);
1096
                if (attr == NULL) {
  Branch (1096:21): [True: 1, False: 4.48k]
1097
                    goto fail;
1098
                }
1099
                PyList_Append(attrs, attr);
1100
                Py_DECREF(attr);
1101
            }
1102
        }
1103
        Py_CLEAR(match_args);
1104
    }
1105
    // Finally, the keyword subpatterns:
1106
    
for (Py_ssize_t i = 0; 5.51k
i < PyTuple_GET_SIZE(kwargs);
i++16
) {
  Branch (1106:28): [True: 17, False: 5.50k]
1107
        PyObject *name = PyTuple_GET_ITEM(kwargs, i);
1108
        PyObject *attr = match_class_attr(tstate, subject, type, name, seen);
1109
        if (attr == NULL) {
  Branch (1109:13): [True: 1, False: 16]
1110
            goto fail;
1111
        }
1112
        PyList_Append(attrs, attr);
1113
        Py_DECREF(attr);
1114
    }
1115
    Py_SETREF(attrs, PyList_AsTuple(attrs));
1116
    Py_DECREF(seen);
1117
    return attrs;
1118
fail:
1119
    // We really don't care whether an error was raised or not... that's our
1120
    // caller's problem. All we know is that the match failed.
1121
    Py_XDECREF(match_args);
1122
    Py_DECREF(seen);
1123
    Py_DECREF(attrs);
1124
    return NULL;
1125
}
1126
1127
1128
static int do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause);
1129
static int exception_group_match(
1130
    PyObject* exc_value, PyObject *match_type,
1131
    PyObject **match, PyObject **rest);
1132
1133
static int unpack_iterable(PyThreadState *, PyObject *, int, int, PyObject **);
1134
1135
PyObject *
1136
PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
1137
{
1138
    PyThreadState *tstate = _PyThreadState_GET();
1139
    if (locals == NULL) {
  Branch (1139:9): [True: 0, False: 55.0k]
1140
        locals = globals;
1141
    }
1142
    PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
1143
    if (builtins == NULL) {
  Branch (1143:9): [True: 0, False: 55.0k]
1144
        return NULL;
1145
    }
1146
    PyFrameConstructor desc = {
1147
        .fc_globals = globals,
1148
        .fc_builtins = builtins,
1149
        .fc_name = ((PyCodeObject *)co)->co_name,
1150
        .fc_qualname = ((PyCodeObject *)co)->co_name,
1151
        .fc_code = co,
1152
        .fc_defaults = NULL,
1153
        .fc_kwdefaults = NULL,
1154
        .fc_closure = NULL
1155
    };
1156
    PyFunctionObject *func = _PyFunction_FromConstructor(&desc);
1157
    if (func == NULL) {
  Branch (1157:9): [True: 0, False: 55.0k]
1158
        return NULL;
1159
    }
1160
    EVAL_CALL_STAT_INC(EVAL_CALL_LEGACY);
1161
    PyObject *res = _PyEval_Vector(tstate, func, locals, NULL, 0, NULL);
1162
    Py_DECREF(func);
1163
    return res;
1164
}
1165
1166
1167
/* Interpreter main loop */
1168
1169
PyObject *
1170
PyEval_EvalFrame(PyFrameObject *f)
1171
{
1172
    /* Function kept for backward compatibility */
1173
    PyThreadState *tstate = _PyThreadState_GET();
1174
    return _PyEval_EvalFrame(tstate, f->f_frame, 0);
1175
}
1176
1177
PyObject *
1178
PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
1179
{
1180
    PyThreadState *tstate = _PyThreadState_GET();
1181
    return _PyEval_EvalFrame(tstate, f->f_frame, throwflag);
1182
}
1183
1184
1185
/* Handle signals, pending calls, GIL drop request
1186
   and asynchronous exception */
1187
static int
1188
eval_frame_handle_pending(PyThreadState *tstate)
1189
{
1190
    _PyRuntimeState * const runtime = &_PyRuntime;
1191
    struct _ceval_runtime_state *ceval = &runtime->ceval;
1192
1193
    /* Pending signals */
1194
    if (_Py_atomic_load_relaxed_int32(&ceval->signals_pending)) {
1195
        if (handle_signals(tstate) != 0) {
  Branch (1195:13): [True: 12, False: 29.4k]
1196
            return -1;
1197
        }
1198
    }
1199
1200
    /* Pending calls */
1201
    struct _ceval_state *ceval2 = &tstate->interp->ceval;
1202
    if (_Py_atomic_load_relaxed_int32(&ceval2->pending.calls_to_do)) {
1203
        if (make_pending_calls(tstate->interp) != 0) {
  Branch (1203:13): [True: 0, False: 72]
1204
            return -1;
1205
        }
1206
    }
1207
1208
    /* GIL drop request */
1209
    if (_Py_atomic_load_relaxed_int32(&ceval2->gil_drop_request)) {
1210
        /* Give another thread a chance */
1211
        if (_PyThreadState_Swap(&runtime->gilstate, NULL) != tstate) {
  Branch (1211:13): [True: 0, False: 39.5k]
1212
            Py_FatalError("tstate mix-up");
1213
        }
1214
        drop_gil(ceval, ceval2, tstate);
1215
1216
        /* Other threads may run now */
1217
1218
        take_gil(tstate);
1219
1220
        if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
  Branch (1220:13): [True: 0, False: 39.5k]
1221
            Py_FatalError("orphan tstate");
1222
        }
1223
    }
1224
1225
    /* Check for asynchronous exception. */
1226
    if (tstate->async_exc != NULL) {
  Branch (1226:9): [True: 2, False: 69.0k]
1227
        PyObject *exc = tstate->async_exc;
1228
        tstate->async_exc = NULL;
1229
        UNSIGNAL_ASYNC_EXC(tstate->interp);
1230
        _PyErr_SetNone(tstate, exc);
1231
        Py_DECREF(exc);
1232
        return -1;
1233
    }
1234
1235
#ifdef MS_WINDOWS
1236
    // bpo-42296: On Windows, _PyEval_SignalReceived() can be called in a
1237
    // different thread than the Python thread, in which case
1238
    // _Py_ThreadCanHandleSignals() is wrong. Recompute eval_breaker in the
1239
    // current Python thread with the correct _Py_ThreadCanHandleSignals()
1240
    // value. It prevents to interrupt the eval loop at every instruction if
1241
    // the current Python thread cannot handle signals (if
1242
    // _Py_ThreadCanHandleSignals() is false).
1243
    COMPUTE_EVAL_BREAKER(tstate->interp, ceval, ceval2);
1244
#endif
1245
1246
    return 0;
1247
}
1248
1249
1250
/* Computed GOTOs, or
1251
       the-optimization-commonly-but-improperly-known-as-"threaded code"
1252
   using gcc's labels-as-values extension
1253
   (http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html).
1254
1255
   The traditional bytecode evaluation loop uses a "switch" statement, which
1256
   decent compilers will optimize as a single indirect branch instruction
1257
   combined with a lookup table of jump addresses. However, since the
1258
   indirect jump instruction is shared by all opcodes, the CPU will have a
1259
   hard time making the right prediction for where to jump next (actually,
1260
   it will be always wrong except in the uncommon case of a sequence of
1261
   several identical opcodes).
1262
1263
   "Threaded code" in contrast, uses an explicit jump table and an explicit
1264
   indirect jump instruction at the end of each opcode. Since the jump
1265
   instruction is at a different address for each opcode, the CPU will make a
1266
   separate prediction for each of these instructions, which is equivalent to
1267
   predicting the second opcode of each opcode pair. These predictions have
1268
   a much better chance to turn out valid, especially in small bytecode loops.
1269
1270
   A mispredicted branch on a modern CPU flushes the whole pipeline and
1271
   can cost several CPU cycles (depending on the pipeline depth),
1272
   and potentially many more instructions (depending on the pipeline width).
1273
   A correctly predicted branch, however, is nearly free.
1274
1275
   At the time of this writing, the "threaded code" version is up to 15-20%
1276
   faster than the normal "switch" version, depending on the compiler and the
1277
   CPU architecture.
1278
1279
   NOTE: care must be taken that the compiler doesn't try to "optimize" the
1280
   indirect jumps by sharing them between all opcodes. Such optimizations
1281
   can be disabled on gcc by using the -fno-gcse flag (or possibly
1282
   -fno-crossjumping).
1283
*/
1284
1285
/* Use macros rather than inline functions, to make it as clear as possible
1286
 * to the C compiler that the tracing check is a simple test then branch.
1287
 * We want to be sure that the compiler knows this before it generates
1288
 * the CFG.
1289
 */
1290
1291
#ifdef WITH_DTRACE
1292
#define OR_DTRACE_LINE | (PyDTrace_LINE_ENABLED() ? 255 : 0)
1293
#else
1294
#define OR_DTRACE_LINE
1295
#endif
1296
1297
#ifdef HAVE_COMPUTED_GOTOS
1298
    #ifndef USE_COMPUTED_GOTOS
1299
    #define USE_COMPUTED_GOTOS 1
1300
    #endif
1301
#else
1302
    #if defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS
1303
    #error "Computed gotos are not supported on this compiler."
1304
    #endif
1305
    #undef USE_COMPUTED_GOTOS
1306
    #define USE_COMPUTED_GOTOS 0
1307
#endif
1308
1309
#ifdef Py_STATS
1310
#define INSTRUCTION_START(op) \
1311
    do { \
1312
        frame->prev_instr = next_instr++; \
1313
        OPCODE_EXE_INC(op); \
1314
        if (_py_stats) _py_stats->opcode_stats[lastopcode].pair_count[op]++; \
1315
        lastopcode = op; \
1316
    } while (0)
1317
#else
1318
#define INSTRUCTION_START(op) (frame->prev_instr = next_instr++)
1319
#endif
1320
1321
#if USE_COMPUTED_GOTOS
1322
#define TARGET(op) TARGET_
##op: 4.65G
INSTRUCTION_START(op);
1323
#define DISPATCH_GOTO() goto *opcode_targets[opcode]
1324
#else
1325
#define TARGET(op) case op: INSTRUCTION_START(op);
1326
#define DISPATCH_GOTO() goto dispatch_opcode
1327
#endif
1328
1329
/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
1330
#ifdef LLTRACE
1331
#define PRE_DISPATCH_GOTO() if (lltrace) { \
1332
    lltrace_instruction(frame, stack_pointer, next_instr); }
1333
#else
1334
#define PRE_DISPATCH_GOTO() ((void)0)
1335
#endif
1336
1337
#define NOTRACE_DISPATCH() \
1338
    { \
1339
        NEXTOPARG(); \
1340
        PRE_DISPATCH_GOTO(); \
1341
        DISPATCH_GOTO(); \
1342
    }
1343
1344
/* Do interpreter dispatch accounting for tracing and instrumentation */
1345
#define DISPATCH() \
1346
    { \
1347
        NEXTOPARG(); \
1348
        PRE_DISPATCH_GOTO(); \
1349
        assert(cframe.use_tracing == 0 || cframe.use_tracing == 255); \
1350
        opcode |= cframe.use_tracing OR_DTRACE_LINE; \
1351
        DISPATCH_GOTO(); \
1352
    }
1353
1354
#define NOTRACE_DISPATCH_SAME_OPARG() \
1355
    { \
1356
        opcode = _Py_OPCODE(*next_instr); \
1357
        PRE_DISPATCH_GOTO(); \
1358
        DISPATCH_GOTO(); \
1359
    }
1360
1361
#define CHECK_EVAL_BREAKER() \
1362
    _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
1363
    if (_Py_atomic_load_relaxed_int32(eval_breaker)) { \
1364
        goto handle_eval_breaker; \
1365
    }
1366
1367
1368
/* Tuple access macros */
1369
1370
#ifndef Py_DEBUG
1371
#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
1372
#else
1373
#define GETITEM(v, i) PyTuple_GetItem((v), (i))
1374
#endif
1375
1376
/* Code access macros */
1377
1378
/* The integer overflow is checked by an assertion below. */
1379
#define INSTR_OFFSET() ((int)(next_instr - first_instr))
1380
#define NEXTOPARG()  do { \
1381
        _Py_CODEUNIT word = *next_instr; \
1382
        opcode = _Py_OPCODE(word); \
1383
        oparg = _Py_OPARG(word); \
1384
    } while (0)
1385
#define JUMPTO(x)       (next_instr = first_instr + (x))
1386
#define JUMPBY(x)       (next_instr += (x))
1387
1388
/* Get opcode and oparg from original instructions, not quickened form. */
1389
#define TRACING_NEXTOPARG() do { \
1390
        NEXTOPARG(); \
1391
        opcode = _PyOpcode_Deopt[opcode]; \
1392
    } while (0)
1393
1394
/* OpCode prediction macros
1395
    Some opcodes tend to come in pairs thus making it possible to
1396
    predict the second code when the first is run.  For example,
1397
    COMPARE_OP is often followed by POP_JUMP_IF_FALSE or POP_JUMP_IF_TRUE.
1398
1399
    Verifying the prediction costs a single high-speed test of a register
1400
    variable against a constant.  If the pairing was good, then the
1401
    processor's own internal branch predication has a high likelihood of
1402
    success, resulting in a nearly zero-overhead transition to the
1403
    next opcode.  A successful prediction saves a trip through the eval-loop
1404
    including its unpredictable switch-case branch.  Combined with the
1405
    processor's internal branch prediction, a successful PREDICT has the
1406
    effect of making the two opcodes run as if they were a single new opcode
1407
    with the bodies combined.
1408
1409
    If collecting opcode statistics, your choices are to either keep the
1410
    predictions turned-on and interpret the results as if some opcodes
1411
    had been combined or turn-off predictions so that the opcode frequency
1412
    counter updates for both opcodes.
1413
1414
    Opcode prediction is disabled with threaded code, since the latter allows
1415
    the CPU to record separate branch prediction information for each
1416
    opcode.
1417
1418
*/
1419
1420
#define PREDICT_ID(op)          PRED_##op
1421
1422
#if USE_COMPUTED_GOTOS
1423
#define PREDICT(op)             if (0) 
goto 0
PREDICT_ID0
(op)
1424
#else
1425
#define PREDICT(op) \
1426
    do { \
1427
        _Py_CODEUNIT word = *next_instr; \
1428
        opcode = _Py_OPCODE(word) | cframe.use_tracing OR_DTRACE_LINE; \
1429
        if (opcode == op) { \
1430
            oparg = _Py_OPARG(word); \
1431
            INSTRUCTION_START(op); \
1432
            goto PREDICT_ID(op); \
1433
        } \
1434
    } while(0)
1435
#endif
1436
#define PREDICTED(op)           PREDICT_ID(op):
1437
1438
1439
/* Stack manipulation macros */
1440
1441
/* The stack can grow at most MAXINT deep, as co_nlocals and
1442
   co_stacksize are ints. */
1443
#define STACK_LEVEL()     ((int)(stack_pointer - _PyFrame_Stackbase(frame)))
1444
#define STACK_SIZE()      (frame->f_code->co_stacksize)
1445
#define EMPTY()           (STACK_LEVEL() == 0)
1446
#define TOP()             (stack_pointer[-1])
1447
#define SECOND()          (stack_pointer[-2])
1448
#define THIRD()           (stack_pointer[-3])
1449
#define FOURTH()          (stack_pointer[-4])
1450
#define PEEK(n)           (stack_pointer[-(n)])
1451
#define SET_TOP(v)        (stack_pointer[-1] = (v))
1452
#define SET_SECOND(v)     (stack_pointer[-2] = (v))
1453
#define BASIC_STACKADJ(n) (stack_pointer += n)
1454
#define BASIC_PUSH(v)     (*stack_pointer++ = (
v5.25M
))
1455
#define BASIC_POP()       (*--stack_pointer)
1456
1457
#ifdef Py_DEBUG
1458
#define PUSH(v)         do { \
1459
                            BASIC_PUSH(v); \
1460
                            assert(STACK_LEVEL() <= STACK_SIZE()); \
1461
                        } while (0)
1462
#define POP()           (assert(STACK_LEVEL() > 0), BASIC_POP())
1463
#define STACK_GROW(n)   do { \
1464
                            assert(n >= 0); \
1465
                            BASIC_STACKADJ(n); \
1466
                            assert(STACK_LEVEL() <= STACK_SIZE()); \
1467
                        } while (0)
1468
#define STACK_SHRINK(n) do { \
1469
                            assert(n >= 0); \
1470
                            assert(STACK_LEVEL() >= n); \
1471
                            BASIC_STACKADJ(-(n)); \
1472
                        } while (0)
1473
#else
1474
#define PUSH(v)                BASIC_PUSH(v)
1475
#define POP()                  BASIC_POP()
1476
#define STACK_GROW(n)          BASIC_STACKADJ(n)
1477
#define STACK_SHRINK(n)        BASIC_STACKADJ(-(n))
1478
#endif
1479
1480
/* Local variable macros */
1481
1482
#define GETLOCAL(i)     (frame->localsplus[i])
1483
1484
/* The SETLOCAL() macro must not DECREF the local variable in-place and
1485
   then store the new value; it must copy the old value to a temporary
1486
   value, then store the new value, and then DECREF the temporary value.
1487
   This is because it is possible that during the DECREF the frame is
1488
   accessed by other code (e.g. a __del__ method or gc.collect()) and the
1489
   variable would be pointing to already-freed memory. */
1490
#define SETLOCAL(i, value)      do { PyObject *tmp = GETLOCAL(i); \
1491
                                     GETLOCAL(i) = value; \
1492
                                     Py_XDECREF(tmp); } while (0)
1493
1494
#define JUMP_TO_INSTRUCTION(op) goto PREDICT_ID(op)
1495
1496
1497
#define DEOPT_IF(cond, instname) if (cond) 
{ goto miss; }26.6M
1498
1499
1500
#define GLOBALS() frame->f_globals
1501
#define BUILTINS() frame->f_builtins
1502
#define LOCALS() frame->f_locals
1503
1504
/* Shared opcode macros */
1505
1506
#define TRACE_FUNCTION_EXIT() \
1507
    if (cframe.use_tracing) { \
1508
        if (trace_function_exit(tstate, frame, retval)) { \
1509
            Py_DECREF(retval); \
1510
            goto exit_unwind; \
1511
        } \
1512
    }
1513
1514
#define DTRACE_FUNCTION_EXIT() \
1515
    if (PyDTrace_FUNCTION_RETURN_ENABLED()) { \
1516
        dtrace_function_return(frame); \
1517
    }
1518
1519
#define TRACE_FUNCTION_UNWIND()  \
1520
    if (cframe.use_tracing) { \
1521
        /* Since we are already unwinding, \
1522
         * we don't care if this raises */ \
1523
        trace_function_exit(tstate, frame, NULL); \
1524
    }
1525
1526
#define TRACE_FUNCTION_ENTRY() \
1527
    if (cframe.use_tracing) { \
1528
        _PyFrame_SetStackPointer(frame, stack_pointer); \
1529
        int err = trace_function_entry(tstate, frame); \
1530
        stack_pointer = _PyFrame_GetStackPointer(frame); \
1531
        if (err) { \
1532
            goto error; \
1533
        } \
1534
    }
1535
1536
#define TRACE_FUNCTION_THROW_ENTRY() \
1537
    if (cframe.use_tracing) { \
1538
        assert(frame->stacktop >= 0); \
1539
        if (trace_function_entry(tstate, frame)) { \
1540
            goto exit_unwind; \
1541
        } \
1542
    }
1543
1544
#define DTRACE_FUNCTION_ENTRY()  \
1545
    if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \
1546
        dtrace_function_entry(frame); \
1547
    }
1548
1549
#define ADAPTIVE_COUNTER_IS_ZERO(cache) \
1550
    (cache)->counter < (1<<ADAPTIVE_BACKOFF_BITS)
1551
1552
#define DECREMENT_ADAPTIVE_COUNTER(cache) \
1553
    (cache)->counter -= (1<<ADAPTIVE_BACKOFF_BITS)
1554
1555
static int
1556
trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *frame)
1557
{
1558
    if (tstate->c_tracefunc != NULL) {
  Branch (1558:9): [True: 135k, False: 1.01k]
1559
        /* tstate->c_tracefunc, if defined, is a
1560
            function that will be called on *every* entry
1561
            to a code block.  Its return value, if not
1562
            None, is a function that will be called at
1563
            the start of each executed line of code.
1564
            (Actually, the function must return itself
1565
            in order to continue tracing.)  The trace
1566
            functions are called with three arguments:
1567
            a pointer to the current frame, a string
1568
            indicating why the function is called, and
1569
            an argument which depends on the situation.
1570
            The global trace function is also called
1571
            whenever an exception is detected. */
1572
        if (call_trace_protected(tstate->c_tracefunc,
  Branch (1572:13): [True: 1.00k, False: 134k]
1573
                                    tstate->c_traceobj,
1574
                                    tstate, frame,
1575
                                    PyTrace_CALL, Py_None)) {
1576
            /* Trace function raised an error */
1577
            return -1;
1578
        }
1579
    }
1580
    if (tstate->c_profilefunc != NULL) {
  Branch (1580:9): [True: 1.01k, False: 134k]
1581
        /* Similar for c_profilefunc, except it needn't
1582
            return itself and isn't called for "line" events */
1583
        if (call_trace_protected(tstate->c_profilefunc,
  Branch (1583:13): [True: 0, False: 1.01k]
1584
                                    tstate->c_profileobj,
1585
                                    tstate, frame,
1586
                                    PyTrace_CALL, Py_None)) {
1587
            /* Profile function raised an error */
1588
            return -1;
1589
        }
1590
    }
1591
    return 0;
1592
}
1593
1594
static int
1595
trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *retval)
1596
{
1597
    if (tstate->c_tracefunc) {
  Branch (1597:9): [True: 2.40M, False: 7.07k]
1598
        if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj,
  Branch (1598:13): [True: 1.00k, False: 2.40M]
1599
                                    tstate, frame, PyTrace_RETURN, retval)) {
1600
            return -1;
1601
        }
1602
    }
1603
    if (tstate->c_profilefunc) {
  Branch (1603:9): [True: 7.07k, False: 2.40M]
1604
        if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj,
  Branch (1604:13): [True: 0, False: 7.07k]
1605
                                    tstate, frame, PyTrace_RETURN, retval)) {
1606
            return -1;
1607
        }
1608
    }
1609
    return 0;
1610
}
1611
1612
static _PyInterpreterFrame *
1613
pop_frame(PyThreadState *tstate, _PyInterpreterFrame *frame)
1614
{
1615
    _PyInterpreterFrame *prev_frame = frame->previous;
1616
    _PyEvalFrameClearAndPop(tstate, frame);
1617
    return prev_frame;
1618
}
1619
1620
/* It is only between the KW_NAMES instruction and the following CALL,
1621
 * that this has any meaning.
1622
 */
1623
typedef struct {
1624
    PyObject *kwnames;
1625
} CallShape;
1626
1627
// GH-89279: Must be a macro to be sure it's inlined by MSVC.
1628
#define is_method(stack_pointer, args) (PEEK((args)+2) != NULL)
1629
1630
#define KWNAMES_LEN() \
1631
    (call_shape.kwnames == NULL ? 
0139M
:
((int)15.2M
PyTuple_GET_SIZE15.2M
(call_shape.kwnames)))
1632
1633
PyObject* _Py_HOT_FUNCTION
1634
_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1635
{
1636
    _Py_EnsureTstateNotNULL(tstate);
1637
    CALL_STAT_INC(pyeval_calls);
1638
1639
#if USE_COMPUTED_GOTOS
1640
/* Import the static jump table */
1641
#include "opcode_targets.h"
1642
#endif
1643
1644
#ifdef Py_STATS
1645
    int lastopcode = 0;
1646
#endif
1647
    // opcode is an 8-bit value to improve the code generated by MSVC
1648
    // for the big switch below (in combination with the EXTRA_CASES macro).
1649
    uint8_t opcode;        /* Current opcode */
1650
    int oparg;         /* Current opcode argument, if any */
1651
    _Py_atomic_int * const eval_breaker = &tstate->interp->ceval.eval_breaker;
1652
#ifdef LLTRACE
1653
    int lltrace = 0;
1654
#endif
1655
1656
    _PyCFrame cframe;
1657
    CallShape call_shape;
1658
    call_shape.kwnames = NULL; // Borrowed reference. Reset by CALL instructions.
1659
1660
    /* WARNING: Because the _PyCFrame lives on the C stack,
1661
     * but can be accessed from a heap allocated object (tstate)
1662
     * strict stack discipline must be maintained.
1663
     */
1664
    _PyCFrame *prev_cframe = tstate->cframe;
1665
    cframe.use_tracing = prev_cframe->use_tracing;
1666
    cframe.previous = prev_cframe;
1667
    tstate->cframe = &cframe;
1668
1669
    frame->is_entry = true;
1670
    /* Push frame */
1671
    frame->previous = prev_cframe->current_frame;
1672
    cframe.current_frame = frame;
1673
1674
    /* support for generator.throw() */
1675
    if (throwflag) {
  Branch (1675:9): [True: 610k, False: 82.6M]
1676
        if (_Py_EnterRecursiveCallTstate(tstate, "")) {
  Branch (1676:13): [True: 0, False: 610k]
1677
            tstate->recursion_remaining--;
1678
            goto exit_unwind;
1679
        }
1680
        TRACE_FUNCTION_THROW_ENTRY();
1681
        DTRACE_FUNCTION_ENTRY();
1682
        goto resume_with_error;
1683
    }
1684
1685
    /* Local "register" variables.
1686
     * These are cached values from the frame and code object.  */
1687
1688
    PyObject *names;
1689
    PyObject *consts;
1690
    _Py_CODEUNIT *first_instr;
1691
    _Py_CODEUNIT *next_instr;
1692
    PyObject **stack_pointer;
1693
1694
/* Sets the above local variables from the frame */
1695
#define SET_LOCALS_FROM_FRAME() \
1696
    { \
1697
        PyCodeObject *co = frame->f_code; \
1698
        names = co->co_names; \
1699
        consts = co->co_consts; \
1700
        first_instr = _PyCode_CODE(co); \
1701
    } \
1702
    assert(_PyInterpreterFrame_LASTI(frame) >= -1); \
1703
    /* Jump back to the last instruction executed... */ \
1704
    next_instr = frame->prev_instr + 1; \
1705
    stack_pointer = _PyFrame_GetStackPointer(frame); \
1706
    /* Set stackdepth to -1. \
1707
        Update when returning or calling trace function. \
1708
        Having stackdepth <= 0 ensures that invalid \
1709
        values are not visible to the cycle GC. \
1710
        We choose -1 rather than 0 to assist debugging. \
1711
        */ \
1712
    frame->stacktop = -1;
1713
1714
1715
start_frame:
1716
    if (_Py_EnterRecursiveCallTstate(tstate, "")) {
  Branch (1716:9): [True: 8.25k, False: 208M]
1717
        tstate->recursion_remaining--;
1718
        goto exit_unwind;
1719
    }
1720
1721
resume_frame:
1722
    SET_LOCALS_FROM_FRAME();
1723
1724
#ifdef LLTRACE
1725
    {
1726
        int r = PyDict_Contains(GLOBALS(), &_Py_ID(__lltrace__));
1727
        if (r < 0) {
1728
            goto exit_unwind;
1729
        }
1730
        lltrace = r;
1731
    }
1732
    if (lltrace) {
1733
        lltrace_resume_frame(frame);
1734
    }
1735
#endif
1736
1737
#ifdef Py_DEBUG
1738
    /* _PyEval_EvalFrameDefault() must not be called with an exception set,
1739
       because it can clear it (directly or indirectly) and so the
1740
       caller loses its exception */
1741
    assert(!_PyErr_Occurred(tstate));
1742
#endif
1743
1744
    DISPATCH();
1745
1746
handle_eval_breaker:
1747
1748
    /* Do periodic things, like check for signals and async I/0.
1749
     * We need to do reasonably frequently, but not too frequently.
1750
     * All loops should include a check of the eval breaker.
1751
     * We also check on return from any builtin function.
1752
     */
1753
    if (eval_frame_handle_pending(tstate) != 0) {
  Branch (1753:9): [True: 14, False: 69.0k]
1754
        goto error;
1755
    }
1756
    DISPATCH();
1757
1758
    {
1759
    /* Start instructions */
1760
#if USE_COMPUTED_GOTOS
1761
    {
1762
#else
1763
    dispatch_opcode:
1764
        switch (opcode) {
1765
#endif
1766
1767
        /* BEWARE!
1768
           It is essential that any operation that fails must goto error
1769
           and that all operation that succeed call DISPATCH() ! */
1770
1771
        
TARGET69.0k
(NOP) {
1772
            DISPATCH();
1773
        }
1774
1775
        TARGET(RESUME) {
1776
            _PyCode_Warmup(frame->f_code);
1777
            JUMP_TO_INSTRUCTION(RESUME_QUICK);
1778
        }
1779
1780
        
TARGET2.81M
(RESUME_QUICK) {
1781
            PREDICTED(RESUME_QUICK);
1782
            assert(tstate->cframe == &cframe);
1783
            assert(frame == cframe.current_frame);
1784
            if (_Py_atomic_load_relaxed_int32(eval_breaker) && 
oparg < 241.9k
) {
  Branch (1784:64): [True: 41.9k, False: 1]
1785
                goto handle_eval_breaker;
1786
            }
1787
            DISPATCH();
1788
        }
1789
1790
        TARGET(LOAD_CLOSURE) {
1791
            /* We keep LOAD_CLOSURE so that the bytecode stays more readable. */
1792
            PyObject *value = GETLOCAL(oparg);
1793
            if (value == NULL) {
  Branch (1793:17): [True: 0, False: 1.98M]
1794
                goto unbound_local_error;
1795
            }
1796
            Py_INCREF(value);
1797
            PUSH(value);
1798
            DISPATCH();
1799
        }
1800
1801
        TARGET(LOAD_FAST_CHECK) {
1802
            PyObject *value = GETLOCAL(oparg);
1803
            if (value == NULL) {
  Branch (1803:17): [True: 6, False: 577k]
1804
                goto unbound_local_error;
1805
            }
1806
            Py_INCREF(value);
1807
            PUSH(value);
1808
            DISPATCH();
1809
        }
1810
1811
        
TARGET577k
(LOAD_FAST) {
1812
            PyObject *value = GETLOCAL(oparg);
1813
            assert(value != NULL);
1814
            Py_INCREF(value);
1815
            PUSH(value);
1816
            DISPATCH();
1817
        }
1818
1819
        TARGET(LOAD_CONST) {
1820
            PREDICTED(LOAD_CONST);
1821
            PyObject *value = GETITEM(consts, oparg);
1822
            Py_INCREF(value);
1823
            PUSH(value);
1824
            DISPATCH();
1825
        }
1826
1827
        TARGET(STORE_FAST) {
1828
            PyObject *value = POP();
1829
            SETLOCAL(oparg, value);
1830
            DISPATCH();
1831
        }
1832
1833
        
TARGET111M
(LOAD_FAST__LOAD_FAST) {
1834
            PyObject *value = GETLOCAL(oparg);
1835
            assert(value != NULL);
1836
            NEXTOPARG();
1837
            next_instr++;
1838
            Py_INCREF(value);
1839
            PUSH(value);
1840
            value = GETLOCAL(oparg);
1841
            assert(value != NULL);
1842
            Py_INCREF(value);
1843
            PUSH(value);
1844
            NOTRACE_DISPATCH();
1845
        }
1846
1847
        TARGET(LOAD_FAST__LOAD_CONST) {
1848
            PyObject *value = GETLOCAL(oparg);
1849
            assert(value != NULL);
1850
            NEXTOPARG();
1851
            next_instr++;
1852
            Py_INCREF(value);
1853
            PUSH(value);
1854
            value = GETITEM(consts, oparg);
1855
            Py_INCREF(value);
1856
            PUSH(value);
1857
            NOTRACE_DISPATCH();
1858
        }
1859
1860
        
TARGET65.1M
(STORE_FAST__LOAD_FAST) {
1861
            PyObject *value = POP();
1862
            SETLOCAL(oparg, value);
1863
            NEXTOPARG();
1864
            next_instr++;
1865
            value = GETLOCAL(oparg);
1866
            assert(value != NULL);
1867
            Py_INCREF(value);
1868
            PUSH(value);
1869
            NOTRACE_DISPATCH();
1870
        }
1871
1872
        TARGET(STORE_FAST__STORE_FAST) {
1873
            PyObject *value = POP();
1874
            SETLOCAL(oparg, value);
1875
            NEXTOPARG();
1876
            next_instr++;
1877
            value = POP();
1878
            SETLOCAL(oparg, value);
1879
            NOTRACE_DISPATCH();
1880
        }
1881
1882
        TARGET(LOAD_CONST__LOAD_FAST) {
1883
            PyObject *value = GETITEM(consts, oparg);
1884
            NEXTOPARG();
1885
            next_instr++;
1886
            Py_INCREF(value);
1887
            PUSH(value);
1888
            value = GETLOCAL(oparg);
1889
            assert(value != NULL);
1890
            Py_INCREF(value);
1891
            PUSH(value);
1892
            NOTRACE_DISPATCH();
1893
        }
1894
1895
        
TARGET29.8M
(POP_TOP) {
1896
            PyObject *value = POP();
1897
            Py_DECREF(value);
1898
            DISPATCH();
1899
        }
1900
1901
        TARGET(PUSH_NULL) {
1902
            /* Use BASIC_PUSH as NULL is not a valid object pointer */
1903
            BASIC_PUSH(NULL);
1904
            DISPATCH();
1905
        }
1906
1907
        TARGET(UNARY_POSITIVE) {
1908
            PyObject *value = TOP();
1909
            PyObject *res = PyNumber_Positive(value);
1910
            Py_DECREF(value);
1911
            SET_TOP(res);
1912
            if (res == NULL)
  Branch (1912:17): [True: 3, False: 34]
1913
                goto error;
1914
            DISPATCH();
1915
        }
1916
1917
        
TARGET34
(UNARY_NEGATIVE) {
1918
            PyObject *value = TOP();
1919
            PyObject *res = PyNumber_Negative(value);
1920
            Py_DECREF(value);
1921
            SET_TOP(res);
1922
            if (res == NULL)
  Branch (1922:17): [True: 6, False: 927k]
1923
                goto error;
1924
            DISPATCH();
1925
        }
1926
1927
        
TARGET927k
(UNARY_NOT) {
1928
            PyObject *value = TOP();
1929
            int err = PyObject_IsTrue(value);
1930
            Py_DECREF(value);
1931
            if (err == 0) {
  Branch (1931:17): [True: 372k, False: 568k]
1932
                Py_INCREF(Py_True);
1933
                SET_TOP(Py_True);
1934
                DISPATCH();
1935
            }
1936
            else if (err > 0) {
  Branch (1936:22): [True: 568k, False: 1]
1937
                Py_INCREF(Py_False);
1938
                SET_TOP(Py_False);
1939
                DISPATCH();
1940
            }
1941
            STACK_SHRINK(1);
1942
            goto error;
1943
        }
1944
1945
        
TARGET941k
(UNARY_INVERT) {
1946
            PyObject *value = TOP();
1947
            PyObject *res = PyNumber_Invert(value);
1948
            Py_DECREF(value);
1949
            SET_TOP(res);
1950
            if (res == NULL)
  Branch (1950:17): [True: 5, False: 1.51M]
1951
                goto error;
1952
            DISPATCH();
1953
        }
1954
1955
        
TARGET1.51M
(BINARY_OP_MULTIPLY_INT) {
1956
            assert(cframe.use_tracing == 0);
1957
            PyObject *left = SECOND();
1958
            PyObject *right = TOP();
1959
            DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
1960
            DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
1961
            STAT_INC(BINARY_OP, hit);
1962
            PyObject *prod = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
1963
            SET_SECOND(prod);
1964
            _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
1965
            _Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
1966
            STACK_SHRINK(1);
1967
            if (prod == NULL) {
  Branch (1967:17): [True: 0, False: 6.55M]
1968
                goto error;
1969
            }
1970
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
1971
            NOTRACE_DISPATCH();
1972
        }
1973
1974
        
TARGET6.55M
(BINARY_OP_MULTIPLY_FLOAT) {
1975
            assert(cframe.use_tracing == 0);
1976
            PyObject *left = SECOND();
1977
            PyObject *right = TOP();
1978
            DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
1979
            DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
1980
            STAT_INC(BINARY_OP, hit);
1981
            double dprod = ((PyFloatObject *)left)->ob_fval *
1982
                ((PyFloatObject *)right)->ob_fval;
1983
            PyObject *prod = PyFloat_FromDouble(dprod);
1984
            SET_SECOND(prod);
1985
            _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
1986
            _Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
1987
            STACK_SHRINK(1);
1988
            if (prod == NULL) {
  Branch (1988:17): [True: 0, False: 34.4M]
1989
                goto error;
1990
            }
1991
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
1992
            NOTRACE_DISPATCH();
1993
        }
1994
1995
        TARGET(BINARY_OP_SUBTRACT_INT) {
1996
            assert(cframe.use_tracing == 0);
1997
            PyObject *left = SECOND();
1998
            PyObject *right = TOP();
1999
            DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
2000
            DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
2001
            STAT_INC(BINARY_OP, hit);
2002
            PyObject *sub = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
2003
            SET_SECOND(sub);
2004
            _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
2005
            _Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
2006
            STACK_SHRINK(1);
2007
            if (sub == NULL) {
  Branch (2007:17): [True: 0, False: 9.72M]
2008
                goto error;
2009
            }
2010
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
2011
            NOTRACE_DISPATCH();
2012
        }
2013
2014
        TARGET(BINARY_OP_SUBTRACT_FLOAT) {
2015
            assert(cframe.use_tracing == 0);
2016
            PyObject *left = SECOND();
2017
            PyObject *right = TOP();
2018
            DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
2019
            DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
2020
            STAT_INC(BINARY_OP, hit);
2021
            double dsub = ((PyFloatObject *)left)->ob_fval - ((PyFloatObject *)right)->ob_fval;
2022
            PyObject *sub = PyFloat_FromDouble(dsub);
2023
            SET_SECOND(sub);
2024
            _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
2025
            _Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
2026
            STACK_SHRINK(1);
2027
            if (sub == NULL) {
  Branch (2027:17): [True: 0, False: 7.39M]
2028
                goto error;
2029
            }
2030
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
2031
            NOTRACE_DISPATCH();
2032
        }
2033
2034
        TARGET(BINARY_OP_ADD_UNICODE) {
2035
            assert(cframe.use_tracing == 0);
2036
            PyObject *left = SECOND();
2037
            PyObject *right = TOP();
2038
            DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
2039
            DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
2040
            STAT_INC(BINARY_OP, hit);
2041
            PyObject *res = PyUnicode_Concat(left, right);
2042
            STACK_SHRINK(1);
2043
            SET_TOP(res);
2044
            _Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
2045
            _Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
2046
            if (TOP() == NULL) {
  Branch (2046:17): [True: 0, False: 3.82M]
2047
                goto error;
2048
            }
2049
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
2050
            NOTRACE_DISPATCH();
2051
        }
2052
2053
        TARGET(BINARY_OP_INPLACE_ADD_UNICODE) {
2054
            assert(cframe.use_tracing == 0);
2055
            PyObject *left = SECOND();
2056
            PyObject *right = TOP();
2057
            DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
2058
            DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
2059
            _Py_CODEUNIT true_next = next_instr[INLINE_CACHE_ENTRIES_BINARY_OP];
2060
            assert(_Py_OPCODE(true_next) == STORE_FAST ||
2061
                   _Py_OPCODE(true_next) == STORE_FAST__LOAD_FAST);
2062
            PyObject **target_local = &GETLOCAL(_Py_OPARG(true_next));
2063
            DEOPT_IF(*target_local != left, BINARY_OP);
2064
            STAT_INC(BINARY_OP, hit);
2065
            /* Handle `left = left + right` or `left += right` for str.
2066
             *
2067
             * When possible, extend `left` in place rather than
2068
             * allocating a new PyUnicodeObject. This attempts to avoid
2069
             * quadratic behavior when one neglects to use str.join().
2070
             *
2071
             * If `left` has only two references remaining (one from
2072
             * the stack, one in the locals), DECREFing `left` leaves
2073
             * only the locals reference, so PyUnicode_Append knows
2074
             * that the string is safe to mutate.
2075
             */
2076
            assert(Py_REFCNT(left) >= 2);
2077
            _Py_DECREF_NO_DEALLOC(left);
2078
            STACK_SHRINK(2);
2079
            PyUnicode_Append(target_local, right);
2080
            _Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
2081
            if (*target_local == NULL) {
  Branch (2081:17): [True: 0, False: 2.02M]
2082
                goto error;
2083
            }
2084
            // The STORE_FAST is already done.
2085
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP + 1);
2086
            NOTRACE_DISPATCH();
2087
        }
2088
2089
        
TARGET2.02M
(BINARY_OP_ADD_FLOAT) {
2090
            assert(cframe.use_tracing == 0);
2091
            PyObject *left = SECOND();
2092
            PyObject *right = TOP();
2093
            DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
2094
            DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
2095
            STAT_INC(BINARY_OP, hit);
2096
            double dsum = ((PyFloatObject *)left)->ob_fval +
2097
                ((PyFloatObject *)right)->ob_fval;
2098
            PyObject *sum = PyFloat_FromDouble(dsum);
2099
            SET_SECOND(sum);
2100
            _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
2101
            _Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
2102
            STACK_SHRINK(1);
2103
            if (sum == NULL) {
  Branch (2103:17): [True: 0, False: 18.8M]
2104
                goto error;
2105
            }
2106
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
2107
            NOTRACE_DISPATCH();
2108
        }
2109
2110
        TARGET(BINARY_OP_ADD_INT) {
2111
            assert(cframe.use_tracing == 0);
2112
            PyObject *left = SECOND();
2113
            PyObject *right = TOP();
2114
            DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
2115
            DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
2116
            STAT_INC(BINARY_OP, hit);
2117
            PyObject *sum = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
2118
            SET_SECOND(sum);
2119
            _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
2120
            _Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
2121
            STACK_SHRINK(1);
2122
            if (sum == NULL) {
  Branch (2122:17): [True: 0, False: 17.5M]
2123
                goto error;
2124
            }
2125
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
2126
            NOTRACE_DISPATCH();
2127
        }
2128
2129
        TARGET(BINARY_SUBSCR) {
2130
            PREDICTED(BINARY_SUBSCR);
2131
            PyObject *sub = POP();
2132
            PyObject *container = TOP();
2133
            PyObject *res = PyObject_GetItem(container, sub);
2134
            Py_DECREF(container);
2135
            Py_DECREF(sub);
2136
            SET_TOP(res);
2137
            if (res == NULL)
  Branch (2137:17): [True: 57.1k, False: 24.0M]
2138
                goto error;
2139
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
2140
            DISPATCH();
2141
        }
2142
2143
        TARGET(BINARY_SLICE) {
2144
            PyObject *stop = POP();
2145
            PyObject *start = POP();
2146
            PyObject *container = TOP();
2147
2148
            PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
2149
            if (slice == NULL) {
  Branch (2149:17): [True: 0, False: 9.03M]
2150
                goto error;
2151
            }
2152
            PyObject *res = PyObject_GetItem(container, slice);
2153
            Py_DECREF(slice);
2154
            if (res == NULL) {
  Branch (2154:17): [True: 31, False: 9.03M]
2155
                goto error;
2156
            }
2157
            SET_TOP(res);
2158
            Py_DECREF(container);
2159
            DISPATCH();
2160
        }
2161
2162
        TARGET(STORE_SLICE) {
2163
            PyObject *stop = POP();
2164
            PyObject *start = POP();
2165
            PyObject *container = TOP();
2166
            PyObject *v = SECOND();
2167
2168
            PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
2169
            if (slice == NULL) {
  Branch (2169:17): [True: 0, False: 238k]
2170
                goto error;
2171
            }
2172
            int err = PyObject_SetItem(container, slice, v);
2173
            Py_DECREF(slice);
2174
            if (err) {
  Branch (2174:17): [True: 23, False: 238k]
2175
                goto error;
2176
            }
2177
            STACK_SHRINK(2);
2178
            Py_DECREF(v);
2179
            Py_DECREF(container);
2180
            DISPATCH();
2181
        }
2182
2183
        
TARGET238k
(BINARY_SUBSCR_ADAPTIVE) {
2184
            _PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr;
2185
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
2186
                PyObject *sub = TOP();
2187
                PyObject *container = SECOND();
2188
                next_instr--;
2189
                if (_Py_Specialize_BinarySubscr(container, sub, next_instr) < 0) {
  Branch (2189:21): [True: 0, False: 100k]
2190
                    goto error;
2191
                }
2192
                NOTRACE_DISPATCH_SAME_OPARG();
2193
            }
2194
            else {
2195
                STAT_INC(BINARY_SUBSCR, deferred);
2196
                DECREMENT_ADAPTIVE_COUNTER(cache);
2197
                JUMP_TO_INSTRUCTION(BINARY_SUBSCR);
2198
            }
2199
        }
2200
2201
        TARGET(BINARY_SUBSCR_LIST_INT) {
2202
            assert(cframe.use_tracing == 0);
2203
            PyObject *sub = TOP();
2204
            PyObject *list = SECOND();
2205
            DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
2206
            DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);
2207
2208
            // Deopt unless 0 <= sub < PyList_Size(list)
2209
            Py_ssize_t signed_magnitude = Py_SIZE(sub);
2210
            DEOPT_IF(((size_t)signed_magnitude) > 1, BINARY_SUBSCR);
2211
            assert(((PyLongObject *)_PyLong_GetZero())->ob_digit[0] == 0);
2212
            Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
2213
            DEOPT_IF(index >= PyList_GET_SIZE(list), BINARY_SUBSCR);
2214
            STAT_INC(BINARY_SUBSCR, hit);
2215
            PyObject *res = PyList_GET_ITEM(list, index);
2216
            assert(res != NULL);
2217
            Py_INCREF(res);
2218
            STACK_SHRINK(1);
2219
            _Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
2220
            SET_TOP(res);
2221
            Py_DECREF(list);
2222
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
2223
            NOTRACE_DISPATCH();
2224
        }
2225
2226
        TARGET(BINARY_SUBSCR_TUPLE_INT) {
2227
            assert(cframe.use_tracing == 0);
2228
            PyObject *sub = TOP();
2229
            PyObject *tuple = SECOND();
2230
            DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
2231
            DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);
2232
2233
            // Deopt unless 0 <= sub < PyTuple_Size(list)
2234
            Py_ssize_t signed_magnitude = Py_SIZE(sub);
2235
            DEOPT_IF(((size_t)signed_magnitude) > 1, BINARY_SUBSCR);
2236
            assert(((PyLongObject *)_PyLong_GetZero())->ob_digit[0] == 0);
2237
            Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
2238
            DEOPT_IF(index >= PyTuple_GET_SIZE(tuple), BINARY_SUBSCR);
2239
            STAT_INC(BINARY_SUBSCR, hit);
2240
            PyObject *res = PyTuple_GET_ITEM(tuple, index);
2241
            assert(res != NULL);
2242
            Py_INCREF(res);
2243
            STACK_SHRINK(1);
2244
            _Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
2245
            SET_TOP(res);
2246
            Py_DECREF(tuple);
2247
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
2248
            NOTRACE_DISPATCH();
2249
        }
2250
2251
        
TARGET7.67M
(BINARY_SUBSCR_DICT) {
2252
            assert(cframe.use_tracing == 0);
2253
            PyObject *dict = SECOND();
2254
            DEOPT_IF(!PyDict_CheckExact(SECOND()), BINARY_SUBSCR);
2255
            STAT_INC(BINARY_SUBSCR, hit);
2256
            PyObject *sub = TOP();
2257
            PyObject *res = PyDict_GetItemWithError(dict, sub);
2258
            if (res == NULL) {
  Branch (2258:17): [True: 364k, False: 10.6M]
2259
                goto binary_subscr_dict_error;
2260
            }
2261
            Py_INCREF(res);
2262
            STACK_SHRINK(1);
2263
            Py_DECREF(sub);
2264
            SET_TOP(res);
2265
            Py_DECREF(dict);
2266
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
2267
            DISPATCH();
2268
        }
2269
2270
        TARGET(BINARY_SUBSCR_GETITEM) {
2271
            PyObject *sub = TOP();
2272
            PyObject *container = SECOND();
2273
            _PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr;
2274
            uint32_t type_version = read_u32(cache->type_version);
2275
            PyTypeObject *tp = Py_TYPE(container);
2276
            DEOPT_IF(tp->tp_version_tag != type_version, BINARY_SUBSCR);
2277
            assert(tp->tp_flags & Py_TPFLAGS_HEAPTYPE);
2278
            PyObject *cached = ((PyHeapTypeObject *)tp)->_spec_cache.getitem;
2279
            assert(PyFunction_Check(cached));
2280
            PyFunctionObject *getitem = (PyFunctionObject *)cached;
2281
            DEOPT_IF(getitem->func_version != cache->func_version, BINARY_SUBSCR);
2282
            PyCodeObject *code = (PyCodeObject *)getitem->func_code;
2283
            assert(code->co_argcount == 2);
2284
            DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), BINARY_SUBSCR);
2285
            STAT_INC(BINARY_SUBSCR, hit);
2286
            Py_INCREF(getitem);
2287
            _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, getitem);
2288
            CALL_STAT_INC(inlined_py_calls);
2289
            STACK_SHRINK(2);
2290
            new_frame->localsplus[0] = container;
2291
            new_frame->localsplus[1] = sub;
2292
            for (int i = 2; i < code->co_nlocalsplus; 
i++171k
) {
  Branch (2292:29): [True: 171k, False: 420k]
2293
                new_frame->localsplus[i] = NULL;
2294
            }
2295
            _PyFrame_SetStackPointer(frame, stack_pointer);
2296
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
2297
            frame->prev_instr = next_instr - 1;
2298
            new_frame->previous = frame;
2299
            frame = cframe.current_frame = new_frame;
2300
            CALL_STAT_INC(inlined_py_calls);
2301
            goto start_frame;
2302
        }
2303
2304
        
TARGET420k
(LIST_APPEND) {
2305
            PyObject *v = POP();
2306
            PyObject *list = PEEK(oparg);
2307
            if (_PyList_AppendTakeRef((PyListObject *)list, v) < 0)
  Branch (2307:17): [True: 0, False: 14.9M]
2308
                goto error;
2309
            PREDICT(JUMP_BACKWARD_QUICK);
2310
            DISPATCH();
2311
        }
2312
2313
        TARGET(SET_ADD) {
2314
            PyObject *v = POP();
2315
            PyObject *set = PEEK(oparg);
2316
            int err;
2317
            err = PySet_Add(set, v);
2318
            Py_DECREF(v);
2319
            if (err != 0)
  Branch (2319:17): [True: 0, False: 2.18M]
2320
                goto error;
2321
            PREDICT(JUMP_BACKWARD_QUICK);
2322
            DISPATCH();
2323
        }
2324
2325
        TARGET(STORE_SUBSCR) {
2326
            PREDICTED(STORE_SUBSCR);
2327
            PyObject *sub = TOP();
2328
            PyObject *container = SECOND();
2329
            PyObject *v = THIRD();
2330
            int err;
2331
            STACK_SHRINK(3);
2332
            /* container[sub] = v */
2333
            err = PyObject_SetItem(container, sub, v);
2334
            Py_DECREF(v);
2335
            Py_DECREF(container);
2336
            Py_DECREF(sub);
2337
            if (err != 0) {
  Branch (2337:17): [True: 6.34k, False: 3.25M]
2338
                goto error;
2339
            }
2340
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR);
2341
            DISPATCH();
2342
        }
2343
2344
        TARGET(STORE_SUBSCR_ADAPTIVE) {
2345
            _PyStoreSubscrCache *cache = (_PyStoreSubscrCache *)next_instr;
2346
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
2347
                PyObject *sub = TOP();
2348
                PyObject *container = SECOND();
2349
                next_instr--;
2350
                if (_Py_Specialize_StoreSubscr(container, sub, next_instr) < 0) {
  Branch (2350:21): [True: 0, False: 9.51k]
2351
                    goto error;
2352
                }
2353
                NOTRACE_DISPATCH_SAME_OPARG();
2354
            }
2355
            else {
2356
                STAT_INC(STORE_SUBSCR, deferred);
2357
                DECREMENT_ADAPTIVE_COUNTER(cache);
2358
                JUMP_TO_INSTRUCTION(STORE_SUBSCR);
2359
            }
2360
        }
2361
2362
        TARGET(STORE_SUBSCR_LIST_INT) {
2363
            assert(cframe.use_tracing == 0);
2364
            PyObject *sub = TOP();
2365
            PyObject *list = SECOND();
2366
            PyObject *value = THIRD();
2367
            DEOPT_IF(!PyLong_CheckExact(sub), STORE_SUBSCR);
2368
            DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);
2369
2370
            // Ensure nonnegative, zero-or-one-digit ints.
2371
            DEOPT_IF(((size_t)Py_SIZE(sub)) > 1, STORE_SUBSCR);
2372
            Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
2373
            // Ensure index < len(list)
2374
            DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR);
2375
            STAT_INC(STORE_SUBSCR, hit);
2376
2377
            PyObject *old_value = PyList_GET_ITEM(list, index);
2378
            PyList_SET_ITEM(list, index, value);
2379
            STACK_SHRINK(3);
2380
            assert(old_value != NULL);
2381
            Py_DECREF(old_value);
2382
            _Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
2383
            Py_DECREF(list);
2384
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR);
2385
            NOTRACE_DISPATCH();
2386
        }
2387
2388
        
TARGET2.14M
(STORE_SUBSCR_DICT) {
2389
            assert(cframe.use_tracing == 0);
2390
            PyObject *sub = TOP();
2391
            PyObject *dict = SECOND();
2392
            PyObject *value = THIRD();
2393
            DEOPT_IF(!PyDict_CheckExact(dict), STORE_SUBSCR);
2394
            STACK_SHRINK(3);
2395
            STAT_INC(STORE_SUBSCR, hit);
2396
            int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, value);
2397
            Py_DECREF(dict);
2398
            if (err != 0) {
  Branch (2398:17): [True: 3, False: 7.44M]
2399
                goto error;
2400
            }
2401
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR);
2402
            DISPATCH();
2403
        }
2404
2405
        TARGET(DELETE_SUBSCR) {
2406
            PyObject *sub = TOP();
2407
            PyObject *container = SECOND();
2408
            int err;
2409
            STACK_SHRINK(2);
2410
            /* del container[sub] */
2411
            err = PyObject_DelItem(container, sub);
2412
            Py_DECREF(container);
2413
            Py_DECREF(sub);
2414
            if (err != 0)
  Branch (2414:17): [True: 400k, False: 1.93M]
2415
                goto error;
2416
            DISPATCH();
2417
        }
2418
2419
        TARGET(PRINT_EXPR) {
2420
            PyObject *value = POP();
2421
            PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook));
2422
            PyObject *res;
2423
            if (hook == NULL) {
  Branch (2423:17): [True: 1, False: 3.03k]
2424
                _PyErr_SetString(tstate, PyExc_RuntimeError,
2425
                                 "lost sys.displayhook");
2426
                Py_DECREF(value);
2427
                goto error;
2428
            }
2429
            res = PyObject_CallOneArg(hook, value);
2430
            Py_DECREF(value);
2431
            if (res == NULL)
  Branch (2431:17): [True: 1, False: 3.03k]
2432
                goto error;
2433
            Py_DECREF(res);
2434
            DISPATCH();
2435
        }
2436
2437
        
TARGET3.03k
(RAISE_VARARGS) {
2438
            PyObject *cause = NULL, *exc = NULL;
2439
            switch (oparg) {
2440
            case 2:
  Branch (2440:13): [True: 122k, False: 168k]
2441
                cause = POP(); /* cause */
2442
                /* fall through */
2443
            case 1:
  Branch (2443:13): [True: 162k, False: 128k]
2444
                exc = POP(); /* exc */
2445
                /* fall through */
2446
            case 0:
  Branch (2446:13): [True: 6.19k, False: 284k]
2447
                if (do_raise(tstate, exc, cause)) {
  Branch (2447:21): [True: 6.18k, False: 284k]
2448
                    goto exception_unwind;
2449
                }
2450
                break;
2451
            default:
  Branch (2451:13): [True: 0, False: 290k]
2452
                _PyErr_SetString(tstate, PyExc_SystemError,
2453
                                 "bad RAISE_VARARGS oparg");
2454
                break;
2455
            }
2456
            goto error;
2457
        }
2458
2459
        
TARGET284k
(RETURN_VALUE) {
2460
            PyObject *retval = POP();
2461
            assert(EMPTY());
2462
            _PyFrame_SetStackPointer(frame, stack_pointer);
2463
            TRACE_FUNCTION_EXIT();
2464
            DTRACE_FUNCTION_EXIT();
2465
            _Py_LeaveRecursiveCallTstate(tstate);
2466
            if (!frame->is_entry) {
  Branch (2466:17): [True: 122M, False: 55.3M]
2467
                frame = cframe.current_frame = pop_frame(tstate, frame);
2468
                _PyFrame_StackPush(frame, retval);
2469
                goto resume_frame;
2470
            }
2471
            /* Restore previous cframe and return. */
2472
            tstate->cframe = cframe.previous;
2473
            tstate->cframe->use_tracing = cframe.use_tracing;
2474
            assert(tstate->cframe->current_frame == frame->previous);
2475
            assert(!_PyErr_Occurred(tstate));
2476
            return retval;
2477
        }
2478
2479
        TARGET(GET_AITER) {
2480
            unaryfunc getter = NULL;
2481
            PyObject *iter = NULL;
2482
            PyObject *obj = TOP();
2483
            PyTypeObject *type = Py_TYPE(obj);
2484
2485
            if (type->tp_as_async != NULL) {
  Branch (2485:17): [True: 157, False: 1]
2486
                getter = type->tp_as_async->am_aiter;
2487
            }
2488
2489
            if (getter != NULL) {
  Branch (2489:17): [True: 157, False: 1]
2490
                iter = (*getter)(obj);
2491
                Py_DECREF(obj);
2492
                if (iter == NULL) {
  Branch (2492:21): [True: 2, False: 155]
2493
                    SET_TOP(NULL);
2494
                    goto error;
2495
                }
2496
            }
2497
            else {
2498
                SET_TOP(NULL);
2499
                _PyErr_Format(tstate, PyExc_TypeError,
2500
                              "'async for' requires an object with "
2501
                              "__aiter__ method, got %.100s",
2502
                              type->tp_name);
2503
                Py_DECREF(obj);
2504
                goto error;
2505
            }
2506
2507
            if (Py_TYPE(iter)->tp_as_async == NULL ||
  Branch (2507:17): [True: 0, False: 155]
2508
                    Py_TYPE(iter)->tp_as_async->am_anext == NULL) {
  Branch (2508:21): [True: 1, False: 154]
2509
2510
                SET_TOP(NULL);
2511
                _PyErr_Format(tstate, PyExc_TypeError,
2512
                              "'async for' received an object from __aiter__ "
2513
                              "that does not implement __anext__: %.100s",
2514
                              Py_TYPE(iter)->tp_name);
2515
                Py_DECREF(iter);
2516
                goto error;
2517
            }
2518
2519
            SET_TOP(iter);
2520
            DISPATCH();
2521
        }
2522
2523
        
TARGET154
(GET_ANEXT) {
2524
            unaryfunc getter = NULL;
2525
            PyObject *next_iter = NULL;
2526
            PyObject *awaitable = NULL;
2527
            PyObject *aiter = TOP();
2528
            PyTypeObject *type = Py_TYPE(aiter);
2529
2530
            if (PyAsyncGen_CheckExact(aiter)) {
2531
                awaitable = type->tp_as_async->am_anext(aiter);
2532
                if (awaitable == NULL) {
  Branch (2532:21): [True: 0, False: 434]
2533
                    goto error;
2534
                }
2535
            } else {
2536
                if (type->tp_as_async != NULL){
  Branch (2536:21): [True: 329, False: 0]
2537
                    getter = type->tp_as_async->am_anext;
2538
                }
2539
2540
                if (getter != NULL) {
  Branch (2540:21): [True: 329, False: 0]
2541
                    next_iter = (*getter)(aiter);
2542
                    if (next_iter == NULL) {
  Branch (2542:25): [True: 0, False: 329]
2543
                        goto error;
2544
                    }
2545
                }
2546
                else {
2547
                    _PyErr_Format(tstate, PyExc_TypeError,
2548
                                  "'async for' requires an iterator with "
2549
                                  "__anext__ method, got %.100s",
2550
                                  type->tp_name);
2551
                    goto error;
2552
                }
2553
2554
                awaitable = _PyCoro_GetAwaitableIter(next_iter);
2555
                if (awaitable == NULL) {
  Branch (2555:21): [True: 2, False: 327]
2556
                    _PyErr_FormatFromCause(
2557
                        PyExc_TypeError,
2558
                        "'async for' received an invalid object "
2559
                        "from __anext__: %.100s",
2560
                        Py_TYPE(next_iter)->tp_name);
2561
2562
                    Py_DECREF(next_iter);
2563
                    goto error;
2564
                } else {
2565
                    Py_DECREF(next_iter);
2566
                }
2567
            }
2568
2569
            PUSH(awaitable);
2570
            PREDICT(LOAD_CONST);
2571
            DISPATCH();
2572
        }
2573
2574
        
TARGET761
(GET_AWAITABLE) {
2575
            PREDICTED(GET_AWAITABLE);
2576
            PyObject *iterable = TOP();
2577
            PyObject *iter = _PyCoro_GetAwaitableIter(iterable);
2578
2579
            if (iter == NULL) {
  Branch (2579:17): [True: 28, False: 36.3k]
2580
                format_awaitable_error(tstate, Py_TYPE(iterable), oparg);
2581
            }
2582
2583
            Py_DECREF(iterable);
2584
2585
            if (iter != NULL && 
PyCoro_CheckExact36.3k
(iter)) {
  Branch (2585:17): [True: 36.3k, False: 28]
2586
                PyObject *yf = _PyGen_yf((PyGenObject*)iter);
2587
                if (yf != NULL) {
  Branch (2587:21): [True: 2, False: 19.7k]
2588
                    /* `iter` is a coroutine object that is being
2589
                       awaited, `yf` is a pointer to the current awaitable
2590
                       being awaited on. */
2591
                    Py_DECREF(yf);
2592
                    Py_CLEAR(iter);
2593
                    _PyErr_SetString(tstate, PyExc_RuntimeError,
2594
                                     "coroutine is being awaited already");
2595
                    /* The code below jumps to `error` if `iter` is NULL. */
2596
                }
2597
            }
2598
2599
            SET_TOP(iter); /* Even if it's NULL */
2600
2601
            if (iter == NULL) {
  Branch (2601:17): [True: 30, False: 36.3k]
2602
                goto error;
2603
            }
2604
2605
            PREDICT(LOAD_CONST);
2606
            DISPATCH();
2607
        }
2608
2609
        
TARGET36.3k
(SEND) {
2610
            assert(frame->is_entry);
2611
            assert(STACK_LEVEL() >= 2);
2612
            PyObject *v = POP();
2613
            PyObject *receiver = TOP();
2614
            PySendResult gen_status;
2615
            PyObject *retval;
2616
            if (tstate->c_tracefunc == NULL) {
  Branch (2616:17): [True: 2.57M, False: 565]
2617
                gen_status = PyIter_Send(receiver, v, &retval);
2618
            } else {
2619
                if (Py_IsNone(v) && PyIter_Check(receiver)) {
  Branch (2619:37): [True: 505, False: 60]
2620
                    retval = Py_TYPE(receiver)->tp_iternext(receiver);
2621
                }
2622
                else {
2623
                    retval = PyObject_CallMethodOneArg(receiver, &_Py_ID(send), v);
2624
                }
2625
                if (retval == NULL) {
  Branch (2625:21): [True: 193, False: 372]
2626
                    if (tstate->c_tracefunc != NULL
  Branch (2626:25): [True: 193, False: 0]
2627
                            && _PyErr_ExceptionMatches(tstate, PyExc_StopIteration))
  Branch (2627:32): [True: 81, False: 112]
2628
                        call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame);
2629
                    if (_PyGen_FetchStopIterationValue(&retval) == 0) {
  Branch (2629:25): [True: 182, False: 11]
2630
                        gen_status = PYGEN_RETURN;
2631
                    }
2632
                    else {
2633
                        gen_status = PYGEN_ERROR;
2634
                    }
2635
                }
2636
                else {
2637
                    gen_status = PYGEN_NEXT;
2638
                }
2639
            }
2640
            Py_DECREF(v);
2641
            if (gen_status == PYGEN_ERROR) {
  Branch (2641:17): [True: 736, False: 2.57M]
2642
                assert(retval == NULL);
2643
                goto error;
2644
            }
2645
            if (gen_status == PYGEN_RETURN) {
  Branch (2645:17): [True: 272k, False: 2.30M]
2646
                assert(retval != NULL);
2647
                Py_DECREF(receiver);
2648
                SET_TOP(retval);
2649
                JUMPBY(oparg);
2650
                DISPATCH();
2651
            }
2652
            assert(gen_status == PYGEN_NEXT);
2653
            assert(retval != NULL);
2654
            PUSH(retval);
2655
            DISPATCH();
2656
        }
2657
2658
        TARGET(ASYNC_GEN_WRAP) {
2659
            PyObject *v = TOP();
2660
            assert(frame->f_code->co_flags & CO_ASYNC_GENERATOR);
2661
            PyObject *w = _PyAsyncGenValueWrapperNew(v);
2662
            if (w == NULL) {
  Branch (2662:17): [True: 0, False: 434]
2663
                goto error;
2664
            }
2665
            SET_TOP(w);
2666
            Py_DECREF(v);
2667
            DISPATCH();
2668
        }
2669
2670
        
TARGET434
(YIELD_VALUE) {
2671
            assert(oparg == STACK_LEVEL());
2672
            assert(frame->is_entry);
2673
            PyObject *retval = POP();
2674
            _PyFrame_GetGenerator(frame)->gi_frame_state = FRAME_SUSPENDED;
2675
            _PyFrame_SetStackPointer(frame, stack_pointer);
2676
            TRACE_FUNCTION_EXIT();
2677
            DTRACE_FUNCTION_EXIT();
2678
            _Py_LeaveRecursiveCallTstate(tstate);
2679
            /* Restore previous cframe and return. */
2680
            tstate->cframe = cframe.previous;
2681
            tstate->cframe->use_tracing = cframe.use_tracing;
2682
            assert(tstate->cframe->current_frame == frame->previous);
2683
            assert(!_PyErr_Occurred(tstate));
2684
            return retval;
2685
        }
2686
2687
        TARGET(POP_EXCEPT) {
2688
            _PyErr_StackItem *exc_info = tstate->exc_info;
2689
            PyObject *value = exc_info->exc_value;
2690
            exc_info->exc_value = POP();
2691
            Py_XDECREF(value);
2692
            DISPATCH();
2693
        }
2694
2695
        TARGET(RERAISE) {
2696
            if (oparg) {
  Branch (2696:17): [True: 302k, False: 135k]
2697
                PyObject *lasti = PEEK(oparg + 1);
2698
                if (PyLong_Check(lasti)) {
2699
                    frame->prev_instr = first_instr + PyLong_AsLong(lasti);
2700
                    assert(!_PyErr_Occurred(tstate));
2701
                }
2702
                else {
2703
                    assert(PyLong_Check(lasti));
2704
                    _PyErr_SetString(tstate, PyExc_SystemError, "lasti is not an int");
2705
                    goto error;
2706
                }
2707
            }
2708
            PyObject *val = POP();
2709
            assert(val && PyExceptionInstance_Check(val));
2710
            PyObject *exc = Py_NewRef(PyExceptionInstance_Class(val));
2711
            PyObject *tb = PyException_GetTraceback(val);
2712
            _PyErr_Restore(tstate, exc, val, tb);
2713
            goto exception_unwind;
2714
        }
2715
2716
        TARGET(PREP_RERAISE_STAR) {
2717
            PyObject *excs = POP();
2718
            assert(PyList_Check(excs));
2719
            PyObject *orig = POP();
2720
2721
            PyObject *val = _PyExc_PrepReraiseStar(orig, excs);
2722
            Py_DECREF(excs);
2723
            Py_DECREF(orig);
2724
2725
            if (val == NULL) {
  Branch (2725:17): [True: 0, False: 150]
2726
                goto error;
2727
            }
2728
2729
            PUSH(val);
2730
            DISPATCH();
2731
        }
2732
2733
        TARGET(END_ASYNC_FOR) {
2734
            PyObject *val = POP();
2735
            assert(val && PyExceptionInstance_Check(val));
2736
            if (PyErr_GivenExceptionMatches(val, PyExc_StopAsyncIteration)) {
  Branch (2736:17): [True: 130, False: 10]
2737
                Py_DECREF(val);
2738
                Py_DECREF(POP());
2739
                DISPATCH();
2740
            }
2741
            else {
2742
                PyObject *exc = Py_NewRef(PyExceptionInstance_Class(val));
2743
                PyObject *tb = PyException_GetTraceback(val);
2744
                _PyErr_Restore(tstate, exc, val, tb);
2745
                goto exception_unwind;
2746
            }
2747
        }
2748
2749
        TARGET(LOAD_ASSERTION_ERROR) {
2750
            PyObject *value = PyExc_AssertionError;
2751
            Py_INCREF(value);
2752
            PUSH(value);
2753
            DISPATCH();
2754
        }
2755
2756
        
TARGET27
(LOAD_BUILD_CLASS) {
2757
            PyObject *bc;
2758
            if (PyDict_CheckExact(BUILTINS())) {
2759
                bc = _PyDict_GetItemWithError(BUILTINS(),
2760
                                              &_Py_ID(__build_class__));
2761
                if (bc == NULL) {
  Branch (2761:21): [True: 1, False: 65.0k]
2762
                    if (!_PyErr_Occurred(tstate)) {
  Branch (2762:25): [True: 1, False: 0]
2763
                        _PyErr_SetString(tstate, PyExc_NameError,
2764
                                         "__build_class__ not found");
2765
                    }
2766
                    goto error;
2767
                }
2768
                Py_INCREF(bc);
2769
            }
2770
            else {
2771
                bc = PyObject_GetItem(BUILTINS(), &_Py_ID(__build_class__));
2772
                if (bc == NULL) {
  Branch (2772:21): [True: 0, False: 0]
2773
                    if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError))
  Branch (2773:25): [True: 0, False: 0]
2774
                        _PyErr_SetString(tstate, PyExc_NameError,
2775
                                         "__build_class__ not found");
2776
                    goto error;
2777
                }
2778
            }
2779
            PUSH(bc);
2780
            DISPATCH();
2781
        }
2782
2783
        
TARGET65.0k
(STORE_NAME) {
2784
            PyObject *name = GETITEM(names, oparg);
2785
            PyObject *v = POP();
2786
            PyObject *ns = LOCALS();
2787
            int err;
2788
            if (ns == NULL) {
  Branch (2788:17): [True: 0, False: 741k]
2789
                _PyErr_Format(tstate, PyExc_SystemError,
2790
                              "no locals found when storing %R", name);
2791
                Py_DECREF(v);
2792
                goto error;
2793
            }
2794
            if (PyDict_CheckExact(ns))
2795
                err = PyDict_SetItem(ns, name, v);
2796
            else
2797
                err = PyObject_SetItem(ns, name, v);
2798
            Py_DECREF(v);
2799
            if (err != 0)
  Branch (2799:17): [True: 55, False: 741k]
2800
                goto error;
2801
            DISPATCH();
2802
        }
2803
2804
        TARGET(DELETE_NAME) {
2805
            PyObject *name = GETITEM(names, oparg);
2806
            PyObject *ns = LOCALS();
2807
            int err;
2808
            if (ns == NULL) {
  Branch (2808:17): [True: 0, False: 5.23k]
2809
                _PyErr_Format(tstate, PyExc_SystemError,
2810
                              "no locals when deleting %R", name);
2811
                goto error;
2812
            }
2813
            err = PyObject_DelItem(ns, name);
2814
            if (err != 0) {
  Branch (2814:17): [True: 0, False: 5.23k]
2815
                format_exc_check_arg(tstate, PyExc_NameError,
2816
                                     NAME_ERROR_MSG,
2817
                                     name);
2818
                goto error;
2819
            }
2820
            DISPATCH();
2821
        }
2822
2823
        
TARGET5.23k
(UNPACK_SEQUENCE) {
2824
            PREDICTED(UNPACK_SEQUENCE);
2825
            PyObject *seq = POP();
2826
            PyObject **top = stack_pointer + oparg;
2827
            if (!unpack_iterable(tstate, seq, oparg, -1, top)) {
  Branch (2827:17): [True: 1.42k, False: 560k]
2828
                Py_DECREF(seq);
2829
                goto error;
2830
            }
2831
            STACK_GROW(oparg);
2832
            Py_DECREF(seq);
2833
            JUMPBY(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE);
2834
            DISPATCH();
2835
        }
2836
2837
        TARGET(UNPACK_SEQUENCE_ADAPTIVE) {
2838
            assert(cframe.use_tracing == 0);
2839
            _PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)next_instr;
2840
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
2841
                PyObject *seq = TOP();
2842
                next_instr--;
2843
                _Py_Specialize_UnpackSequence(seq, next_instr, oparg);
2844
                NOTRACE_DISPATCH_SAME_OPARG();
2845
            }
2846
            else {
2847
                STAT_INC(UNPACK_SEQUENCE, deferred);
2848
                DECREMENT_ADAPTIVE_COUNTER(cache);
2849
                JUMP_TO_INSTRUCTION(UNPACK_SEQUENCE);
2850
            }
2851
        }
2852
2853
        
TARGET295k
(UNPACK_SEQUENCE_TWO_TUPLE) {
2854
            PyObject *seq = TOP();
2855
            DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
2856
            DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE);
2857
            STAT_INC(UNPACK_SEQUENCE, hit);
2858
            SET_TOP(Py_NewRef(PyTuple_GET_ITEM(seq, 1)));
2859
            PUSH(Py_NewRef(PyTuple_GET_ITEM(seq, 0)));
2860
            Py_DECREF(seq);
2861
            JUMPBY(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE);
2862
            NOTRACE_DISPATCH();
2863
        }
2864
2865
        TARGET(UNPACK_SEQUENCE_TUPLE) {
2866
            PyObject *seq = TOP();
2867
            DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
2868
            DEOPT_IF(PyTuple_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
2869
            STAT_INC(UNPACK_SEQUENCE, hit);
2870
            STACK_SHRINK(1);
2871
            PyObject **items = _PyTuple_ITEMS(seq);
2872
            while (oparg--) {
  Branch (2872:20): [True: 34.8M, False: 10.9M]
2873
                PUSH(Py_NewRef(items[oparg]));
2874
            }
2875
            Py_DECREF(seq);
2876
            JUMPBY(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE);
2877
            NOTRACE_DISPATCH();
2878
        }
2879
2880
        TARGET(UNPACK_SEQUENCE_LIST) {
2881
            PyObject *seq = TOP();
2882
            DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE);
2883
            DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
2884
            STAT_INC(UNPACK_SEQUENCE, hit);
2885
            STACK_SHRINK(1);
2886
            PyObject **items = _PyList_ITEMS(seq);
2887
            while (oparg--) {
  Branch (2887:20): [True: 1.47M, False: 701k]
2888
                PUSH(Py_NewRef(items[oparg]));
2889
            }
2890
            Py_DECREF(seq);
2891
            JUMPBY(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE);
2892
            NOTRACE_DISPATCH();
2893
        }
2894
2895
        TARGET(UNPACK_EX) {
2896
            int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
2897
            PyObject *seq = POP();
2898
            PyObject **top = stack_pointer + totalargs;
2899
            if (!unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top)) {
  Branch (2899:17): [True: 4, False: 104k]
2900
                Py_DECREF(seq);
2901
                goto error;
2902
            }
2903
            STACK_GROW(totalargs);
2904
            Py_DECREF(seq);
2905
            DISPATCH();
2906
        }
2907
2908
        
TARGET104k
(STORE_ATTR) {
2909
            PREDICTED(STORE_ATTR);
2910
            PyObject *name = GETITEM(names, oparg);
2911
            PyObject *owner = TOP();
2912
            PyObject *v = SECOND();
2913
            int err;
2914
            STACK_SHRINK(2);
2915
            err = PyObject_SetAttr(owner, name, v);
2916
            Py_DECREF(v);
2917
            Py_DECREF(owner);
2918
            if (err != 0) {
  Branch (2918:17): [True: 1.09k, False: 7.14M]
2919
                goto error;
2920
            }
2921
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_ATTR);
2922
            DISPATCH();
2923
        }
2924
2925
        TARGET(DELETE_ATTR) {
2926
            PyObject *name = GETITEM(names, oparg);
2927
            PyObject *owner = POP();
2928
            int err;
2929
            err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
2930
            Py_DECREF(owner);
2931
            if (err != 0)
  Branch (2931:17): [True: 243, False: 1.89M]
2932
                goto error;
2933
            DISPATCH();
2934
        }
2935
2936
        TARGET(STORE_GLOBAL) {
2937
            PyObject *name = GETITEM(names, oparg);
2938
            PyObject *v = POP();
2939
            int err;
2940
            err = PyDict_SetItem(GLOBALS(), name, v);
2941
            Py_DECREF(v);
2942
            if (err != 0)
  Branch (2942:17): [True: 0, False: 14.4k]
2943
                goto error;
2944
            DISPATCH();
2945
        }
2946
2947
        TARGET(DELETE_GLOBAL) {
2948
            PyObject *name = GETITEM(names, oparg);
2949
            int err;
2950
            err = PyDict_DelItem(GLOBALS(), name);
2951
            if (err != 0) {
  Branch (2951:17): [True: 0, False: 9]
2952
                if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (2952:21): [True: 0, False: 0]
2953
                    format_exc_check_arg(tstate, PyExc_NameError,
2954
                                         NAME_ERROR_MSG, name);
2955
                }
2956
                goto error;
2957
            }
2958
            DISPATCH();
2959
        }
2960
2961
        
TARGET9
(LOAD_NAME) {
2962
            PyObject *name = GETITEM(names, oparg);
2963
            PyObject *locals = LOCALS();
2964
            PyObject *v;
2965
            if (locals == NULL) {
  Branch (2965:17): [True: 0, False: 534k]
2966
                _PyErr_Format(tstate, PyExc_SystemError,
2967
                              "no locals when loading %R", name);
2968
                goto error;
2969
            }
2970
            if (PyDict_CheckExact(locals)) {
2971
                v = PyDict_GetItemWithError(locals, name);
2972
                if (v != NULL) {
  Branch (2972:21): [True: 350k, False: 170k]
2973
                    Py_INCREF(v);
2974
                }
2975
                else if (_PyErr_Occurred(tstate)) {
  Branch (2975:26): [True: 0, False: 170k]
2976
                    goto error;
2977
                }
2978
            }
2979
            else {
2980
                v = PyObject_GetItem(locals, name);
2981
                if (v == NULL) {
  Branch (2981:21): [True: 8.68k, False: 5.30k]
2982
                    if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError))
  Branch (2982:25): [True: 1, False: 8.68k]
2983
                        goto error;
2984
                    _PyErr_Clear(tstate);
2985
                }
2986
            }
2987
            if (v == NULL) {
  Branch (2987:17): [True: 179k, False: 355k]
2988
                v = PyDict_GetItemWithError(GLOBALS(), name);
2989
                if (v != NULL) {
  Branch (2989:21): [True: 102k, False: 76.5k]
2990
                    Py_INCREF(v);
2991
                }
2992
                else if (_PyErr_Occurred(tstate)) {
  Branch (2992:26): [True: 0, False: 76.5k]
2993
                    goto error;
2994
                }
2995
                else {
2996
                    if (PyDict_CheckExact(BUILTINS())) {
2997
                        v = PyDict_GetItemWithError(BUILTINS(), name);
2998
                        if (v == NULL) {
  Branch (2998:29): [True: 89, False: 76.4k]
2999
                            if (!_PyErr_Occurred(tstate)) {
  Branch (2999:33): [True: 89, False: 0]
3000
                                format_exc_check_arg(
3001
                                        tstate, PyExc_NameError,
3002
                                        NAME_ERROR_MSG, name);
3003
                            }
3004
                            goto error;
3005
                        }
3006
                        Py_INCREF(v);
3007
                    }
3008
                    else {
3009
                        v = PyObject_GetItem(BUILTINS(), name);
3010
                        if (v == NULL) {
  Branch (3010:29): [True: 1, False: 0]
3011
                            if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (3011:33): [True: 0, False: 1]
3012
                                format_exc_check_arg(
3013
                                            tstate, PyExc_NameError,
3014
                                            NAME_ERROR_MSG, name);
3015
                            }
3016
                            goto error;
3017
                        }
3018
                    }
3019
                }
3020
            }
3021
            PUSH(v);
3022
            DISPATCH();
3023
        }
3024
3025
        
TARGET534k
(LOAD_GLOBAL) {
3026
            PREDICTED(LOAD_GLOBAL);
3027
            int push_null = oparg & 1;
3028
            PEEK(0) = NULL;
3029
            PyObject *name = GETITEM(names, oparg>>1);
3030
            PyObject *v;
3031
            if (PyDict_CheckExact(GLOBALS())
3032
                && 
PyDict_CheckExact10.3M
(BUILTINS()))
3033
            {
3034
                v = _PyDict_LoadGlobal((PyDictObject *)GLOBALS(),
3035
                                       (PyDictObject *)BUILTINS(),
3036
                                       name);
3037
                if (v == NULL) {
  Branch (3037:21): [True: 80, False: 10.3M]
3038
                    if (!_PyErr_Occurred(tstate)) {
  Branch (3038:25): [True: 80, False: 0]
3039
                        /* _PyDict_LoadGlobal() returns NULL without raising
3040
                         * an exception if the key doesn't exist */
3041
                        format_exc_check_arg(tstate, PyExc_NameError,
3042
                                             NAME_ERROR_MSG, name);
3043
                    }
3044
                    goto error;
3045
                }
3046
                Py_INCREF(v);
3047
            }
3048
            else {
3049
                /* Slow-path if globals or builtins is not a dict */
3050
3051
                /* namespace 1: globals */
3052
                v = PyObject_GetItem(GLOBALS(), name);
3053
                if (v == NULL) {
  Branch (3053:21): [True: 78, False: 30.1k]
3054
                    if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (3054:25): [True: 0, False: 78]
3055
                        goto error;
3056
                    }
3057
                    _PyErr_Clear(tstate);
3058
3059
                    /* namespace 2: builtins */
3060
                    v = PyObject_GetItem(BUILTINS(), name);
3061
                    if (v == NULL) {
  Branch (3061:25): [True: 0, False: 78]
3062
                        if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (3062:29): [True: 0, False: 0]
3063
                            format_exc_check_arg(
3064
                                        tstate, PyExc_NameError,
3065
                                        NAME_ERROR_MSG, name);
3066
                        }
3067
                        goto error;
3068
                    }
3069
                }
3070
            }
3071
            /* Skip over inline cache */
3072
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
3073
            STACK_GROW(push_null);
3074
            PUSH(v);
3075
            DISPATCH();
3076
        }
3077
3078
        TARGET(LOAD_GLOBAL_ADAPTIVE) {
3079
            assert(cframe.use_tracing == 0);
3080
            _PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
3081
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
3082
                PyObject *name = GETITEM(names, oparg>>1);
3083
                next_instr--;
3084
                if (_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name) < 0) {
  Branch (3084:21): [True: 0, False: 115k]
3085
                    goto error;
3086
                }
3087
                NOTRACE_DISPATCH_SAME_OPARG();
3088
            }
3089
            else {
3090
                STAT_INC(LOAD_GLOBAL, deferred);
3091
                DECREMENT_ADAPTIVE_COUNTER(cache);
3092
                JUMP_TO_INSTRUCTION(LOAD_GLOBAL);
3093
            }
3094
        }
3095
3096
        
TARGET619k
(LOAD_GLOBAL_MODULE) {
3097
            assert(cframe.use_tracing == 0);
3098
            DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
3099
            PyDictObject *dict = (PyDictObject *)GLOBALS();
3100
            _PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
3101
            uint32_t version = read_u32(cache->module_keys_version);
3102
            DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
3103
            assert(DK_IS_UNICODE(dict->ma_keys));
3104
            PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(dict->ma_keys);
3105
            PyObject *res = entries[cache->index].me_value;
3106
            DEOPT_IF(res == NULL, LOAD_GLOBAL);
3107
            int push_null = oparg & 1;
3108
            PEEK(0) = NULL;
3109
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
3110
            STAT_INC(LOAD_GLOBAL, hit);
3111
            STACK_GROW(push_null+1);
3112
            Py_INCREF(res);
3113
            SET_TOP(res);
3114
            NOTRACE_DISPATCH();
3115
        }
3116
3117
        TARGET(LOAD_GLOBAL_BUILTIN) {
3118
            assert(cframe.use_tracing == 0);
3119
            DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
3120
            DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL);
3121
            PyDictObject *mdict = (PyDictObject *)GLOBALS();
3122
            PyDictObject *bdict = (PyDictObject *)BUILTINS();
3123
            _PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
3124
            uint32_t mod_version = read_u32(cache->module_keys_version);
3125
            uint16_t bltn_version = cache->builtin_keys_version;
3126
            DEOPT_IF(mdict->ma_keys->dk_version != mod_version, LOAD_GLOBAL);
3127
            DEOPT_IF(bdict->ma_keys->dk_version != bltn_version, LOAD_GLOBAL);
3128
            assert(DK_IS_UNICODE(bdict->ma_keys));
3129
            PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(bdict->ma_keys);
3130
            PyObject *res = entries[cache->index].me_value;
3131
            DEOPT_IF(res == NULL, LOAD_GLOBAL);
3132
            int push_null = oparg & 1;
3133
            PEEK(0) = NULL;
3134
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
3135
            STAT_INC(LOAD_GLOBAL, hit);
3136
            STACK_GROW(push_null+1);
3137
            Py_INCREF(res);
3138
            SET_TOP(res);
3139
            NOTRACE_DISPATCH();
3140
        }
3141
3142
        TARGET(DELETE_FAST) {
3143
            PyObject *v = GETLOCAL(oparg);
3144
            if (v != NULL) {
  Branch (3144:17): [True: 1.94M, False: 0]
3145
                SETLOCAL(oparg, NULL);
3146
                DISPATCH();
3147
            }
3148
            goto unbound_local_error;
3149
        }
3150
3151
        
TARGET1.94M
(MAKE_CELL) {
3152
            // "initial" is probably NULL but not if it's an arg (or set
3153
            // via PyFrame_LocalsToFast() before MAKE_CELL has run).
3154
            PyObject *initial = GETLOCAL(oparg);
3155
            PyObject *cell = PyCell_New(initial);
3156
            if (cell == NULL) {
  Branch (3156:17): [True: 0, False: 3.29M]
3157
                goto resume_with_error;
3158
            }
3159
            SETLOCAL(oparg, cell);
3160
            DISPATCH();
3161
        }
3162
3163
        TARGET(DELETE_DEREF) {
3164
            PyObject *cell = GETLOCAL(oparg);
3165
            PyObject *oldobj = PyCell_GET(cell);
3166
            if (oldobj != NULL) {
  Branch (3166:17): [True: 38, False: 0]
3167
                PyCell_SET(cell, NULL);
3168
                Py_DECREF(oldobj);
3169
                DISPATCH();
3170
            }
3171
            format_exc_unbound(tstate, frame->f_code, oparg);
3172
            goto error;
3173
        }
3174
3175
        
TARGET38
(LOAD_CLASSDEREF) {
3176
            PyObject *name, *value, *locals = LOCALS();
3177
            assert(locals);
3178
            assert(oparg >= 0 && oparg < frame->f_code->co_nlocalsplus);
3179
            name = PyTuple_GET_ITEM(frame->f_code->co_localsplusnames, oparg);
3180
            if (PyDict_CheckExact(locals)) {
3181
                value = PyDict_GetItemWithError(locals, name);
3182
                if (value != NULL) {
  Branch (3182:21): [True: 1, False: 1.07k]
3183
                    Py_INCREF(value);
3184
                }
3185
                else if (_PyErr_Occurred(tstate)) {
  Branch (3185:26): [True: 0, False: 1.07k]
3186
                    goto error;
3187
                }
3188
            }
3189
            else {
3190
                value = PyObject_GetItem(locals, name);
3191
                if (value == NULL) {
  Branch (3191:21): [True: 439, False: 0]
3192
                    if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (3192:25): [True: 0, False: 439]
3193
                        goto error;
3194
                    }
3195
                    _PyErr_Clear(tstate);
3196
                }
3197
            }
3198
            if (!value) {
  Branch (3198:17): [True: 1.51k, False: 1]
3199
                PyObject *cell = GETLOCAL(oparg);
3200
                value = PyCell_GET(cell);
3201
                if (value == NULL) {
  Branch (3201:21): [True: 0, False: 1.51k]
3202
                    format_exc_unbound(tstate, frame->f_code, oparg);
3203
                    goto error;
3204
                }
3205
                Py_INCREF(value);
3206
            }
3207
            PUSH(value);
3208
            DISPATCH();
3209
        }
3210
3211
        
TARGET1.51k
(LOAD_DEREF) {
3212
            PyObject *cell = GETLOCAL(oparg);
3213
            PyObject *value = PyCell_GET(cell);
3214
            if (value == NULL) {
  Branch (3214:17): [True: 8, False: 79.9M]
3215
                format_exc_unbound(tstate, frame->f_code, oparg);
3216
                goto error;
3217
            }
3218
            Py_INCREF(value);
3219
            PUSH(value);
3220
            DISPATCH();
3221
        }
3222
3223
        TARGET(STORE_DEREF) {
3224
            PyObject *v = POP();
3225
            PyObject *cell = GETLOCAL(oparg);
3226
            PyObject *oldobj = PyCell_GET(cell);
3227
            PyCell_SET(cell, v);
3228
            Py_XDECREF(oldobj);
3229
            DISPATCH();
3230
        }
3231
3232
        
TARGET929k
(COPY_FREE_VARS) {
3233
            /* Copy closure variables to free variables */
3234
            PyCodeObject *co = frame->f_code;
3235
            PyObject *closure = frame->f_func->func_closure;
3236
            int offset = co->co_nlocals + co->co_nplaincellvars;
3237
            assert(oparg == co->co_nfreevars);
3238
            for (int i = 0; i < oparg; 
++i35.4M
) {
  Branch (3238:29): [True: 35.4M, False: 17.1M]
3239
                PyObject *o = PyTuple_GET_ITEM(closure, i);
3240
                Py_INCREF(o);
3241
                frame->localsplus[offset + i] = o;
3242
            }
3243
            DISPATCH();
3244
        }
3245
3246
        TARGET(BUILD_STRING) {
3247
            PyObject *str;
3248
            str = _PyUnicode_JoinArray(&_Py_STR(empty),
3249
                                       stack_pointer - oparg, oparg);
3250
            if (str == NULL)
  Branch (3250:17): [True: 0, False: 375k]
3251
                goto error;
3252
            
while (375k
--oparg >= 0) {
  Branch (3252:20): [True: 1.18M, False: 375k]
3253
                PyObject *item = POP();
3254
                Py_DECREF(item);
3255
            }
3256
            PUSH(str);
3257
            DISPATCH();
3258
        }
3259
3260
        
TARGET375k
(BUILD_TUPLE) {
3261
            PyObject *tup = PyTuple_New(oparg);
3262
            if (tup == NULL)
  Branch (3262:17): [True: 0, False: 28.5M]
3263
                goto error;
3264
            
while (28.5M
--oparg >= 0) {
  Branch (3264:20): [True: 78.7M, False: 28.5M]
3265
                PyObject *item = POP();
3266
                PyTuple_SET_ITEM(tup, oparg, item);
3267
            }
3268
            PUSH(tup);
3269
            DISPATCH();
3270
        }
3271
3272
        TARGET(BUILD_LIST) {
3273
            PyObject *list =  PyList_New(oparg);
3274
            if (list == NULL)
  Branch (3274:17): [True: 0, False: 10.1M]
3275
                goto error;
3276
            
while (10.1M
--oparg >= 0) {
  Branch (3276:20): [True: 6.37M, False: 10.1M]
3277
                PyObject *item = POP();
3278
                PyList_SET_ITEM(list, oparg, item);
3279
            }
3280
            PUSH(list);
3281
            DISPATCH();
3282
        }
3283
3284
        TARGET(LIST_TO_TUPLE) {
3285
            PyObject *list = POP();
3286
            PyObject *tuple = PyList_AsTuple(list);
3287
            Py_DECREF(list);
3288
            if (tuple == NULL) {
  Branch (3288:17): [True: 0, False: 2.43M]
3289
                goto error;
3290
            }
3291
            PUSH(tuple);
3292
            DISPATCH();
3293
        }
3294
3295
        
TARGET2.43M
(LIST_EXTEND) {
3296
            PyObject *iterable = POP();
3297
            PyObject *list = PEEK(oparg);
3298
            PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable);
3299
            if (none_val == NULL) {
  Branch (3299:17): [True: 20, False: 2.48M]
3300
                if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
  Branch (3300:21): [True: 20, False: 0]
3301
                   (Py_TYPE(iterable)->tp_iter == NULL && 
!PySequence_Check(iterable)17
))
  Branch (3301:21): [True: 17, False: 3]
  Branch (3301:59): [True: 16, False: 1]
3302
                {
3303
                    _PyErr_Clear(tstate);
3304
                    _PyErr_Format(tstate, PyExc_TypeError,
3305
                          "Value after * must be an iterable, not %.200s",
3306
                          Py_TYPE(iterable)->tp_name);
3307
                }
3308
                Py_DECREF(iterable);
3309
                goto error;
3310
            }
3311
            Py_DECREF(none_val);
3312
            Py_DECREF(iterable);
3313
            DISPATCH();
3314
        }
3315
3316
        TARGET(SET_UPDATE) {
3317
            PyObject *iterable = POP();
3318
            PyObject *set = PEEK(oparg);
3319
            int err = _PySet_Update(set, iterable);
3320
            Py_DECREF(iterable);
3321
            if (err < 0) {
  Branch (3321:17): [True: 1, False: 2.05k]
3322
                goto error;
3323
            }
3324
            DISPATCH();
3325
        }
3326
3327
        
TARGET2.05k
(BUILD_SET) {
3328
            PyObject *set = PySet_New(NULL);
3329
            int err = 0;
3330
            int i;
3331
            if (set == NULL)
  Branch (3331:17): [True: 0, False: 733k]
3332
                goto error;
3333
            
for (i = oparg; 733k
i > 0;
i--1.86M
) {
  Branch (3333:29): [True: 1.86M, False: 733k]
3334
                PyObject *item = PEEK(i);
3335
                if (err == 0)
  Branch (3335:21): [True: 1.86M, False: 0]
3336
                    err = PySet_Add(set, item);
3337
                Py_DECREF(item);
3338
            }
3339
            STACK_SHRINK(oparg);
3340
            if (err != 0) {
  Branch (3340:17): [True: 1, False: 733k]
3341
                Py_DECREF(set);
3342
                goto error;
3343
            }
3344
            PUSH(set);
3345
            DISPATCH();
3346
        }
3347
3348
        
TARGET733k
(BUILD_MAP) {
3349
            PyObject *map = _PyDict_FromItems(
3350
                    &PEEK(2*oparg), 2,
3351
                    &PEEK(2*oparg - 1), 2,
3352
                    oparg);
3353
            if (map == NULL)
  Branch (3353:17): [True: 0, False: 8.63M]
3354
                goto error;
3355
3356
            
while (8.63M
oparg--) {
  Branch (3356:20): [True: 400k, False: 8.63M]
3357
                Py_DECREF(POP());
3358
                Py_DECREF(POP());
3359
            }
3360
            PUSH(map);
3361
            DISPATCH();
3362
        }
3363
3364
        TARGET(SETUP_ANNOTATIONS) {
3365
            int err;
3366
            PyObject *ann_dict;
3367
            if (LOCALS() == NULL) {
  Branch (3367:17): [True: 0, False: 940]
3368
                _PyErr_Format(tstate, PyExc_SystemError,
3369
                              "no locals found when setting up annotations");
3370
                goto error;
3371
            }
3372
            /* check if __annotations__ in locals()... */
3373
            if (PyDict_CheckExact(LOCALS())) {
3374
                ann_dict = _PyDict_GetItemWithError(LOCALS(),
3375
                                                    &_Py_ID(__annotations__));
3376
                if (ann_dict == NULL) {
  Branch (3376:21): [True: 935, False: 3]
3377
                    if (_PyErr_Occurred(tstate)) {
  Branch (3377:25): [True: 0, False: 935]
3378
                        goto error;
3379
                    }
3380
                    /* ...if not, create a new one */
3381
                    ann_dict = PyDict_New();
3382
                    if (ann_dict == NULL) {
  Branch (3382:25): [True: 0, False: 935]
3383
                        goto error;
3384
                    }
3385
                    err = PyDict_SetItem(LOCALS(), &_Py_ID(__annotations__),
3386
                                         ann_dict);
3387
                    Py_DECREF(ann_dict);
3388
                    if (err != 0) {
  Branch (3388:25): [True: 0, False: 935]
3389
                        goto error;
3390
                    }
3391
                }
3392
            }
3393
            else {
3394
                /* do the same if locals() is not a dict */
3395
                ann_dict = PyObject_GetItem(LOCALS(), &_Py_ID(__annotations__));
3396
                if (ann_dict == NULL) {
  Branch (3396:21): [True: 1, False: 1]
3397
                    if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (3397:25): [True: 0, False: 1]
3398
                        goto error;
3399
                    }
3400
                    _PyErr_Clear(tstate);
3401
                    ann_dict = PyDict_New();
3402
                    if (ann_dict == NULL) {
  Branch (3402:25): [True: 0, False: 1]
3403
                        goto error;
3404
                    }
3405
                    err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__),
3406
                                           ann_dict);
3407
                    Py_DECREF(ann_dict);
3408
                    if (err != 0) {
  Branch (3408:25): [True: 0, False: 1]
3409
                        goto error;
3410
                    }
3411
                }
3412
                else {
3413
                    Py_DECREF(ann_dict);
3414
                }
3415
            }
3416
            DISPATCH();
3417
        }
3418
3419
        
TARGET940
(BUILD_CONST_KEY_MAP) {
3420
            PyObject *map;
3421
            PyObject *keys = TOP();
3422
            if (!PyTuple_CheckExact(keys) ||
  Branch (3422:17): [True: 0, False: 64.6k]
3423
                PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) {
  Branch (3423:17): [True: 0, False: 64.6k]
3424
                _PyErr_SetString(tstate, PyExc_SystemError,
3425
                                 "bad BUILD_CONST_KEY_MAP keys argument");
3426
                goto error;
3427
            }
3428
            map = _PyDict_FromItems(
3429
                    &PyTuple_GET_ITEM(keys, 0), 1,
3430
                    &PEEK(oparg + 1), 1, oparg);
3431
            if (map == NULL) {
  Branch (3431:17): [True: 0, False: 64.6k]
3432
                goto error;
3433
            }
3434
3435
            Py_DECREF(POP());
3436
            while (oparg--) {
  Branch (3436:20): [True: 198k, False: 64.6k]
3437
                Py_DECREF(POP());
3438
            }
3439
            PUSH(map);
3440
            DISPATCH();
3441
        }
3442
3443
        TARGET(DICT_UPDATE) {
3444
            PyObject *update = POP();
3445
            PyObject *dict = PEEK(oparg);
3446
            if (PyDict_Update(dict, update) < 0) {
  Branch (3446:17): [True: 3, False: 21.0k]
3447
                if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
  Branch (3447:21): [True: 2, False: 1]
3448
                    _PyErr_Format(tstate, PyExc_TypeError,
3449
                                    "'%.200s' object is not a mapping",
3450
                                    Py_TYPE(update)->tp_name);
3451
                }
3452
                Py_DECREF(update);
3453
                goto error;
3454
            }
3455
            Py_DECREF(update);
3456
            DISPATCH();
3457
        }
3458
3459
        
TARGET21.0k
(DICT_MERGE) {
3460
            PyObject *update = POP();
3461
            PyObject *dict = PEEK(oparg);
3462
3463
            if (_PyDict_MergeEx(dict, update, 2) < 0) {
  Branch (3463:17): [True: 23, False: 4.12M]
3464
                format_kwargs_error(tstate, PEEK(2 + oparg), update);
3465
                Py_DECREF(update);
3466
                goto error;
3467
            }
3468
            Py_DECREF(update);
3469
            PREDICT(CALL_FUNCTION_EX);
3470
            DISPATCH();
3471
        }
3472
3473
        TARGET(MAP_ADD) {
3474
            PyObject *value = TOP();
3475
            PyObject *key = SECOND();
3476
            PyObject *map;
3477
            STACK_SHRINK(2);
3478
            map = PEEK(oparg);                      /* dict */
3479
            assert(PyDict_CheckExact(map));
3480
            /* map[key] = value */
3481
            if (_PyDict_SetItem_Take2((PyDictObject *)map, key, value) != 0) {
  Branch (3481:17): [True: 1, False: 333k]
3482
                goto error;
3483
            }
3484
            PREDICT(JUMP_BACKWARD_QUICK);
3485
            DISPATCH();
3486
        }
3487
3488
        
TARGET333k
(LOAD_ATTR) {
3489
            PREDICTED(LOAD_ATTR);
3490
            PyObject *name = GETITEM(names, oparg >> 1);
3491
            PyObject *owner = TOP();
3492
            if (oparg & 1) {
  Branch (3492:17): [True: 27.2M, False: 71.7M]
3493
                /* Designed to work in tandem with CALL. */
3494
                PyObject* meth = NULL;
3495
3496
                int meth_found = _PyObject_GetMethod(owner, name, &meth);
3497
3498
                if (meth == NULL) {
  Branch (3498:21): [True: 1.64k, False: 27.2M]
3499
                    /* Most likely attribute wasn't found. */
3500
                    goto error;
3501
                }
3502
3503
                if (meth_found) {
  Branch (3503:21): [True: 19.9M, False: 7.35M]
3504
                    /* We can bypass temporary bound method object.
3505
                       meth is unbound method and obj is self.
3506
3507
                       meth | self | arg1 | ... | argN
3508
                     */
3509
                    SET_TOP(meth);
3510
                    PUSH(owner);  // self
3511
                }
3512
                else {
3513
                    /* meth is not an unbound method (but a regular attr, or
3514
                       something was returned by a descriptor protocol).  Set
3515
                       the second element of the stack to NULL, to signal
3516
                       CALL that it's not a method call.
3517
3518
                       NULL | meth | arg1 | ... | argN
3519
                    */
3520
                    SET_TOP(NULL);
3521
                    Py_DECREF(owner);
3522
                    PUSH(meth);
3523
                }
3524
                JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3525
                DISPATCH();
3526
            }
3527
            PyObject *res = PyObject_GetAttr(owner, name);
3528
            if (res == NULL) {
  Branch (3528:17): [True: 104k, False: 98.9M]
3529
                goto error;
3530
            }
3531
            Py_DECREF(owner);
3532
            SET_TOP(res);
3533
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3534
            DISPATCH();
3535
        }
3536
3537
        TARGET(LOAD_ATTR_ADAPTIVE) {
3538
            assert(cframe.use_tracing == 0);
3539
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3540
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
3541
                PyObject *owner = TOP();
3542
                PyObject *name = GETITEM(names, oparg>>1);
3543
                next_instr--;
3544
                if (_Py_Specialize_LoadAttr(owner, next_instr, name) < 0) {
  Branch (3544:21): [True: 0, False: 489k]
3545
                    goto error;
3546
                }
3547
                NOTRACE_DISPATCH_SAME_OPARG();
3548
            }
3549
            else {
3550
                STAT_INC(LOAD_ATTR, deferred);
3551
                DECREMENT_ADAPTIVE_COUNTER(cache);
3552
                JUMP_TO_INSTRUCTION(LOAD_ATTR);
3553
            }
3554
        }
3555
3556
        
TARGET70.8M
(LOAD_ATTR_INSTANCE_VALUE) {
3557
            assert(cframe.use_tracing == 0);
3558
            PyObject *owner = TOP();
3559
            PyObject *res;
3560
            PyTypeObject *tp = Py_TYPE(owner);
3561
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3562
            uint32_t type_version = read_u32(cache->version);
3563
            assert(type_version != 0);
3564
            DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
3565
            assert(tp->tp_dictoffset < 0);
3566
            assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
3567
            PyDictValues *values = *_PyObject_ValuesPointer(owner);
3568
            DEOPT_IF(values == NULL, LOAD_ATTR);
3569
            res = values->values[cache->index];
3570
            DEOPT_IF(res == NULL, LOAD_ATTR);
3571
            STAT_INC(LOAD_ATTR, hit);
3572
            Py_INCREF(res);
3573
            SET_TOP(NULL);
3574
            STACK_GROW((oparg & 1));
3575
            SET_TOP(res);
3576
            Py_DECREF(owner);
3577
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3578
            NOTRACE_DISPATCH();
3579
        }
3580
3581
        TARGET(LOAD_ATTR_MODULE) {
3582
            assert(cframe.use_tracing == 0);
3583
            PyObject *owner = TOP();
3584
            PyObject *res;
3585
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3586
            DEOPT_IF(!PyModule_CheckExact(owner), LOAD_ATTR);
3587
            PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner)->md_dict;
3588
            assert(dict != NULL);
3589
            DEOPT_IF(dict->ma_keys->dk_version != read_u32(cache->version),
3590
                LOAD_ATTR);
3591
            assert(dict->ma_keys->dk_kind == DICT_KEYS_UNICODE);
3592
            assert(cache->index < dict->ma_keys->dk_nentries);
3593
            PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + cache->index;
3594
            res = ep->me_value;
3595
            DEOPT_IF(res == NULL, LOAD_ATTR);
3596
            STAT_INC(LOAD_ATTR, hit);
3597
            Py_INCREF(res);
3598
            SET_TOP(NULL);
3599
            STACK_GROW((oparg & 1));
3600
            SET_TOP(res);
3601
            Py_DECREF(owner);
3602
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3603
            NOTRACE_DISPATCH();
3604
        }
3605
3606
        TARGET(LOAD_ATTR_WITH_HINT) {
3607
            assert(cframe.use_tracing == 0);
3608
            PyObject *owner = TOP();
3609
            PyObject *res;
3610
            PyTypeObject *tp = Py_TYPE(owner);
3611
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3612
            uint32_t type_version = read_u32(cache->version);
3613
            assert(type_version != 0);
3614
            DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
3615
            assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
3616
            PyDictObject *dict = *(PyDictObject **)_PyObject_ManagedDictPointer(owner);
3617
            DEOPT_IF(dict == NULL, LOAD_ATTR);
3618
            assert(PyDict_CheckExact((PyObject *)dict));
3619
            PyObject *name = GETITEM(names, oparg>>1);
3620
            uint16_t hint = cache->index;
3621
            DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR);
3622
            if (DK_IS_UNICODE(dict->ma_keys)) {
3623
                PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
3624
                DEOPT_IF(ep->me_key != name, LOAD_ATTR);
3625
                res = ep->me_value;
3626
            }
3627
            else {
3628
                PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + hint;
3629
                DEOPT_IF(ep->me_key != name, LOAD_ATTR);
3630
                res = ep->me_value;
3631
            }
3632
            DEOPT_IF(res == NULL, LOAD_ATTR);
3633
            STAT_INC(LOAD_ATTR, hit);
3634
            Py_INCREF(res);
3635
            SET_TOP(NULL);
3636
            STACK_GROW((oparg & 1));
3637
            SET_TOP(res);
3638
            Py_DECREF(owner);
3639
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3640
            NOTRACE_DISPATCH();
3641
        }
3642
3643
        
TARGET4.10M
(LOAD_ATTR_SLOT) {
3644
            assert(cframe.use_tracing == 0);
3645
            PyObject *owner = TOP();
3646
            PyObject *res;
3647
            PyTypeObject *tp = Py_TYPE(owner);
3648
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3649
            uint32_t type_version = read_u32(cache->version);
3650
            assert(type_version != 0);
3651
            DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
3652
            char *addr = (char *)owner + cache->index;
3653
            res = *(PyObject **)addr;
3654
            DEOPT_IF(res == NULL, LOAD_ATTR);
3655
            STAT_INC(LOAD_ATTR, hit);
3656
            Py_INCREF(res);
3657
            SET_TOP(NULL);
3658
            STACK_GROW((oparg & 1));
3659
            SET_TOP(res);
3660
            Py_DECREF(owner);
3661
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3662
            NOTRACE_DISPATCH();
3663
        }
3664
3665
        TARGET(LOAD_ATTR_CLASS) {
3666
            assert(cframe.use_tracing == 0);
3667
            _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
3668
3669
            PyObject *cls = TOP();
3670
            DEOPT_IF(!PyType_Check(cls), LOAD_ATTR);
3671
            uint32_t type_version = read_u32(cache->type_version);
3672
            DEOPT_IF(((PyTypeObject *)cls)->tp_version_tag != type_version,
3673
                LOAD_ATTR);
3674
            assert(type_version != 0);
3675
3676
            STAT_INC(LOAD_ATTR, hit);
3677
            PyObject *res = read_obj(cache->descr);
3678
            assert(res != NULL);
3679
            Py_INCREF(res);
3680
            SET_TOP(NULL);
3681
            STACK_GROW((oparg & 1));
3682
            SET_TOP(res);
3683
            Py_DECREF(cls);
3684
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3685
            NOTRACE_DISPATCH();
3686
        }
3687
3688
        TARGET(LOAD_ATTR_PROPERTY) {
3689
            assert(cframe.use_tracing == 0);
3690
            DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR);
3691
            _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
3692
3693
            PyObject *owner = TOP();
3694
            PyTypeObject *cls = Py_TYPE(owner);
3695
            uint32_t type_version = read_u32(cache->type_version);
3696
            DEOPT_IF(cls->tp_version_tag != type_version, LOAD_ATTR);
3697
            assert(type_version != 0);
3698
            PyObject *fget = read_obj(cache->descr);
3699
            PyFunctionObject *f = (PyFunctionObject *)fget;
3700
            uint32_t func_version = read_u32(cache->keys_version);
3701
            assert(func_version != 0);
3702
            DEOPT_IF(f->func_version != func_version, LOAD_ATTR);
3703
            PyCodeObject *code = (PyCodeObject *)f->func_code;
3704
            assert(code->co_argcount == 1);
3705
            DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR);
3706
            STAT_INC(LOAD_ATTR, hit);
3707
            Py_INCREF(fget);
3708
            _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f);
3709
            SET_TOP(NULL);
3710
            int push_null = !(oparg & 1);
3711
            STACK_SHRINK(push_null);
3712
            new_frame->localsplus[0] = owner;
3713
            for (int i = 1; i < code->co_nlocalsplus; 
i++130k
) {
  Branch (3713:29): [True: 130k, False: 3.93M]
3714
                new_frame->localsplus[i] = NULL;
3715
            }
3716
            _PyFrame_SetStackPointer(frame, stack_pointer);
3717
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
3718
            frame->prev_instr = next_instr - 1;
3719
            new_frame->previous = frame;
3720
            frame = cframe.current_frame = new_frame;
3721
            CALL_STAT_INC(inlined_py_calls);
3722
            goto start_frame;
3723
        }
3724
3725
        
TARGET3.93M
(STORE_ATTR_ADAPTIVE) {
3726
            assert(cframe.use_tracing == 0);
3727
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3728
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
3729
                PyObject *owner = TOP();
3730
                PyObject *name = GETITEM(names, oparg);
3731
                next_instr--;
3732
                if (_Py_Specialize_StoreAttr(owner, next_instr, name) < 0) {
  Branch (3732:21): [True: 0, False: 54.2k]
3733
                    goto error;
3734
                }
3735
                NOTRACE_DISPATCH_SAME_OPARG();
3736
            }
3737
            else {
3738
                STAT_INC(STORE_ATTR, deferred);
3739
                DECREMENT_ADAPTIVE_COUNTER(cache);
3740
                JUMP_TO_INSTRUCTION(STORE_ATTR);
3741
            }
3742
        }
3743
3744
        
TARGET5.84M
(STORE_ATTR_INSTANCE_VALUE) {
3745
            assert(cframe.use_tracing == 0);
3746
            PyObject *owner = TOP();
3747
            PyTypeObject *tp = Py_TYPE(owner);
3748
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3749
            uint32_t type_version = read_u32(cache->version);
3750
            assert(type_version != 0);
3751
            DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR);
3752
            assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
3753
            PyDictValues *values = *_PyObject_ValuesPointer(owner);
3754
            DEOPT_IF(values == NULL, STORE_ATTR);
3755
            STAT_INC(STORE_ATTR, hit);
3756
            Py_ssize_t index = cache->index;
3757
            STACK_SHRINK(1);
3758
            PyObject *value = POP();
3759
            PyObject *old_value = values->values[index];
3760
            values->values[index] = value;
3761
            if (old_value == NULL) {
  Branch (3761:17): [True: 29.3M, False: 14.6M]
3762
                _PyDictValues_AddToInsertionOrder(values, index);
3763
            }
3764
            else {
3765
                Py_DECREF(old_value);
3766
            }
3767
            Py_DECREF(owner);
3768
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_ATTR);
3769
            NOTRACE_DISPATCH();
3770
        }
3771
3772
        TARGET(STORE_ATTR_WITH_HINT) {
3773
            assert(cframe.use_tracing == 0);
3774
            PyObject *owner = TOP();
3775
            PyTypeObject *tp = Py_TYPE(owner);
3776
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3777
            uint32_t type_version = read_u32(cache->version);
3778
            assert(type_version != 0);
3779
            DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR);
3780
            assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
3781
            PyDictObject *dict = *(PyDictObject **)_PyObject_ManagedDictPointer(owner);
3782
            DEOPT_IF(dict == NULL, STORE_ATTR);
3783
            assert(PyDict_CheckExact((PyObject *)dict));
3784
            PyObject *name = GETITEM(names, oparg);
3785
            uint16_t hint = cache->index;
3786
            DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR);
3787
            PyObject *value, *old_value;
3788
            if (DK_IS_UNICODE(dict->ma_keys)) {
3789
                PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
3790
                DEOPT_IF(ep->me_key != name, STORE_ATTR);
3791
                old_value = ep->me_value;
3792
                DEOPT_IF(old_value == NULL, STORE_ATTR);
3793
                STACK_SHRINK(1);
3794
                value = POP();
3795
                ep->me_value = value;
3796
            }
3797
            else {
3798
                PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + hint;
3799
                DEOPT_IF(ep->me_key != name, STORE_ATTR);
3800
                old_value = ep->me_value;
3801
                DEOPT_IF(old_value == NULL, STORE_ATTR);
3802
                STACK_SHRINK(1);
3803
                value = POP();
3804
                ep->me_value = value;
3805
            }
3806
            Py_DECREF(old_value);
3807
            STAT_INC(STORE_ATTR, hit);
3808
            /* Ensure dict is GC tracked if it needs to be */
3809
            if (!_PyObject_GC_IS_TRACKED(dict) && 
_PyObject_GC_MAY_BE_TRACKED(value)0
) {
  Branch (3809:17): [True: 0, False: 28.2k]
  Branch (3809:51): [True: 0, False: 0]
3810
                _PyObject_GC_TRACK(dict);
3811
            }
3812
            /* PEP 509 */
3813
            dict->ma_version_tag = DICT_NEXT_VERSION();
3814
            Py_DECREF(owner);
3815
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_ATTR);
3816
            NOTRACE_DISPATCH();
3817
        }
3818
3819
        
TARGET28.2k
(STORE_ATTR_SLOT) {
3820
            assert(cframe.use_tracing == 0);
3821
            PyObject *owner = TOP();
3822
            PyTypeObject *tp = Py_TYPE(owner);
3823
            _PyAttrCache *cache = (_PyAttrCache *)next_instr;
3824
            uint32_t type_version = read_u32(cache->version);
3825
            assert(type_version != 0);
3826
            DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR);
3827
            char *addr = (char *)owner + cache->index;
3828
            STAT_INC(STORE_ATTR, hit);
3829
            STACK_SHRINK(1);
3830
            PyObject *value = POP();
3831
            PyObject *old_value = *(PyObject **)addr;
3832
            *(PyObject **)addr = value;
3833
            Py_XDECREF(old_value);
3834
            Py_DECREF(owner);
3835
            JUMPBY(INLINE_CACHE_ENTRIES_STORE_ATTR);
3836
            NOTRACE_DISPATCH();
3837
        }
3838
3839
        
TARGET6.70M
(COMPARE_OP) {
3840
            PREDICTED(COMPARE_OP);
3841
            assert(oparg <= Py_GE);
3842
            PyObject *right = POP();
3843
            PyObject *left = TOP();
3844
            PyObject *res = PyObject_RichCompare(left, right, oparg);
3845
            SET_TOP(res);
3846
            Py_DECREF(left);
3847
            Py_DECREF(right);
3848
            if (res == NULL) {
  Branch (3848:17): [True: 6.64k, False: 31.9M]
3849
                goto error;
3850
            }
3851
            JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
3852
            DISPATCH();
3853
        }
3854
3855
        TARGET(COMPARE_OP_ADAPTIVE) {
3856
            assert(cframe.use_tracing == 0);
3857
            _PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
3858
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
3859
                PyObject *right = TOP();
3860
                PyObject *left = SECOND();
3861
                next_instr--;
3862
                _Py_Specialize_CompareOp(left, right, next_instr, oparg);
3863
                NOTRACE_DISPATCH_SAME_OPARG();
3864
            }
3865
            else {
3866
                STAT_INC(COMPARE_OP, deferred);
3867
                DECREMENT_ADAPTIVE_COUNTER(cache);
3868
                JUMP_TO_INSTRUCTION(COMPARE_OP);
3869
            }
3870
        }
3871
3872
        TARGET(COMPARE_OP_FLOAT_JUMP) {
3873
            assert(cframe.use_tracing == 0);
3874
            // Combined: COMPARE_OP (float ? float) + POP_JUMP_(direction)_IF_(true/false)
3875
            _PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
3876
            int when_to_jump_mask = cache->mask;
3877
            PyObject *right = TOP();
3878
            PyObject *left = SECOND();
3879
            DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
3880
            DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
3881
            double dleft = PyFloat_AS_DOUBLE(left);
3882
            double dright = PyFloat_AS_DOUBLE(right);
3883
            int sign = (dleft > dright) - (dleft < dright);
3884
            DEOPT_IF(isnan(dleft), COMPARE_OP);
3885
            DEOPT_IF(isnan(dright), COMPARE_OP);
3886
            STAT_INC(COMPARE_OP, hit);
3887
            JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
3888
            NEXTOPARG();
3889
            STACK_SHRINK(2);
3890
            _Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
3891
            _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
3892
            assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
3893
                   opcode == POP_JUMP_BACKWARD_IF_FALSE ||
3894
                   opcode == POP_JUMP_FORWARD_IF_TRUE ||
3895
                   opcode == POP_JUMP_BACKWARD_IF_TRUE);
3896
            int jump = (9 << (sign + 1)) & when_to_jump_mask;
3897
            if (!jump) {
  Branch (3897:17): [True: 4.52M, False: 7.34M]
3898
                next_instr++;
3899
            }
3900
            else if (jump >= 8) {
  Branch (3900:22): [True: 58.0k, False: 7.28M]
3901
                assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
3902
                       opcode == POP_JUMP_BACKWARD_IF_FALSE);
3903
                JUMPBY(1 - oparg);
3904
                CHECK_EVAL_BREAKER();
3905
            }
3906
            else {
3907
                assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
3908
                       opcode == POP_JUMP_FORWARD_IF_FALSE);
3909
                JUMPBY(1 + oparg);
3910
            }
3911
            NOTRACE_DISPATCH();
3912
        }
3913
3914
        
TARGET11.8M
(COMPARE_OP_INT_JUMP) {
3915
            assert(cframe.use_tracing == 0);
3916
            // Combined: COMPARE_OP (int ? int) + POP_JUMP_(direction)_IF_(true/false)
3917
            _PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
3918
            int when_to_jump_mask = cache->mask;
3919
            PyObject *right = TOP();
3920
            PyObject *left = SECOND();
3921
            DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
3922
            DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
3923
            DEOPT_IF((size_t)(Py_SIZE(left) + 1) > 2, COMPARE_OP);
3924
            DEOPT_IF((size_t)(Py_SIZE(right) + 1) > 2, COMPARE_OP);
3925
            STAT_INC(COMPARE_OP, hit);
3926
            assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
3927
            Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->ob_digit[0];
3928
            Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->ob_digit[0];
3929
            int sign = (ileft > iright) - (ileft < iright);
3930
            JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
3931
            NEXTOPARG();
3932
            STACK_SHRINK(2);
3933
            _Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
3934
            _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
3935
            assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
3936
                   opcode == POP_JUMP_BACKWARD_IF_FALSE ||
3937
                   opcode == POP_JUMP_FORWARD_IF_TRUE ||
3938
                   opcode == POP_JUMP_BACKWARD_IF_TRUE);
3939
            int jump = (9 << (sign + 1)) & when_to_jump_mask;
3940
            if (!jump) {
  Branch (3940:17): [True: 25.6M, False: 39.3M]
3941
                next_instr++;
3942
            }
3943
            else if (jump >= 8) {
  Branch (3943:22): [True: 7.41M, False: 31.9M]
3944
                assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
3945
                       opcode == POP_JUMP_BACKWARD_IF_FALSE);
3946
                JUMPBY(1 - oparg);
3947
                CHECK_EVAL_BREAKER();
3948
            }
3949
            else {
3950
                assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
3951
                       opcode == POP_JUMP_FORWARD_IF_FALSE);
3952
                JUMPBY(1 + oparg);
3953
            }
3954
            NOTRACE_DISPATCH();
3955
        }
3956
3957
        TARGET(COMPARE_OP_STR_JUMP) {
3958
            assert(cframe.use_tracing == 0);
3959
            // Combined: COMPARE_OP (str == str or str != str) + POP_JUMP_(direction)_IF_(true/false)
3960
            _PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
3961
            int when_to_jump_mask = cache->mask;
3962
            PyObject *right = TOP();
3963
            PyObject *left = SECOND();
3964
            DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
3965
            DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
3966
            STAT_INC(COMPARE_OP, hit);
3967
            int res = _PyUnicode_Equal(left, right);
3968
            if (res < 0) {
  Branch (3968:17): [True: 0, False: 16.3M]
3969
                goto error;
3970
            }
3971
            assert(oparg == Py_EQ || oparg == Py_NE);
3972
            JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
3973
            NEXTOPARG();
3974
            assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
3975
                   opcode == POP_JUMP_BACKWARD_IF_FALSE ||
3976
                   opcode == POP_JUMP_FORWARD_IF_TRUE ||
3977
                   opcode == POP_JUMP_BACKWARD_IF_TRUE);
3978
            STACK_SHRINK(2);
3979
            _Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
3980
            _Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
3981
            assert(res == 0 || res == 1);
3982
            int sign = 1 - res;
3983
            int jump = (9 << (sign + 1)) & when_to_jump_mask;
3984
            if (!jump) {
  Branch (3984:17): [True: 4.07M, False: 12.2M]
3985
                next_instr++;
3986
            }
3987
            else if (jump >= 8) {
  Branch (3987:22): [True: 3.62M, False: 8.66M]
3988
                assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
3989
                       opcode == POP_JUMP_BACKWARD_IF_FALSE);
3990
                JUMPBY(1 - oparg);
3991
                CHECK_EVAL_BREAKER();
3992
            }
3993
            else {
3994
                assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
3995
                       opcode == POP_JUMP_FORWARD_IF_FALSE);
3996
                JUMPBY(1 + oparg);
3997
            }
3998
            NOTRACE_DISPATCH();
3999
        }
4000
4001
        
TARGET16.3M
(IS_OP) {
4002
            PyObject *right = POP();
4003
            PyObject *left = TOP();
4004
            int res = Py_Is(left, right) ^ oparg;
4005
            PyObject *b = res ? Py_True : Py_False;
  Branch (4005:27): [True: 9.95M, False: 7.98M]
4006
            Py_INCREF(b);
4007
            SET_TOP(b);
4008
            Py_DECREF(left);
4009
            Py_DECREF(right);
4010
            DISPATCH();
4011
        }
4012
4013
        
TARGET17.9M
(CONTAINS_OP) {
4014
            PyObject *right = POP();
4015
            PyObject *left = POP();
4016
            int res = PySequence_Contains(right, left);
4017
            Py_DECREF(left);
4018
            Py_DECREF(right);
4019
            if (res < 0) {
  Branch (4019:17): [True: 60, False: 22.1M]
4020
                goto error;
4021
            }
4022
            PyObject *b = (res^oparg) ? Py_True : Py_False;
  Branch (4022:27): [True: 5.96M, False: 16.2M]
4023
            Py_INCREF(b);
4024
            PUSH(b);
4025
            DISPATCH();
4026
        }
4027
4028
        TARGET(CHECK_EG_MATCH) {
4029
            PyObject *match_type = POP();
4030
            if (check_except_star_type_valid(tstate, match_type) < 0) {
  Branch (4030:17): [True: 4, False: 175]
4031
                Py_DECREF(match_type);
4032
                goto error;
4033
            }
4034
4035
            PyObject *exc_value = TOP();
4036
            PyObject *match = NULL, *rest = NULL;
4037
            int res = exception_group_match(exc_value, match_type,
4038
                                            &match, &rest);
4039
            Py_DECREF(match_type);
4040
            if (res < 0) {
  Branch (4040:17): [True: 0, False: 175]
4041
                goto error;
4042
            }
4043
4044
            if (match == NULL || rest == NULL) {
  Branch (4044:17): [True: 0, False: 175]
  Branch (4044:34): [True: 0, False: 175]
4045
                assert(match == NULL);
4046
                assert(rest == NULL);
4047
                goto error;
4048
            }
4049
            if (Py_IsNone(match)) {
4050
                PUSH(match);
4051
                Py_XDECREF(rest);
4052
            }
4053
            else {
4054
                /* Total or partial match - update the stack from
4055
                 * [val]
4056
                 * to
4057
                 * [rest, match]
4058
                 * (rest can be Py_None)
4059
                 */
4060
4061
                SET_TOP(rest);
4062
                PUSH(match);
4063
                PyErr_SetExcInfo(NULL, Py_NewRef(match), NULL);
4064
                Py_DECREF(exc_value);
4065
            }
4066
            DISPATCH();
4067
        }
4068
4069
        
TARGET175
(CHECK_EXC_MATCH) {
4070
            PyObject *right = POP();
4071
            PyObject *left = TOP();
4072
            assert(PyExceptionInstance_Check(left));
4073
            if (check_except_type_valid(tstate, right) < 0) {
  Branch (4073:17): [True: 10, False: 2.62M]
4074
                 Py_DECREF(right);
4075
                 goto error;
4076
            }
4077
4078
            int res = PyErr_GivenExceptionMatches(left, right);
4079
            Py_DECREF(right);
4080
            PUSH(Py_NewRef(res ? Py_True : Py_False));
4081
            DISPATCH();
4082
        }
4083
4084
        TARGET(IMPORT_NAME) {
4085
            PyObject *name = GETITEM(names, oparg);
4086
            PyObject *fromlist = POP();
4087
            PyObject *level = TOP();
4088
            PyObject *res;
4089
            res = import_name(tstate, frame, name, fromlist, level);
4090
            Py_DECREF(level);
4091
            Py_DECREF(fromlist);
4092
            SET_TOP(res);
4093
            if (res == NULL)
  Branch (4093:17): [True: 788, False: 258k]
4094
                goto error;
4095
            DISPATCH();
4096
        }
4097
4098
        TARGET(IMPORT_STAR) {
4099
            PyObject *from = POP(), *locals;
4100
            int err;
4101
            if (_PyFrame_FastToLocalsWithError(frame) < 0) {
  Branch (4101:17): [True: 0, False: 1.87k]
4102
                Py_DECREF(from);
4103
                goto error;
4104
            }
4105
4106
            locals = LOCALS();
4107
            if (locals == NULL) {
  Branch (4107:17): [True: 0, False: 1.87k]
4108
                _PyErr_SetString(tstate, PyExc_SystemError,
4109
                                 "no locals found during 'import *'");
4110
                Py_DECREF(from);
4111
                goto error;
4112
            }
4113
            err = import_all_from(tstate, locals, from);
4114
            _PyFrame_LocalsToFast(frame, 0);
4115
            Py_DECREF(from);
4116
            if (err != 0)
  Branch (4116:17): [True: 2, False: 1.87k]
4117
                goto error;
4118
            DISPATCH();
4119
        }
4120
4121
        
TARGET1.87k
(IMPORT_FROM) {
4122
            PyObject *name = GETITEM(names, oparg);
4123
            PyObject *from = TOP();
4124
            PyObject *res;
4125
            res = import_from(tstate, from, name);
4126
            PUSH(res);
4127
            if (res == NULL)
  Branch (4127:17): [True: 325, False: 91.5k]
4128
                goto error;
4129
            DISPATCH();
4130
        }
4131
4132
        
TARGET91.5k
(JUMP_FORWARD) {
4133
            JUMPBY(oparg);
4134
            DISPATCH();
4135
        }
4136
4137
        TARGET(JUMP_BACKWARD) {
4138
            _PyCode_Warmup(frame->f_code);
4139
            JUMP_TO_INSTRUCTION(JUMP_BACKWARD_QUICK);
4140
        }
4141
4142
        
TARGET145k
(POP_JUMP_BACKWARD_IF_FALSE) {
4143
            PREDICTED(POP_JUMP_BACKWARD_IF_FALSE);
4144
            PyObject *cond = POP();
4145
            if (Py_IsTrue(cond)) {
4146
                _Py_DECREF_NO_DEALLOC(cond);
4147
                DISPATCH();
4148
            }
4149
            if (Py_IsFalse(cond)) {
4150
                _Py_DECREF_NO_DEALLOC(cond);
4151
                JUMPBY(-oparg);
4152
                CHECK_EVAL_BREAKER();
4153
                DISPATCH();
4154
            }
4155
            int err = PyObject_IsTrue(cond);
4156
            Py_DECREF(cond);
4157
            if (err > 0)
  Branch (4157:17): [True: 1.94M, False: 20.4M]
4158
                ;
4159
            else if (err == 0) {
  Branch (4159:22): [True: 3.92M, False: 16.5M]
4160
                JUMPBY(-oparg);
4161
                CHECK_EVAL_BREAKER();
4162
            }
4163
            else
4164
                goto error;
4165
            DISPATCH();
4166
        }
4167
4168
        
TARGET5.86M
(POP_JUMP_FORWARD_IF_FALSE) {
4169
            PREDICTED(POP_JUMP_FORWARD_IF_FALSE);
4170
            PyObject *cond = POP();
4171
            if (Py_IsTrue(cond)) {
4172
                _Py_DECREF_NO_DEALLOC(cond);
4173
            }
4174
            else if (Py_IsFalse(cond)) {
4175
                _Py_DECREF_NO_DEALLOC(cond);
4176
                JUMPBY(oparg);
4177
            }
4178
            else {
4179
                int err = PyObject_IsTrue(cond);
4180
                Py_DECREF(cond);
4181
                if (err > 0)
  Branch (4181:21): [True: 14.0M, False: 10.7M]
4182
                    ;
4183
                else if (err == 0) {
  Branch (4183:26): [True: 10.7M, False: 5]
4184
                    JUMPBY(oparg);
4185
                }
4186
                else
4187
                    goto error;
4188
            }
4189
            DISPATCH();
4190
        }
4191
4192
        TARGET(POP_JUMP_BACKWARD_IF_TRUE) {
4193
            PyObject *cond = POP();
4194
            if (Py_IsFalse(cond)) {
4195
                _Py_DECREF_NO_DEALLOC(cond);
4196
                DISPATCH();
4197
            }
4198
            if (Py_IsTrue(cond)) {
4199
                _Py_DECREF_NO_DEALLOC(cond);
4200
                JUMPBY(-oparg);
4201
                CHECK_EVAL_BREAKER();
4202
                DISPATCH();
4203
            }
4204
            int err = PyObject_IsTrue(cond);
4205
            Py_DECREF(cond);
4206
            if (err > 0) {
  Branch (4206:17): [True: 1.65M, False: 5.60M]
4207
                JUMPBY(-oparg);
4208
                CHECK_EVAL_BREAKER();
4209
            }
4210
            else if (err == 0)
  Branch (4210:22): [True: 200k, False: 5.40M]
4211
                ;
4212
            else
4213
                goto error;
4214
            DISPATCH();
4215
        }
4216
4217
        
TARGET1.85M
(POP_JUMP_FORWARD_IF_TRUE) {
4218
            PyObject *cond = POP();
4219
            if (Py_IsFalse(cond)) {
4220
                _Py_DECREF_NO_DEALLOC(cond);
4221
            }
4222
            else if (Py_IsTrue(cond)) {
4223
                _Py_DECREF_NO_DEALLOC(cond);
4224
                JUMPBY(oparg);
4225
            }
4226
            else {
4227
                int err = PyObject_IsTrue(cond);
4228
                Py_DECREF(cond);
4229
                if (err > 0) {
  Branch (4229:21): [True: 13.7M, False: 1.84M]
4230
                    JUMPBY(oparg);
4231
                }
4232
                else if (err == 0)
  Branch (4232:26): [True: 1.84M, False: 1]
4233
                    ;
4234
                else
4235
                    goto error;
4236
            }
4237
            DISPATCH();
4238
        }
4239
4240
        TARGET(POP_JUMP_BACKWARD_IF_NOT_NONE) {
4241
            PyObject *value = POP();
4242
            if (!Py_IsNone(value)) {
  Branch (4242:17): [True: 212k, False: 235k]
4243
                Py_DECREF(value);
4244
                JUMPBY(-oparg);
4245
                CHECK_EVAL_BREAKER();
4246
                DISPATCH();
4247
            }
4248
            _Py_DECREF_NO_DEALLOC(value);
4249
            DISPATCH();
4250
        }
4251
4252
        
TARGET448k
(POP_JUMP_FORWARD_IF_NOT_NONE) {
4253
            PyObject *value = POP();
4254
            if (!Py_IsNone(value)) {
  Branch (4254:17): [True: 16.5M, False: 13.5M]
4255
                JUMPBY(oparg);
4256
            }
4257
            Py_DECREF(value);
4258
            DISPATCH();
4259
        }
4260
4261
        TARGET(POP_JUMP_BACKWARD_IF_NONE) {
4262
            PyObject *value = POP();
4263
            if (Py_IsNone(value)) {
4264
                _Py_DECREF_NO_DEALLOC(value);
4265
                JUMPBY(-oparg);
4266
                CHECK_EVAL_BREAKER();
4267
            }
4268
            else {
4269
                Py_DECREF(value);
4270
            }
4271
            DISPATCH();
4272
        }
4273
4274
        
TARGET1.87M
(POP_JUMP_FORWARD_IF_NONE) {
4275
            PyObject *value = POP();
4276
            if (Py_IsNone(value)) {
4277
                _Py_DECREF_NO_DEALLOC(value);
4278
                JUMPBY(oparg);
4279
            }
4280
            else {
4281
                Py_DECREF(value);
4282
            }
4283
            DISPATCH();
4284
        }
4285
4286
        TARGET(JUMP_IF_FALSE_OR_POP) {
4287
            PyObject *cond = TOP();
4288
            int err;
4289
            if (Py_IsTrue(cond)) {
4290
                STACK_SHRINK(1);
4291
                _Py_DECREF_NO_DEALLOC(cond);
4292
                DISPATCH();
4293
            }
4294
            if (Py_IsFalse(cond)) {
4295
                JUMPBY(oparg);
4296
                DISPATCH();
4297
            }
4298
            err = PyObject_IsTrue(cond);
4299
            if (err > 0) {
  Branch (4299:17): [True: 11.6k, False: 2.33M]
4300
                STACK_SHRINK(1);
4301
                Py_DECREF(cond);
4302
            }
4303
            else if (err == 0)
  Branch (4303:22): [True: 128k, False: 2.20M]
4304
                JUMPBY(oparg);
4305
            else
4306
                goto error;
4307
            DISPATCH();
4308
        }
4309
4310
        
TARGET140k
(JUMP_IF_TRUE_OR_POP) {
4311
            PyObject *cond = TOP();
4312
            int err;
4313
            if (Py_IsFalse(cond)) {
4314
                STACK_SHRINK(1);
4315
                _Py_DECREF_NO_DEALLOC(cond);
4316
                DISPATCH();
4317
            }
4318
            if (Py_IsTrue(cond)) {
4319
                JUMPBY(oparg);
4320
                DISPATCH();
4321
            }
4322
            err = PyObject_IsTrue(cond);
4323
            if (err > 0) {
  Branch (4323:17): [True: 638k, False: 2.05M]
4324
                JUMPBY(oparg);
4325
            }
4326
            else if (err == 0) {
  Branch (4326:22): [True: 1.36M, False: 683k]
4327
                STACK_SHRINK(1);
4328
                Py_DECREF(cond);
4329
            }
4330
            else
4331
                goto error;
4332
            DISPATCH();
4333
        }
4334
4335
        
TARGET2.00M
(JUMP_BACKWARD_NO_INTERRUPT) {
4336
            /* This bytecode is used in the `yield from` or `await` loop.
4337
             * If there is an interrupt, we want it handled in the innermost
4338
             * generator or coroutine, so we deliberately do not check it here.
4339
             * (see bpo-30039).
4340
             */
4341
            JUMPBY(-oparg);
4342
            DISPATCH();
4343
        }
4344
4345
        
TARGET2.28M
(JUMP_BACKWARD_QUICK) {
4346
            PREDICTED(JUMP_BACKWARD_QUICK);
4347
            assert(oparg < INSTR_OFFSET());
4348
            JUMPBY(-oparg);
4349
            CHECK_EVAL_BREAKER();
4350
            DISPATCH();
4351
        }
4352
4353
        TARGET(GET_LEN) {
4354
            // PUSH(len(TOS))
4355
            Py_ssize_t len_i = PyObject_Length(TOP());
4356
            if (len_i < 0) {
  Branch (4356:17): [True: 0, False: 221]
4357
                goto error;
4358
            }
4359
            PyObject *len_o = PyLong_FromSsize_t(len_i);
4360
            if (len_o == NULL) {
  Branch (4360:17): [True: 0, False: 221]
4361
                goto error;
4362
            }
4363
            PUSH(len_o);
4364
            DISPATCH();
4365
        }
4366
4367
        
TARGET221
(MATCH_CLASS) {
4368
            // Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
4369
            // None on failure.
4370
            PyObject *names = POP();
4371
            PyObject *type = POP();
4372
            PyObject *subject = TOP();
4373
            assert(PyTuple_CheckExact(names));
4374
            PyObject *attrs = match_class(tstate, subject, type, oparg, names);
4375
            Py_DECREF(names);
4376
            Py_DECREF(type);
4377
            if (attrs) {
  Branch (4377:17): [True: 5.50k, False: 7.19k]
4378
                // Success!
4379
                assert(PyTuple_CheckExact(attrs));
4380
                SET_TOP(attrs);
4381
            }
4382
            else if (_PyErr_Occurred(tstate)) {
  Branch (4382:22): [True: 8, False: 7.19k]
4383
                // Error!
4384
                goto error;
4385
            }
4386
            else {
4387
                // Failure!
4388
                Py_INCREF(Py_None);
4389
                SET_TOP(Py_None);
4390
            }
4391
            Py_DECREF(subject);
4392
            DISPATCH();
4393
        }
4394
4395
        TARGET(MATCH_MAPPING) {
4396
            PyObject *subject = TOP();
4397
            int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
4398
            PyObject *res = match ? Py_True : Py_False;
  Branch (4398:29): [True: 81, False: 11]
4399
            Py_INCREF(res);
4400
            PUSH(res);
4401
            PREDICT(POP_JUMP_FORWARD_IF_FALSE);
4402
            PREDICT(POP_JUMP_BACKWARD_IF_FALSE);
4403
            DISPATCH();
4404
        }
4405
4406
        
TARGET92
(MATCH_SEQUENCE) {
4407
            PyObject *subject = TOP();
4408
            int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
4409
            PyObject *res = match ? Py_True : Py_False;
  Branch (4409:29): [True: 190, False: 45]
4410
            Py_INCREF(res);
4411
            PUSH(res);
4412
            PREDICT(POP_JUMP_FORWARD_IF_FALSE);
4413
            PREDICT(POP_JUMP_BACKWARD_IF_FALSE);
4414
            DISPATCH();
4415
        }
4416
4417
        TARGET(MATCH_KEYS) {
4418
            // On successful match, PUSH(values). Otherwise, PUSH(None).
4419
            PyObject *keys = TOP();
4420
            PyObject *subject = SECOND();
4421
            PyObject *values_or_none = match_keys(tstate, subject, keys);
4422
            if (values_or_none == NULL) {
  Branch (4422:17): [True: 1, False: 46]
4423
                goto error;
4424
            }
4425
            PUSH(values_or_none);
4426
            DISPATCH();
4427
        }
4428
4429
        
TARGET46
(GET_ITER) {
4430
            /* before: [obj]; after [getiter(obj)] */
4431
            PyObject *iterable = TOP();
4432
            PyObject *iter = PyObject_GetIter(iterable);
4433
            Py_DECREF(iterable);
4434
            SET_TOP(iter);
4435
            if (iter == NULL)
  Branch (4435:17): [True: 84, False: 15.4M]
4436
                goto error;
4437
            DISPATCH();
4438
        }
4439
4440
        TARGET(GET_YIELD_FROM_ITER) {
4441
            /* before: [obj]; after [getiter(obj)] */
4442
            PyObject *iterable = TOP();
4443
            PyObject *iter;
4444
            if (PyCoro_CheckExact(iterable)) {
4445
                /* `iterable` is a coroutine */
4446
                if (!(frame->f_code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) {
  Branch (4446:21): [True: 1, False: 1]
4447
                    /* and it is used in a 'yield from' expression of a
4448
                       regular generator. */
4449
                    Py_DECREF(iterable);
4450
                    SET_TOP(NULL);
4451
                    _PyErr_SetString(tstate, PyExc_TypeError,
4452
                                     "cannot 'yield from' a coroutine object "
4453
                                     "in a non-coroutine generator");
4454
                    goto error;
4455
                }
4456
            }
4457
            else if (!PyGen_CheckExact(iterable)) {
  Branch (4457:22): [True: 9.16k, False: 240k]
4458
                /* `iterable` is not a generator. */
4459
                iter = PyObject_GetIter(iterable);
4460
                Py_DECREF(iterable);
4461
                SET_TOP(iter);
4462
                if (iter == NULL)
  Branch (4462:21): [True: 0, False: 9.16k]
4463
                    goto error;
4464
            }
4465
            PREDICT(LOAD_CONST);
4466
            DISPATCH();
4467
        }
4468
4469
        
TARGET250k
(FOR_ITER) {
4470
            PREDICTED(FOR_ITER);
4471
            /* before: [iter]; after: [iter, iter()] *or* [] */
4472
            PyObject *iter = TOP();
4473
            PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
4474
            if (next != NULL) {
  Branch (4474:17): [True: 37.2M, False: 7.00M]
4475
                PUSH(next);
4476
                JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
4477
                DISPATCH();
4478
            }
4479
            if (_PyErr_Occurred(tstate)) {
  Branch (4479:17): [True: 5.42k, False: 44.3M]
4480
                if (!_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
  Branch (4480:21): [True: 369, False: 5.05k]
4481
                    goto error;
4482
                }
4483
                else if (tstate->c_tracefunc != NULL) {
  Branch (4483:26): [True: 5, False: 5.04k]
4484
                    call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame);
4485
                }
4486
                _PyErr_Clear(tstate);
4487
            }
4488
        iterator_exhausted_no_error:
4489
            /* iterator ended normally */
4490
            assert(!_PyErr_Occurred(tstate));
4491
            Py_DECREF(POP());
4492
            JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
4493
            DISPATCH();
4494
        }
4495
4496
        
TARGET13.8M
(FOR_ITER_ADAPTIVE) {
4497
            assert(cframe.use_tracing == 0);
4498
            _PyForIterCache *cache = (_PyForIterCache *)next_instr;
4499
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
4500
                next_instr--;
4501
                _Py_Specialize_ForIter(TOP(), next_instr);
4502
                NOTRACE_DISPATCH_SAME_OPARG();
4503
            }
4504
            else {
4505
                STAT_INC(FOR_ITER, deferred);
4506
                DECREMENT_ADAPTIVE_COUNTER(cache);
4507
                JUMP_TO_INSTRUCTION(FOR_ITER);
4508
            }
4509
        }
4510
4511
        TARGET(FOR_ITER_LIST) {
4512
            assert(cframe.use_tracing == 0);
4513
            _PyListIterObject *it = (_PyListIterObject *)TOP();
4514
            DEOPT_IF(Py_TYPE(it) != &PyListIter_Type, FOR_ITER);
4515
            STAT_INC(FOR_ITER, hit);
4516
            PyListObject *seq = it->it_seq;
4517
            if (seq == NULL) {
  Branch (4517:17): [True: 1.58k, False: 28.4M]
4518
                goto iterator_exhausted_no_error;
4519
            }
4520
            if (it->it_index < PyList_GET_SIZE(seq)) {
  Branch (4520:17): [True: 22.3M, False: 6.10M]
4521
                PyObject *next = PyList_GET_ITEM(seq, it->it_index++);
4522
                Py_INCREF(next);
4523
                PUSH(next);
4524
                JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
4525
                NOTRACE_DISPATCH();
4526
            }
4527
            it->it_seq = NULL;
4528
            Py_DECREF(seq);
4529
            goto iterator_exhausted_no_error;
4530
        }
4531
4532
        
TARGET28.4M
(FOR_ITER_RANGE) {
4533
            assert(cframe.use_tracing == 0);
4534
            _PyRangeIterObject *r = (_PyRangeIterObject *)TOP();
4535
            DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER);
4536
            STAT_INC(FOR_ITER, hit);
4537
            _Py_CODEUNIT next = next_instr[INLINE_CACHE_ENTRIES_FOR_ITER];
4538
            assert(_PyOpcode_Deopt[_Py_OPCODE(next)] == STORE_FAST);
4539
            if (r->index >= r->len) {
  Branch (4539:17): [True: 772k, False: 36.1M]
4540
                goto iterator_exhausted_no_error;
4541
            }
4542
            long value = (long)(r->start +
4543
                                (unsigned long)(r->index++) * r->step);
4544
            if (_PyLong_AssignValue(&GETLOCAL(_Py_OPARG(next)), value) < 0) {
  Branch (4544:17): [True: 0, False: 36.1M]
4545
                goto error;
4546
            }
4547
            // The STORE_FAST is already done.
4548
            JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + 1);
4549
            NOTRACE_DISPATCH();
4550
        }
4551
4552
        TARGET(BEFORE_ASYNC_WITH) {
4553
            PyObject *mgr = TOP();
4554
            PyObject *res;
4555
            PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__));
4556
            if (enter == NULL) {
  Branch (4556:17): [True: 2, False: 376]
4557
                if (!_PyErr_Occurred(tstate)) {
  Branch (4557:21): [True: 2, False: 0]
4558
                    _PyErr_Format(tstate, PyExc_TypeError,
4559
                                  "'%.200s' object does not support the "
4560
                                  "asynchronous context manager protocol",
4561
                                  Py_TYPE(mgr)->tp_name);
4562
                }
4563
                goto error;
4564
            }
4565
            PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__aexit__));
4566
            if (exit == NULL) {
  Branch (4566:17): [True: 1, False: 375]
4567
                if (!_PyErr_Occurred(tstate)) {
  Branch (4567:21): [True: 1, False: 0]
4568
                    _PyErr_Format(tstate, PyExc_TypeError,
4569
                                  "'%.200s' object does not support the "
4570
                                  "asynchronous context manager protocol "
4571
                                  "(missed __aexit__ method)",
4572
                                  Py_TYPE(mgr)->tp_name);
4573
                }
4574
                Py_DECREF(enter);
4575
                goto error;
4576
            }
4577
            SET_TOP(exit);
4578
            Py_DECREF(mgr);
4579
            res = _PyObject_CallNoArgs(enter);
4580
            Py_DECREF(enter);
4581
            if (res == NULL)
  Branch (4581:17): [True: 0, False: 375]
4582
                goto error;
4583
            PUSH(res);
4584
            PREDICT(GET_AWAITABLE);
4585
            DISPATCH();
4586
        }
4587
4588
        
TARGET375
(BEFORE_WITH) {
4589
            PyObject *mgr = TOP();
4590
            PyObject *res;
4591
            PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__enter__));
4592
            if (enter == NULL) {
  Branch (4592:17): [True: 4, False: 5.60M]
4593
                if (!_PyErr_Occurred(tstate)) {
  Branch (4593:21): [True: 3, False: 1]
4594
                    _PyErr_Format(tstate, PyExc_TypeError,
4595
                                  "'%.200s' object does not support the "
4596
                                  "context manager protocol",
4597
                                  Py_TYPE(mgr)->tp_name);
4598
                }
4599
                goto error;
4600
            }
4601
            PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__));
4602
            if (exit == NULL) {
  Branch (4602:17): [True: 3, False: 5.60M]
4603
                if (!_PyErr_Occurred(tstate)) {
  Branch (4603:21): [True: 2, False: 1]
4604
                    _PyErr_Format(tstate, PyExc_TypeError,
4605
                                  "'%.200s' object does not support the "
4606
                                  "context manager protocol "
4607
                                  "(missed __exit__ method)",
4608
                                  Py_TYPE(mgr)->tp_name);
4609
                }
4610
                Py_DECREF(enter);
4611
                goto error;
4612
            }
4613
            SET_TOP(exit);
4614
            Py_DECREF(mgr);
4615
            res = _PyObject_CallNoArgs(enter);
4616
            Py_DECREF(enter);
4617
            if (res == NULL) {
  Branch (4617:17): [True: 74, False: 5.60M]
4618
                goto error;
4619
            }
4620
            PUSH(res);
4621
            DISPATCH();
4622
        }
4623
4624
        TARGET(WITH_EXCEPT_START) {
4625
            /* At the top of the stack are 4 values:
4626
               - TOP = exc_info()
4627
               - SECOND = previous exception
4628
               - THIRD: lasti of exception in exc_info()
4629
               - FOURTH: the context.__exit__ bound method
4630
               We call FOURTH(type(TOP), TOP, GetTraceback(TOP)).
4631
               Then we push the __exit__ return value.
4632
            */
4633
            PyObject *exit_func;
4634
            PyObject *exc, *val, *tb, *res;
4635
4636
            val = TOP();
4637
            assert(val && PyExceptionInstance_Check(val));
4638
            exc = PyExceptionInstance_Class(val);
4639
            tb = PyException_GetTraceback(val);
4640
            Py_XDECREF(tb);
4641
            assert(PyLong_Check(PEEK(3)));
4642
            exit_func = PEEK(4);
4643
            PyObject *stack[4] = {NULL, exc, val, tb};
4644
            res = PyObject_Vectorcall(exit_func, stack + 1,
4645
                    3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
4646
            if (res == NULL)
  Branch (4646:17): [True: 39, False: 195k]
4647
                goto error;
4648
4649
            PUSH(res);
4650
            DISPATCH();
4651
        }
4652
4653
        
TARGET195k
(PUSH_EXC_INFO) {
4654
            PyObject *value = TOP();
4655
4656
            _PyErr_StackItem *exc_info = tstate->exc_info;
4657
            if (exc_info->exc_value != NULL) {
  Branch (4657:17): [True: 2.66M, False: 270k]
4658
                SET_TOP(exc_info->exc_value);
4659
            }
4660
            else {
4661
                Py_INCREF(Py_None);
4662
                SET_TOP(Py_None);
4663
            }
4664
4665
            Py_INCREF(value);
4666
            PUSH(value);
4667
            assert(PyExceptionInstance_Check(value));
4668
            exc_info->exc_value = value;
4669
4670
            DISPATCH();
4671
        }
4672
4673
        
TARGET2.93M
(LOAD_ATTR_METHOD_WITH_VALUES) {
4674
            /* Cached method object */
4675
            assert(cframe.use_tracing == 0);
4676
            PyObject *self = TOP();
4677
            PyTypeObject *self_cls = Py_TYPE(self);
4678
            _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
4679
            uint32_t type_version = read_u32(cache->type_version);
4680
            assert(type_version != 0);
4681
            DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
4682
            assert(self_cls->tp_flags & Py_TPFLAGS_MANAGED_DICT);
4683
            PyDictObject *dict = *(PyDictObject**)_PyObject_ManagedDictPointer(self);
4684
            DEOPT_IF(dict != NULL, LOAD_ATTR);
4685
            PyHeapTypeObject *self_heap_type = (PyHeapTypeObject *)self_cls;
4686
            DEOPT_IF(self_heap_type->ht_cached_keys->dk_version !=
4687
                     read_u32(cache->keys_version), LOAD_ATTR);
4688
            STAT_INC(LOAD_ATTR, hit);
4689
            PyObject *res = read_obj(cache->descr);
4690
            assert(res != NULL);
4691
            assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
4692
            Py_INCREF(res);
4693
            SET_TOP(res);
4694
            PUSH(self);
4695
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
4696
            NOTRACE_DISPATCH();
4697
        }
4698
4699
        TARGET(LOAD_ATTR_METHOD_WITH_DICT) {
4700
            /* Can be either a managed dict, or a tp_dictoffset offset.*/
4701
            assert(cframe.use_tracing == 0);
4702
            PyObject *self = TOP();
4703
            PyTypeObject *self_cls = Py_TYPE(self);
4704
            _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
4705
4706
            DEOPT_IF(self_cls->tp_version_tag != read_u32(cache->type_version),
4707
                     LOAD_ATTR);
4708
            /* Treat index as a signed 16 bit value */
4709
            Py_ssize_t dictoffset = self_cls->tp_dictoffset;
4710
            assert(dictoffset > 0);
4711
            PyDictObject **dictptr = (PyDictObject**)(((char *)self)+dictoffset);
4712
            PyDictObject *dict = *dictptr;
4713
            DEOPT_IF(dict == NULL, LOAD_ATTR);
4714
            DEOPT_IF(dict->ma_keys->dk_version != read_u32(cache->keys_version),
4715
                     LOAD_ATTR);
4716
            STAT_INC(LOAD_ATTR, hit);
4717
            PyObject *res = read_obj(cache->descr);
4718
            assert(res != NULL);
4719
            assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
4720
            Py_INCREF(res);
4721
            SET_TOP(res);
4722
            PUSH(self);
4723
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
4724
            NOTRACE_DISPATCH();
4725
        }
4726
4727
        
TARGET3.44M
(LOAD_ATTR_METHOD_NO_DICT) {
4728
            assert(cframe.use_tracing == 0);
4729
            PyObject *self = TOP();
4730
            PyTypeObject *self_cls = Py_TYPE(self);
4731
            _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
4732
            uint32_t type_version = read_u32(cache->type_version);
4733
            DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
4734
            assert(self_cls->tp_dictoffset == 0);
4735
            STAT_INC(LOAD_ATTR, hit);
4736
            PyObject *res = read_obj(cache->descr);
4737
            assert(res != NULL);
4738
            assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
4739
            Py_INCREF(res);
4740
            SET_TOP(res);
4741
            PUSH(self);
4742
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
4743
            NOTRACE_DISPATCH();
4744
        }
4745
4746
        TARGET(LOAD_ATTR_METHOD_LAZY_DICT) {
4747
            assert(cframe.use_tracing == 0);
4748
            PyObject *self = TOP();
4749
            PyTypeObject *self_cls = Py_TYPE(self);
4750
            _PyLoadMethodCache *cache = (_PyLoadMethodCache *)next_instr;
4751
            uint32_t type_version = read_u32(cache->type_version);
4752
            DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
4753
            Py_ssize_t dictoffset = self_cls->tp_dictoffset;
4754
            assert(dictoffset > 0);
4755
            PyObject *dict = *(PyObject **)((char *)self + dictoffset);
4756
            /* This object has a __dict__, just not yet created */
4757
            DEOPT_IF(dict != NULL, LOAD_ATTR);
4758
            STAT_INC(LOAD_ATTR, hit);
4759
            PyObject *res = read_obj(cache->descr);
4760
            assert(res != NULL);
4761
            assert(_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR));
4762
            Py_INCREF(res);
4763
            SET_TOP(res);
4764
            PUSH(self);
4765
            JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
4766
            NOTRACE_DISPATCH();
4767
        }
4768
4769
        TARGET(CALL_BOUND_METHOD_EXACT_ARGS) {
4770
            DEOPT_IF(is_method(stack_pointer, oparg), CALL);
4771
            PyObject *function = PEEK(oparg + 1);
4772
            DEOPT_IF(Py_TYPE(function) != &PyMethod_Type, CALL);
4773
            STAT_INC(CALL, hit);
4774
            PyObject *meth = ((PyMethodObject *)function)->im_func;
4775
            PyObject *self = ((PyMethodObject *)function)->im_self;
4776
            Py_INCREF(meth);
4777
            Py_INCREF(self);
4778
            PEEK(oparg + 1) = self;
4779
            PEEK(oparg + 2) = meth;
4780
            Py_DECREF(function);
4781
            goto call_exact_args;
4782
        }
4783
4784
        
TARGET10.3M
(KW_NAMES) {
4785
            assert(call_shape.kwnames == NULL);
4786
            assert(oparg < PyTuple_GET_SIZE(consts));
4787
            call_shape.kwnames = GETITEM(consts, oparg);
4788
            DISPATCH();
4789
        }
4790
4791
        
TARGET15.2M
(CALL) {
4792
            int total_args, is_meth;
4793
        call_function:
4794
            is_meth = is_method(stack_pointer, oparg);
4795
            PyObject *function = PEEK(oparg + 1);
4796
            if (!is_meth && 
Py_TYPE92.3M
(function) == &PyMethod_Type92.3M
) {
  Branch (4796:17): [True: 92.3M, False: 37.7M]
  Branch (4796:29): [True: 9.09M, False: 83.2M]
4797
                PyObject *meth = ((PyMethodObject *)function)->im_func;
4798
                PyObject *self = ((PyMethodObject *)function)->im_self;
4799
                Py_INCREF(meth);
4800
                Py_INCREF(self);
4801
                PEEK(oparg+1) = self;
4802
                PEEK(oparg+2) = meth;
4803
                Py_DECREF(function);
4804
                is_meth = 1;
4805
            }
4806
            total_args = oparg + is_meth;
4807
            function = PEEK(total_args + 1);
4808
            int positional_args = total_args - KWNAMES_LEN();
4809
            // Check if the call can be inlined or not
4810
            if (Py_TYPE(function) == &PyFunction_Type && 
tstate->interp->eval_frame == NULL28.0M
) {
  Branch (4810:17): [True: 28.0M, False: 102M]
  Branch (4810:58): [True: 28.0M, False: 200]
4811
                int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
4812
                PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : 
Py_NewRef82
(PyFunction_GET_GLOBALS(function));
  Branch (4812:36): [True: 28.0M, False: 82]
4813
                STACK_SHRINK(total_args);
4814
                _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
4815
                    tstate, (PyFunctionObject *)function, locals,
4816
                    stack_pointer, positional_args, call_shape.kwnames
4817
                );
4818
                call_shape.kwnames = NULL;
4819
                STACK_SHRINK(2-is_meth);
4820
                // The frame has stolen all the arguments from the stack,
4821
                // so there is no need to clean them up.
4822
                if (new_frame == NULL) {
  Branch (4822:21): [True: 312, False: 28.0M]
4823
                    goto error;
4824
                }
4825
                _PyFrame_SetStackPointer(frame, stack_pointer);
4826
                JUMPBY(INLINE_CACHE_ENTRIES_CALL);
4827
                frame->prev_instr = next_instr - 1;
4828
                new_frame->previous = frame;
4829
                cframe.current_frame = frame = new_frame;
4830
                CALL_STAT_INC(inlined_py_calls);
4831
                goto start_frame;
4832
            }
4833
            /* Callable is not a normal Python function */
4834
            PyObject *res;
4835
            if (cframe.use_tracing) {
  Branch (4835:17): [True: 1.92M, False: 100M]
4836
                res = trace_call_function(
4837
                    tstate, function, stack_pointer-total_args,
4838
                    positional_args, call_shape.kwnames);
4839
            }
4840
            else {
4841
                res = PyObject_Vectorcall(
4842
                    function, stack_pointer-total_args,
4843
                    positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
4844
                    call_shape.kwnames);
4845
            }
4846
            call_shape.kwnames = NULL;
4847
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4848
            Py_DECREF(function);
4849
            /* Clear the stack */
4850
            STACK_SHRINK(total_args);
4851
            for (int i = 0; i < total_args; 
i++129M
) {
  Branch (4851:29): [True: 129M, False: 102M]
4852
                Py_DECREF(stack_pointer[i]);
4853
            }
4854
            STACK_SHRINK(2-is_meth);
4855
            PUSH(res);
4856
            if (res == NULL) {
  Branch (4856:17): [True: 163k, False: 101M]
4857
                goto error;
4858
            }
4859
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
4860
            CHECK_EVAL_BREAKER();
4861
            DISPATCH();
4862
        }
4863
4864
        TARGET(CALL_ADAPTIVE) {
4865
            _PyCallCache *cache = (_PyCallCache *)next_instr;
4866
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
4867
                next_instr--;
4868
                int is_meth = is_method(stack_pointer, oparg);
4869
                int nargs = oparg + is_meth;
4870
                PyObject *callable = PEEK(nargs + 1);
4871
                int err = _Py_Specialize_Call(callable, next_instr, nargs,
4872
                                              call_shape.kwnames);
4873
                if (err < 0) {
  Branch (4873:21): [True: 0, False: 350k]
4874
                    goto error;
4875
                }
4876
                NOTRACE_DISPATCH_SAME_OPARG();
4877
            }
4878
            else {
4879
                STAT_INC(CALL, deferred);
4880
                DECREMENT_ADAPTIVE_COUNTER(cache);
4881
                goto call_function;
4882
            }
4883
        }
4884
4885
        TARGET(CALL_PY_EXACT_ARGS) {
4886
        call_exact_args:
4887
            assert(call_shape.kwnames == NULL);
4888
            DEOPT_IF(tstate->interp->eval_frame, CALL);
4889
            _PyCallCache *cache = (_PyCallCache *)next_instr;
4890
            int is_meth = is_method(stack_pointer, oparg);
4891
            int argcount = oparg + is_meth;
4892
            PyObject *callable = PEEK(argcount + 1);
4893
            DEOPT_IF(!PyFunction_Check(callable), CALL);
4894
            PyFunctionObject *func = (PyFunctionObject *)callable;
4895
            DEOPT_IF(func->func_version != read_u32(cache->func_version), CALL);
4896
            PyCodeObject *code = (PyCodeObject *)func->func_code;
4897
            DEOPT_IF(code->co_argcount != argcount, CALL);
4898
            DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
4899
            STAT_INC(CALL, hit);
4900
            _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
4901
            CALL_STAT_INC(inlined_py_calls);
4902
            STACK_SHRINK(argcount);
4903
            for (int i = 0; i < argcount; 
i++150M
) {
  Branch (4903:29): [True: 150M, False: 75.7M]
4904
                new_frame->localsplus[i] = stack_pointer[i];
4905
            }
4906
            for (int i = argcount; i < code->co_nlocalsplus; 
i++119M
) {
  Branch (4906:36): [True: 119M, False: 75.7M]
4907
                new_frame->localsplus[i] = NULL;
4908
            }
4909
            STACK_SHRINK(2-is_meth);
4910
            _PyFrame_SetStackPointer(frame, stack_pointer);
4911
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
4912
            frame->prev_instr = next_instr - 1;
4913
            new_frame->previous = frame;
4914
            frame = cframe.current_frame = new_frame;
4915
            goto start_frame;
4916
        }
4917
4918
        TARGET(CALL_PY_WITH_DEFAULTS) {
4919
            assert(call_shape.kwnames == NULL);
4920
            DEOPT_IF(tstate->interp->eval_frame, CALL);
4921
            _PyCallCache *cache = (_PyCallCache *)next_instr;
4922
            int is_meth = is_method(stack_pointer, oparg);
4923
            int argcount = oparg + is_meth;
4924
            PyObject *callable = PEEK(argcount + 1);
4925
            DEOPT_IF(!PyFunction_Check(callable), CALL);
4926
            PyFunctionObject *func = (PyFunctionObject *)callable;
4927
            DEOPT_IF(func->func_version != read_u32(cache->func_version), CALL);
4928
            PyCodeObject *code = (PyCodeObject *)func->func_code;
4929
            DEOPT_IF(argcount > code->co_argcount, CALL);
4930
            int minargs = cache->min_args;
4931
            DEOPT_IF(argcount < minargs, CALL);
4932
            DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
4933
            STAT_INC(CALL, hit);
4934
            _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
4935
            CALL_STAT_INC(inlined_py_calls);
4936
            STACK_SHRINK(argcount);
4937
            for (int i = 0; i < argcount; 
i++45.6M
) {
  Branch (4937:29): [True: 45.6M, False: 17.2M]
4938
                new_frame->localsplus[i] = stack_pointer[i];
4939
            }
4940
            for (int i = argcount; i < code->co_argcount; 
i++22.3M
) {
  Branch (4940:36): [True: 22.3M, False: 17.2M]
4941
                PyObject *def = PyTuple_GET_ITEM(func->func_defaults,
4942
                                                 i - minargs);
4943
                Py_INCREF(def);
4944
                new_frame->localsplus[i] = def;
4945
            }
4946
            for (int i = code->co_argcount; i < code->co_nlocalsplus; 
i++29.4M
) {
  Branch (4946:45): [True: 29.4M, False: 17.2M]
4947
                new_frame->localsplus[i] = NULL;
4948
            }
4949
            STACK_SHRINK(2-is_meth);
4950
            _PyFrame_SetStackPointer(frame, stack_pointer);
4951
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
4952
            frame->prev_instr = next_instr - 1;
4953
            new_frame->previous = frame;
4954
            frame = cframe.current_frame = new_frame;
4955
            goto start_frame;
4956
        }
4957
4958
        
TARGET17.2M
(CALL_NO_KW_TYPE_1) {
4959
            assert(call_shape.kwnames == NULL);
4960
            assert(cframe.use_tracing == 0);
4961
            assert(oparg == 1);
4962
            DEOPT_IF(is_method(stack_pointer, 1), CALL);
4963
            PyObject *obj = TOP();
4964
            PyObject *callable = SECOND();
4965
            DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL);
4966
            STAT_INC(CALL, hit);
4967
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
4968
            PyObject *res = Py_NewRef(Py_TYPE(obj));
4969
            Py_DECREF(callable);
4970
            Py_DECREF(obj);
4971
            STACK_SHRINK(2);
4972
            SET_TOP(res);
4973
            NOTRACE_DISPATCH();
4974
        }
4975
4976
        TARGET(CALL_NO_KW_STR_1) {
4977
            assert(call_shape.kwnames == NULL);
4978
            assert(cframe.use_tracing == 0);
4979
            assert(oparg == 1);
4980
            DEOPT_IF(is_method(stack_pointer, 1), CALL);
4981
            PyObject *callable = PEEK(2);
4982
            DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, CALL);
4983
            STAT_INC(CALL, hit);
4984
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
4985
            PyObject *arg = TOP();
4986
            PyObject *res = PyObject_Str(arg);
4987
            Py_DECREF(arg);
4988
            Py_DECREF(&PyUnicode_Type);
4989
            STACK_SHRINK(2);
4990
            SET_TOP(res);
4991
            if (res == NULL) {
  Branch (4991:17): [True: 6, False: 937k]
4992
                goto error;
4993
            }
4994
            CHECK_EVAL_BREAKER
()937k
;
4995
            DISPATCH();
4996
        }
4997
4998
        TARGET(CALL_NO_KW_TUPLE_1) {
4999
            assert(call_shape.kwnames == NULL);
5000
            assert(oparg == 1);
5001
            DEOPT_IF(is_method(stack_pointer, 1), CALL);
5002
            PyObject *callable = PEEK(2);
5003
            DEOPT_IF(callable != (PyObject *)&PyTuple_Type, CALL);
5004
            STAT_INC(CALL, hit);
5005
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5006
            PyObject *arg = TOP();
5007
            PyObject *res = PySequence_Tuple(arg);
5008
            Py_DECREF(arg);
5009
            Py_DECREF(&PyTuple_Type);
5010
            STACK_SHRINK(2);
5011
            SET_TOP(res);
5012
            if (res == NULL) {
  Branch (5012:17): [True: 53, False: 493k]
5013
                goto error;
5014
            }
5015
            CHECK_EVAL_BREAKER
()493k
;
5016
            DISPATCH();
5017
        }
5018
5019
        
TARGET493k
(CALL_BUILTIN_CLASS) {
5020
            int is_meth = is_method(stack_pointer, oparg);
5021
            int total_args = oparg + is_meth;
5022
            int kwnames_len = KWNAMES_LEN();
5023
            PyObject *callable = PEEK(total_args + 1);
5024
            DEOPT_IF(!PyType_Check(callable), CALL);
5025
            PyTypeObject *tp = (PyTypeObject *)callable;
5026
            DEOPT_IF(tp->tp_vectorcall == NULL, CALL);
5027
            STAT_INC(CALL, hit);
5028
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5029
            STACK_SHRINK(total_args);
5030
            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer,
5031
                                              total_args-kwnames_len, call_shape.kwnames);
5032
            call_shape.kwnames = NULL;
5033
            /* Free the arguments. */
5034
            for (int i = 0; i < total_args; 
i++7.22M
) {
  Branch (5034:29): [True: 7.22M, False: 7.58M]
5035
                Py_DECREF(stack_pointer[i]);
5036
            }
5037
            Py_DECREF(tp);
5038
            STACK_SHRINK(1-is_meth);
5039
            SET_TOP(res);
5040
            if (res == NULL) {
  Branch (5040:17): [True: 1.42k, False: 7.58M]
5041
                goto error;
5042
            }
5043
            CHECK_EVAL_BREAKER
()7.58M
;
5044
            DISPATCH();
5045
        }
5046
5047
        
TARGET7.58M
(CALL_NO_KW_BUILTIN_O) {
5048
            assert(cframe.use_tracing == 0);
5049
            /* Builtin METH_O functions */
5050
            assert(call_shape.kwnames == NULL);
5051
            int is_meth = is_method(stack_pointer, oparg);
5052
            int total_args = oparg + is_meth;
5053
            DEOPT_IF(total_args != 1, CALL);
5054
            PyObject *callable = PEEK(total_args + 1);
5055
            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
5056
            DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, CALL);
5057
            STAT_INC(CALL, hit);
5058
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5059
            PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
5060
            // This is slower but CPython promises to check all non-vectorcall
5061
            // function calls.
5062
            if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
  Branch (5062:17): [True: 2, False: 48.1M]
5063
                goto error;
5064
            }
5065
            PyObject *arg = TOP();
5066
            PyObject *res = cfunc(PyCFunction_GET_SELF(callable), arg);
5067
            _Py_LeaveRecursiveCallTstate(tstate);
5068
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5069
5070
            Py_DECREF(arg);
5071
            Py_DECREF(callable);
5072
            STACK_SHRINK(2-is_meth);
5073
            SET_TOP(res);
5074
            if (res == NULL) {
  Branch (5074:17): [True: 7.05k, False: 48.0M]
5075
                goto error;
5076
            }
5077
            CHECK_EVAL_BREAKER
()48.0M
;
5078
            DISPATCH();
5079
        }
5080
5081
        TARGET(CALL_NO_KW_BUILTIN_FAST) {
5082
            assert(cframe.use_tracing == 0);
5083
            /* Builtin METH_FASTCALL functions, without keywords */
5084
            assert(call_shape.kwnames == NULL);
5085
            int is_meth = is_method(stack_pointer, oparg);
5086
            int total_args = oparg + is_meth;
5087
            PyObject *callable = PEEK(total_args + 1);
5088
            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
5089
            DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_FASTCALL,
5090
                CALL);
5091
            STAT_INC(CALL, hit);
5092
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5093
            PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
5094
            STACK_SHRINK(total_args);
5095
            /* res = func(self, args, nargs) */
5096
            PyObject *res = ((_PyCFunctionFast)(void(*)(void))cfunc)(
5097
                PyCFunction_GET_SELF(callable),
5098
                stack_pointer,
5099
                total_args);
5100
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5101
5102
            /* Free the arguments. */
5103
            for (int i = 0; i < total_args; 
i++66.4M
) {
  Branch (5103:29): [True: 66.4M, False: 31.3M]
5104
                Py_DECREF(stack_pointer[i]);
5105
            }
5106
            STACK_SHRINK(2-is_meth);
5107
            PUSH(res);
5108
            Py_DECREF(callable);
5109
            if (res == NULL) {
  Branch (5109:17): [True: 797k, False: 30.5M]
5110
                /* Not deopting because this doesn't mean our optimization was
5111
                   wrong. `res` can be NULL for valid reasons. Eg. getattr(x,
5112
                   'invalid'). In those cases an exception is set, so we must
5113
                   handle it.
5114
                */
5115
                goto error;
5116
            }
5117
            CHECK_EVAL_BREAKER
()30.5M
;
5118
            DISPATCH();
5119
        }
5120
5121
        TARGET(CALL_BUILTIN_FAST_WITH_KEYWORDS) {
5122
            assert(cframe.use_tracing == 0);
5123
            /* Builtin METH_FASTCALL | METH_KEYWORDS functions */
5124
            int is_meth = is_method(stack_pointer, oparg);
5125
            int total_args = oparg + is_meth;
5126
            PyObject *callable = PEEK(total_args + 1);
5127
            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
5128
            DEOPT_IF(PyCFunction_GET_FLAGS(callable) !=
5129
                (METH_FASTCALL | METH_KEYWORDS), CALL);
5130
            STAT_INC(CALL, hit);
5131
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5132
            STACK_SHRINK(total_args);
5133
            /* res = func(self, args, nargs, kwnames) */
5134
            _PyCFunctionFastWithKeywords cfunc =
5135
                (_PyCFunctionFastWithKeywords)(void(*)(void))
5136
                PyCFunction_GET_FUNCTION(callable);
5137
            PyObject *res = cfunc(
5138
                PyCFunction_GET_SELF(callable),
5139
                stack_pointer,
5140
                total_args - KWNAMES_LEN(),
5141
                call_shape.kwnames
5142
            );
5143
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5144
            call_shape.kwnames = NULL;
5145
5146
            /* Free the arguments. */
5147
            for (int i = 0; i < total_args; 
i++9.04M
) {
  Branch (5147:29): [True: 9.04M, False: 5.19M]
5148
                Py_DECREF(stack_pointer[i]);
5149
            }
5150
            STACK_SHRINK(2-is_meth);
5151
            PUSH(res);
5152
            Py_DECREF(callable);
5153
            if (res == NULL) {
  Branch (5153:17): [True: 142k, False: 5.05M]
5154
                goto error;
5155
            }
5156
            CHECK_EVAL_BREAKER
()5.05M
;
5157
            DISPATCH();
5158
        }
5159
5160
        
TARGET5.05M
(CALL_NO_KW_LEN) {
5161
            assert(cframe.use_tracing == 0);
5162
            assert(call_shape.kwnames == NULL);
5163
            /* len(o) */
5164
            int is_meth = is_method(stack_pointer, oparg);
5165
            int total_args = oparg + is_meth;
5166
            DEOPT_IF(total_args != 1, CALL);
5167
            PyObject *callable = PEEK(total_args + 1);
5168
            PyInterpreterState *interp = _PyInterpreterState_GET();
5169
            DEOPT_IF(callable != interp->callable_cache.len, CALL);
5170
            STAT_INC(CALL, hit);
5171
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5172
            PyObject *arg = TOP();
5173
            Py_ssize_t len_i = PyObject_Length(arg);
5174
            if (len_i < 0) {
  Branch (5174:17): [True: 325, False: 19.8M]
5175
                goto error;
5176
            }
5177
            PyObject *res = PyLong_FromSsize_t(len_i);
5178
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5179
5180
            STACK_SHRINK(2-is_meth);
5181
            SET_TOP(res);
5182
            Py_DECREF(callable);
5183
            Py_DECREF(arg);
5184
            if (res == NULL) {
  Branch (5184:17): [True: 0, False: 19.8M]
5185
                goto error;
5186
            }
5187
            DISPATCH();
5188
        }
5189
5190
        
TARGET19.8M
(CALL_NO_KW_ISINSTANCE) {
5191
            assert(cframe.use_tracing == 0);
5192
            assert(call_shape.kwnames == NULL);
5193
            /* isinstance(o, o2) */
5194
            int is_meth = is_method(stack_pointer, oparg);
5195
            int total_args = oparg + is_meth;
5196
            PyObject *callable = PEEK(total_args + 1);
5197
            DEOPT_IF(total_args != 2, CALL);
5198
            PyInterpreterState *interp = _PyInterpreterState_GET();
5199
            DEOPT_IF(callable != interp->callable_cache.isinstance, CALL);
5200
            STAT_INC(CALL, hit);
5201
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5202
            PyObject *cls = POP();
5203
            PyObject *inst = TOP();
5204
            int retval = PyObject_IsInstance(inst, cls);
5205
            if (retval < 0) {
  Branch (5205:17): [True: 16, False: 22.4M]
5206
                Py_DECREF(cls);
5207
                goto error;
5208
            }
5209
            PyObject *res = PyBool_FromLong(retval);
5210
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5211
5212
            STACK_SHRINK(2-is_meth);
5213
            SET_TOP(res);
5214
            Py_DECREF(inst);
5215
            Py_DECREF(cls);
5216
            Py_DECREF(callable);
5217
            if (res == NULL) {
  Branch (5217:17): [True: 0, False: 22.4M]
5218
                goto error;
5219
            }
5220
            DISPATCH();
5221
        }
5222
5223
        TARGET(CALL_NO_KW_LIST_APPEND) {
5224
            assert(cframe.use_tracing == 0);
5225
            assert(call_shape.kwnames == NULL);
5226
            assert(oparg == 1);
5227
            PyObject *callable = PEEK(3);
5228
            PyInterpreterState *interp = _PyInterpreterState_GET();
5229
            DEOPT_IF(callable != interp->callable_cache.list_append, CALL);
5230
            PyObject *list = SECOND();
5231
            DEOPT_IF(!PyList_Check(list), CALL);
5232
            STAT_INC(CALL, hit);
5233
            // CALL + POP_TOP
5234
            JUMPBY(INLINE_CACHE_ENTRIES_CALL + 1);
5235
            assert(_Py_OPCODE(next_instr[-1]) == POP_TOP);
5236
            PyObject *arg = POP();
5237
            if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
  Branch (5237:17): [True: 0, False: 8.85M]
5238
                goto error;
5239
            }
5240
            STACK_SHRINK(2);
5241
            Py_DECREF(list);
5242
            Py_DECREF(callable);
5243
            NOTRACE_DISPATCH();
5244
        }
5245
5246
        
TARGET8.85M
(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
5247
            assert(call_shape.kwnames == NULL);
5248
            int is_meth = is_method(stack_pointer, oparg);
5249
            int total_args = oparg + is_meth;
5250
            PyMethodDescrObject *callable =
5251
                (PyMethodDescrObject *)PEEK(total_args + 1);
5252
            DEOPT_IF(total_args != 2, CALL);
5253
            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
5254
            PyMethodDef *meth = callable->d_method;
5255
            DEOPT_IF(meth->ml_flags != METH_O, CALL);
5256
            PyObject *arg = TOP();
5257
            PyObject *self = SECOND();
5258
            DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), CALL);
5259
            STAT_INC(CALL, hit);
5260
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5261
            PyCFunction cfunc = meth->ml_meth;
5262
            // This is slower but CPython promises to check all non-vectorcall
5263
            // function calls.
5264
            if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
  Branch (5264:17): [True: 0, False: 9.24M]
5265
                goto error;
5266
            }
5267
            PyObject *res = cfunc(self, arg);
5268
            _Py_LeaveRecursiveCallTstate(tstate);
5269
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5270
            Py_DECREF(self);
5271
            Py_DECREF(arg);
5272
            STACK_SHRINK(oparg + 1);
5273
            SET_TOP(res);
5274
            Py_DECREF(callable);
5275
            if (res == NULL) {
  Branch (5275:17): [True: 9.60k, False: 9.23M]
5276
                goto error;
5277
            }
5278
            CHECK_EVAL_BREAKER
()9.23M
;
5279
            DISPATCH();
5280
        }
5281
5282
        
TARGET9.23M
(CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS) {
5283
            int is_meth = is_method(stack_pointer, oparg);
5284
            int total_args = oparg + is_meth;
5285
            PyMethodDescrObject *callable =
5286
                (PyMethodDescrObject *)PEEK(total_args + 1);
5287
            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
5288
            PyMethodDef *meth = callable->d_method;
5289
            DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), CALL);
5290
            PyTypeObject *d_type = callable->d_common.d_type;
5291
            PyObject *self = PEEK(total_args);
5292
            DEOPT_IF(!Py_IS_TYPE(self, d_type), CALL);
5293
            STAT_INC(CALL, hit);
5294
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5295
            int nargs = total_args-1;
5296
            STACK_SHRINK(nargs);
5297
            _PyCFunctionFastWithKeywords cfunc =
5298
                (_PyCFunctionFastWithKeywords)(void(*)(void))meth->ml_meth;
5299
            PyObject *res = cfunc(self, stack_pointer, nargs - KWNAMES_LEN(),
5300
                                  call_shape.kwnames);
5301
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5302
            call_shape.kwnames = NULL;
5303
5304
            /* Free the arguments. */
5305
            for (int i = 0; i < nargs; 
i++14.1M
) {
  Branch (5305:29): [True: 14.1M, False: 11.4M]
5306
                Py_DECREF(stack_pointer[i]);
5307
            }
5308
            Py_DECREF(self);
5309
            STACK_SHRINK(2-is_meth);
5310
            SET_TOP(res);
5311
            Py_DECREF(callable);
5312
            if (res == NULL) {
  Branch (5312:17): [True: 2.68k, False: 11.4M]
5313
                goto error;
5314
            }
5315
            CHECK_EVAL_BREAKER
()11.4M
;
5316
            DISPATCH();
5317
        }
5318
5319
        
TARGET11.4M
(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
5320
            assert(call_shape.kwnames == NULL);
5321
            assert(oparg == 0 || oparg == 1);
5322
            int is_meth = is_method(stack_pointer, oparg);
5323
            int total_args = oparg + is_meth;
5324
            DEOPT_IF(total_args != 1, CALL);
5325
            PyMethodDescrObject *callable = (PyMethodDescrObject *)SECOND();
5326
            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
5327
            PyMethodDef *meth = callable->d_method;
5328
            PyObject *self = TOP();
5329
            DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), CALL);
5330
            DEOPT_IF(meth->ml_flags != METH_NOARGS, CALL);
5331
            STAT_INC(CALL, hit);
5332
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5333
            PyCFunction cfunc = meth->ml_meth;
5334
            // This is slower but CPython promises to check all non-vectorcall
5335
            // function calls.
5336
            if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
  Branch (5336:17): [True: 0, False: 13.1M]
5337
                goto error;
5338
            }
5339
            PyObject *res = cfunc(self, NULL);
5340
            _Py_LeaveRecursiveCallTstate(tstate);
5341
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5342
            Py_DECREF(self);
5343
            STACK_SHRINK(oparg + 1);
5344
            SET_TOP(res);
5345
            Py_DECREF(callable);
5346
            if (res == NULL) {
  Branch (5346:17): [True: 193k, False: 12.9M]
5347
                goto error;
5348
            }
5349
            CHECK_EVAL_BREAKER
()12.9M
;
5350
            DISPATCH();
5351
        }
5352
5353
        
TARGET12.9M
(CALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
5354
            assert(call_shape.kwnames == NULL);
5355
            int is_meth = is_method(stack_pointer, oparg);
5356
            int total_args = oparg + is_meth;
5357
            PyMethodDescrObject *callable =
5358
                (PyMethodDescrObject *)PEEK(total_args + 1);
5359
            /* Builtin METH_FASTCALL methods, without keywords */
5360
            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
5361
            PyMethodDef *meth = callable->d_method;
5362
            DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
5363
            PyObject *self = PEEK(total_args);
5364
            DEOPT_IF(!Py_IS_TYPE(self, callable->d_common.d_type), CALL);
5365
            STAT_INC(CALL, hit);
5366
            JUMPBY(INLINE_CACHE_ENTRIES_CALL);
5367
            _PyCFunctionFast cfunc =
5368
                (_PyCFunctionFast)(void(*)(void))meth->ml_meth;
5369
            int nargs = total_args-1;
5370
            STACK_SHRINK(nargs);
5371
            PyObject *res = cfunc(self, stack_pointer, nargs);
5372
            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
5373
            /* Clear the stack of the arguments. */
5374
            for (int i = 0; i < nargs; 
i++31.3M
) {
  Branch (5374:29): [True: 31.3M, False: 30.1M]
5375
                Py_DECREF(stack_pointer[i]);
5376
            }
5377
            Py_DECREF(self);
5378
            STACK_SHRINK(2-is_meth);
5379
            SET_TOP(res);
5380
            Py_DECREF(callable);
5381
            if (res == NULL) {
  Branch (5381:17): [True: 282k, False: 29.8M]
5382
                goto error;
5383
            }
5384
            CHECK_EVAL_BREAKER
()29.8M
;
5385
            DISPATCH();
5386
        }
5387
5388
        TARGET(CALL_FUNCTION_EX) {
5389
            PREDICTED(CALL_FUNCTION_EX);
5390
            PyObject *func, *callargs, *kwargs = NULL, *result;
5391
            if (oparg & 0x01) {
  Branch (5391:17): [True: 4.15M, False: 5.69M]
5392
                kwargs = POP();
5393
                if (!PyDict_CheckExact(kwargs)) {
  Branch (5393:21): [True: 0, False: 4.15M]
5394
                    PyObject *d = PyDict_New();
5395
                    if (d == NULL)
  Branch (5395:25): [True: 0, False: 0]
5396
                        goto error;
5397
                    if (_PyDict_MergeEx(d, kwargs, 2) < 0) {
  Branch (5397:25): [True: 0, False: 0]
5398
                        Py_DECREF(d);
5399
                        format_kwargs_error(tstate, SECOND(), kwargs);
5400
                        Py_DECREF(kwargs);
5401
                        goto error;
5402
                    }
5403
                    Py_DECREF(kwargs);
5404
                    kwargs = d;
5405
                }
5406
                assert(PyDict_CheckExact(kwargs));
5407
            }
5408
            callargs = POP();
5409
            func = TOP();
5410
            if (!PyTuple_CheckExact(callargs)) {
  Branch (5410:17): [True: 214k, False: 9.63M]
5411
                if (check_args_iterable(tstate, func, callargs) < 0) {
  Branch (5411:21): [True: 6, False: 214k]
5412
                    Py_DECREF(callargs);
5413
                    goto error;
5414
                }
5415
                Py_SETREF(callargs, PySequence_Tuple(callargs));
5416
                if (callargs == NULL) {
  Branch (5416:21): [True: 4, False: 214k]
5417
                    goto error;
5418
                }
5419
            }
5420
            assert(PyTuple_CheckExact(callargs));
5421
5422
            result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);
5423
            Py_DECREF(func);
5424
            Py_DECREF(callargs);
5425
            Py_XDECREF(kwargs);
5426
5427
            STACK_SHRINK(1);
5428
            assert(TOP() == NULL);
5429
            SET_TOP(result);
5430
            if (result == NULL) {
  Branch (5430:17): [True: 123k, False: 9.73M]
5431
                goto error;
5432
            }
5433
            CHECK_EVAL_BREAKER
()9.73M
;
5434
            DISPATCH();
5435
        }
5436
5437
        TARGET(MAKE_FUNCTION) {
5438
            PyObject *codeobj = POP();
5439
            PyFunctionObject *func = (PyFunctionObject *)
5440
                PyFunction_New(codeobj, GLOBALS());
5441
5442
            Py_DECREF(codeobj);
5443
            if (func == NULL) {
  Branch (5443:17): [True: 0, False: 2.52M]
5444
                goto error;
5445
            }
5446
5447
            if (oparg & 0x08) {
  Branch (5447:17): [True: 978k, False: 1.54M]
5448
                assert(PyTuple_CheckExact(TOP()));
5449
                func->func_closure = POP();
5450
            }
5451
            if (oparg & 0x04) {
  Branch (5451:17): [True: 2.67k, False: 2.52M]
5452
                assert(PyTuple_CheckExact(TOP()));
5453
                func->func_annotations = POP();
5454
            }
5455
            if (oparg & 0x02) {
  Branch (5455:17): [True: 15.1k, False: 2.50M]
5456
                assert(PyDict_CheckExact(TOP()));
5457
                func->func_kwdefaults = POP();
5458
            }
5459
            if (oparg & 0x01) {
  Branch (5459:17): [True: 124k, False: 2.39M]
5460
                assert(PyTuple_CheckExact(TOP()));
5461
                func->func_defaults = POP();
5462
            }
5463
5464
            PUSH((PyObject *)func);
5465
            DISPATCH();
5466
        }
5467
5468
        
TARGET2.52M
(RETURN_GENERATOR) {
5469
            PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(frame->f_func);
5470
            if (gen == NULL) {
  Branch (5470:17): [True: 0, False: 3.56M]
5471
                goto error;
5472
            }
5473
            assert(EMPTY());
5474
            _PyFrame_SetStackPointer(frame, stack_pointer);
5475
            _PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
5476
            _PyFrame_Copy(frame, gen_frame);
5477
            assert(frame->frame_obj == NULL);
5478
            gen->gi_frame_state = FRAME_CREATED;
5479
            gen_frame->owner = FRAME_OWNED_BY_GENERATOR;
5480
            _Py_LeaveRecursiveCallTstate(tstate);
5481
            if (!frame->is_entry) {
  Branch (5481:17): [True: 2.90M, False: 662k]
5482
                _PyInterpreterFrame *prev = frame->previous;
5483
                _PyThreadState_PopFrame(tstate, frame);
5484
                frame = cframe.current_frame = prev;
5485
                _PyFrame_StackPush(frame, (PyObject *)gen);
5486
                goto resume_frame;
5487
            }
5488
            /* Make sure that frame is in a valid state */
5489
            frame->stacktop = 0;
5490
            frame->f_locals = NULL;
5491
            Py_INCREF(frame->f_func);
5492
            Py_INCREF(frame->f_code);
5493
            /* Restore previous cframe and return. */
5494
            tstate->cframe = cframe.previous;
5495
            tstate->cframe->use_tracing = cframe.use_tracing;
5496
            assert(tstate->cframe->current_frame == frame->previous);
5497
            assert(!_PyErr_Occurred(tstate));
5498
            return (PyObject *)gen;
5499
        }
5500
5501
        TARGET(BUILD_SLICE) {
5502
            PyObject *start, *stop, *step, *slice;
5503
            if (oparg == 3)
  Branch (5503:17): [True: 287k, False: 46.5k]
5504
                step = POP();
5505
            else
5506
                step = NULL;
5507
            stop = POP();
5508
            start = TOP();
5509
            slice = PySlice_New(start, stop, step);
5510
            Py_DECREF(start);
5511
            Py_DECREF(stop);
5512
            Py_XDECREF(step);
5513
            SET_TOP(slice);
5514
            if (slice == NULL)
  Branch (5514:17): [True: 0, False: 333k]
5515
                goto error;
5516
            DISPATCH();
5517
        }
5518
5519
        
TARGET333k
(FORMAT_VALUE) {
5520
            /* Handles f-string value formatting. */
5521
            PyObject *result;
5522
            PyObject *fmt_spec;
5523
            PyObject *value;
5524
            PyObject *(*conv_fn)(PyObject *);
5525
            int which_conversion = oparg & FVC_MASK;
5526
            int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC;
5527
5528
            fmt_spec = have_fmt_spec ? POP() : NULL;
  Branch (5528:24): [True: 9.27k, False: 720k]
5529
            value = POP();
5530
5531
            /* See if any conversion is specified. */
5532
            switch (which_conversion) {
5533
            case FVC_NONE:  conv_fn = NULL;           break;
  Branch (5533:13): [True: 356k, False: 373k]
5534
            case FVC_STR:   conv_fn = PyObject_Str;   break;
  Branch (5534:13): [True: 211k, False: 518k]
5535
            case FVC_REPR:  conv_fn = PyObject_Repr;  break;
  Branch (5535:13): [True: 157k, False: 572k]
5536
            case FVC_ASCII: conv_fn = PyObject_ASCII; break;
  Branch (5536:13): [True: 4.15k, False: 725k]
5537
            default:
  Branch (5537:13): [True: 0, False: 729k]
5538
                _PyErr_Format(tstate, PyExc_SystemError,
5539
                              "unexpected conversion flag %d",
5540
                              which_conversion);
5541
                goto error;
5542
            }
5543
5544
            /* If there's a conversion function, call it and replace
5545
               value with that result. Otherwise, just use value,
5546
               without conversion. */
5547
            if (conv_fn != NULL) {
  Branch (5547:17): [True: 373k, False: 356k]
5548
                result = conv_fn(value);
5549
                Py_DECREF(value);
5550
                if (result == NULL) {
  Branch (5550:21): [True: 483, False: 372k]
5551
                    Py_XDECREF(fmt_spec);
5552
                    goto error;
5553
                }
5554
                value = result;
5555
            }
5556
5557
            /* If value is a unicode object, and there's no fmt_spec,
5558
               then we know the result of format(value) is value
5559
               itself. In that case, skip calling format(). I plan to
5560
               move this optimization in to PyObject_Format()
5561
               itself. */
5562
            if (PyUnicode_CheckExact(value) && 
fmt_spec == NULL560k
) {
  Branch (5562:48): [True: 552k, False: 7.68k]
5563
                /* Do nothing, just transfer ownership to result. */
5564
                result = value;
5565
            } else {
5566
                /* Actually call format(). */
5567
                result = PyObject_Format(value, fmt_spec);
5568
                Py_DECREF(value);
5569
                Py_XDECREF(fmt_spec);
5570
                if (result == NULL) {
  Branch (5570:21): [True: 16, False: 176k]
5571
                    goto error;
5572
                }
5573
            }
5574
5575
            PUSH(result);
5576
            DISPATCH();
5577
        }
5578
5579
        
TARGET729k
(COPY) {
5580
            assert(oparg != 0);
5581
            PyObject *peek = PEEK(oparg);
5582
            Py_INCREF(peek);
5583
            PUSH(peek);
5584
            DISPATCH();
5585
        }
5586
5587
        
TARGET11.9M
(BINARY_OP) {
5588
            PREDICTED(BINARY_OP);
5589
            PyObject *rhs = POP();
5590
            PyObject *lhs = TOP();
5591
            assert(0 <= oparg);
5592
            assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
5593
            assert(binary_ops[oparg]);
5594
            PyObject *res = binary_ops[oparg](lhs, rhs);
5595
            Py_DECREF(lhs);
5596
            Py_DECREF(rhs);
5597
            SET_TOP(res);
5598
            if (res == NULL) {
  Branch (5598:17): [True: 4.63k, False: 39.0M]
5599
                goto error;
5600
            }
5601
            JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
5602
            DISPATCH();
5603
        }
5604
5605
        TARGET(BINARY_OP_ADAPTIVE) {
5606
            assert(cframe.use_tracing == 0);
5607
            _PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
5608
            if (ADAPTIVE_COUNTER_IS_ZERO(cache)) {
5609
                PyObject *lhs = SECOND();
5610
                PyObject *rhs = TOP();
5611
                next_instr--;
5612
                _Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg, &GETLOCAL(0));
5613
                NOTRACE_DISPATCH_SAME_OPARG();
5614
            }
5615
            else {
5616
                STAT_INC(BINARY_OP, deferred);
5617
                DECREMENT_ADAPTIVE_COUNTER(cache);
5618
                JUMP_TO_INSTRUCTION(BINARY_OP);
5619
            }
5620
        }
5621
5622
        
TARGET7.93M
(SWAP) {
5623
            assert(oparg != 0);
5624
            PyObject *top = TOP();
5625
            SET_TOP(PEEK(oparg));
5626
            PEEK(oparg) = top;
5627
            DISPATCH();
5628
        }
5629
5630
        TARGET(EXTENDED_ARG) {
5631
            assert(oparg);
5632
            oparg <<= 8;
5633
            oparg |= _Py_OPARG(*next_instr);
5634
            opcode = _PyOpcode_Deopt[_Py_OPCODE(*next_instr)];
5635
            PRE_DISPATCH_GOTO();
5636
            DISPATCH_GOTO();
5637
        }
5638
5639
        
TARGET24.2k
(EXTENDED_ARG_QUICK) {
5640
            assert(oparg);
5641
            oparg <<= 8;
5642
            oparg |= _Py_OPARG(*next_instr);
5643
            NOTRACE_DISPATCH_SAME_OPARG();
5644
        }
5645
5646
        TARGET(CACHE) {
5647
            Py_UNREACHABLE();
5648
        }
5649
5650
#if USE_COMPUTED_GOTOS
5651
        TARGET_DO_TRACING:
5652
#else
5653
        case DO_TRACING:
5654
#endif
5655
    {
5656
        if (tstate->tracing == 0 &&
  Branch (5656:13): [True: 6.03M, False: 39.4M]
5657
            
INSTR_OFFSET6.03M
() >= frame->f_code->_co_firsttraceable6.03M
  Branch (5657:13): [True: 6.03M, False: 7.06k]
5658
        ) {
5659
            int instr_prev = _PyInterpreterFrame_LASTI(frame);
5660
            frame->prev_instr = next_instr;
5661
            TRACING_NEXTOPARG();
5662
            if (opcode == RESUME) {
  Branch (5662:17): [True: 136k, False: 5.89M]
5663
                if (oparg < 2) {
  Branch (5663:21): [True: 135k, False: 370]
5664
                    CHECK_EVAL_BREAKER();
5665
                }
5666
                /* Call tracing */
5667
                TRACE_FUNCTION_ENTRY();
5668
                DTRACE_FUNCTION_ENTRY();
5669
            }
5670
            else {
5671
                /* line-by-line tracing support */
5672
                if (PyDTrace_LINE_ENABLED()) {
  Branch (5672:21): [True: 0, False: 5.89M]
5673
                    maybe_dtrace_line(frame, &tstate->trace_info, instr_prev);
5674
                }
5675
5676
                if (cframe.use_tracing &&
  Branch (5676:21): [True: 5.89M, False: 0]
5677
                    tstate->c_tracefunc != NULL && 
!tstate->tracing5.88M
) {
  Branch (5677:21): [True: 5.88M, False: 15.6k]
  Branch (5677:52): [True: 5.88M, False: 0]
5678
                    int err;
5679
                    /* see maybe_call_line_trace()
5680
                    for expository comments */
5681
                    _PyFrame_SetStackPointer(frame, stack_pointer);
5682
5683
                    err = maybe_call_line_trace(tstate->c_tracefunc,
5684
                                                tstate->c_traceobj,
5685
                                                tstate, frame, instr_prev);
5686
                    if (err) {
  Branch (5686:25): [True: 1.06k, False: 5.87M]
5687
                        /* trace function raised an exception */
5688
                        next_instr++;
5689
                        goto error;
5690
                    }
5691
                    /* Reload possibly changed frame fields */
5692
                    next_instr = frame->prev_instr;
5693
5694
                    stack_pointer = _PyFrame_GetStackPointer(frame);
5695
                    frame->stacktop = -1;
5696
                }
5697
            }
5698
        }
5699
        TRACING_NEXTOPARG();
5700
        PRE_DISPATCH_GOTO();
5701
        DISPATCH_GOTO();
5702
    }
5703
5704
#if USE_COMPUTED_GOTOS
5705
        _unknown_opcode:
5706
#else
5707
        EXTRA_CASES  // From opcode.h, a 'case' for each unused opcode
5708
#endif
5709
            /* Tell C compilers not to hold the opcode variable in the loop.
5710
               next_instr points the current instruction without TARGET(). */
5711
            opcode = _Py_OPCODE(*next_instr);
5712
            fprintf(stderr, "XXX lineno: %d, opcode: %d\n",
5713
                    _PyInterpreterFrame_GetLine(frame),  opcode);
5714
            _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode");
5715
            goto error;
5716
5717
        } /* End instructions */
5718
5719
        /* This should never be reached. Every opcode should end with DISPATCH()
5720
           or goto error. */
5721
        
Py_UNREACHABLE0
();
5722
5723
/* Specialization misses */
5724
5725
miss:
5726
    {
5727
        STAT_INC(opcode, miss);
5728
        opcode = _PyOpcode_Deopt[opcode];
5729
        STAT_INC(opcode, miss);
5730
        /* The counter is always the first cache entry: */
5731
        _Py_CODEUNIT *counter = (_Py_CODEUNIT *)next_instr;
5732
        *counter -= 1;
5733
        if (*counter == 0) {
  Branch (5733:13): [True: 491k, False: 26.1M]
5734
            int adaptive_opcode = _PyOpcode_Adaptive[opcode];
5735
            assert(adaptive_opcode);
5736
            _Py_SET_OPCODE(next_instr[-1], adaptive_opcode);
5737
            STAT_INC(opcode, deopt);
5738
            *counter = adaptive_counter_start();
5739
        }
5740
        next_instr--;
5741
        DISPATCH_GOTO();
5742
    }
5743
5744
binary_subscr_dict_error:
5745
        {
5746
            PyObject *sub = POP();
5747
            if (!_PyErr_Occurred(tstate)) {
  Branch (5747:17): [True: 364k, False: 8]
5748
                _PyErr_SetKeyError(sub);
5749
            }
5750
            Py_DECREF(sub);
5751
            goto error;
5752
        }
5753
5754
unbound_local_error:
5755
        {
5756
            format_exc_check_arg(tstate, PyExc_UnboundLocalError,
5757
                UNBOUNDLOCAL_ERROR_MSG,
5758
                PyTuple_GetItem(frame->f_code->co_localsplusnames, oparg)
5759
            );
5760
            goto error;
5761
        }
5762
5763
error:
5764
        call_shape.kwnames = NULL;
5765
        /* Double-check exception status. */
5766
#ifdef NDEBUG
5767
        if (!_PyErr_Occurred(tstate)) {
  Branch (5767:13): [True: 0, False: 3.90M]
5768
            _PyErr_SetString(tstate, PyExc_SystemError,
5769
                             "error return without exception set");
5770
        }
5771
#else
5772
        assert(_PyErr_Occurred(tstate));
5773
#endif
5774
5775
        /* Log traceback info. */
5776
        PyFrameObject *f = _PyFrame_GetFrameObject(frame);
5777
        if (f != NULL) {
  Branch (5777:13): [True: 3.90M, False: 0]
5778
            PyTraceBack_Here(f);
5779
        }
5780
5781
        if (tstate->c_tracefunc != NULL) {
  Branch (5781:13): [True: 8.92k, False: 3.89M]
5782
            /* Make sure state is set to FRAME_UNWINDING for tracing */
5783
            call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj,
5784
                           tstate, frame);
5785
        }
5786
5787
exception_unwind:
5788
        {
5789
            /* We can't use frame->f_lasti here, as RERAISE may have set it */
5790
            int offset = INSTR_OFFSET()-1;
5791
            int level, handler, lasti;
5792
            if (get_exception_handler(frame->f_code, offset, &level, &handler, &lasti) == 0) {
  Branch (5792:17): [True: 1.11M, False: 3.23M]
5793
                // No handlers, so exit.
5794
                assert(_PyErr_Occurred(tstate));
5795
5796
                /* Pop remaining stack entries. */
5797
                PyObject **stackbase = _PyFrame_Stackbase(frame);
5798
                while (stack_pointer > stackbase) {
  Branch (5798:24): [True: 1.41M, False: 1.11M]
5799
                    PyObject *o = POP();
5800
                    Py_XDECREF(o);
5801
                }
5802
                assert(STACK_LEVEL() == 0);
5803
                _PyFrame_SetStackPointer(frame, stack_pointer);
5804
                TRACE_FUNCTION_UNWIND();
5805
                DTRACE_FUNCTION_EXIT();
5806
                goto exit_unwind;
5807
            }
5808
5809
            assert(STACK_LEVEL() >= level);
5810
            PyObject **new_top = _PyFrame_Stackbase(frame) + level;
5811
            while (stack_pointer > new_top) {
  Branch (5811:20): [True: 2.45M, False: 3.23M]
5812
                PyObject *v = POP();
5813
                Py_XDECREF(v);
5814
            }
5815
            PyObject *exc, *val, *tb;
5816
            if (lasti) {
  Branch (5816:17): [True: 489k, False: 2.74M]
5817
                int frame_lasti = _PyInterpreterFrame_LASTI(frame);
5818
                PyObject *lasti = PyLong_FromLong(frame_lasti);
5819
                if (lasti == NULL) {
  Branch (5819:21): [True: 0, False: 489k]
5820
                    goto exception_unwind;
5821
                }
5822
                PUSH(lasti);
5823
            }
5824
            _PyErr_Fetch(tstate, &exc, &val, &tb);
5825
            /* Make the raw exception data
5826
                available to the handler,
5827
                so a program can emulate the
5828
                Python main loop. */
5829
            _PyErr_NormalizeException(tstate, &exc, &val, &tb);
5830
            if (tb != NULL)
  Branch (5830:17): [True: 3.23M, False: 16]
5831
                PyException_SetTraceback(val, tb);
5832
            else
5833
                PyException_SetTraceback(val, Py_None);
5834
            Py_XDECREF(tb);
5835
            Py_XDECREF(exc);
5836
            PUSH(val);
5837
            JUMPTO(handler);
5838
            /* Resume normal execution */
5839
            DISPATCH();
5840
        }
5841
    }
5842
5843
exit_unwind:
5844
    assert(_PyErr_Occurred(tstate));
5845
    _Py_LeaveRecursiveCallTstate(tstate);
5846
    if (frame->is_entry) {
  Branch (5846:9): [True: 796k, False: 328k]
5847
        /* Restore previous cframe and exit */
5848
        tstate->cframe = cframe.previous;
5849
        tstate->cframe->use_tracing = cframe.use_tracing;
5850
        assert(tstate->cframe->current_frame == frame->previous);
5851
        return NULL;
5852
    }
5853
    frame = cframe.current_frame = pop_frame(tstate, frame);
5854
5855
resume_with_error:
5856
    SET_LOCALS_FROM_FRAME();
5857
    goto error;
5858
5859
}
5860
5861
static void
5862
format_missing(PyThreadState *tstate, const char *kind,
5863
               PyCodeObject *co, PyObject *names, PyObject *qualname)
5864
{
5865
    int err;
5866
    Py_ssize_t len = PyList_GET_SIZE(names);
5867
    PyObject *name_str, *comma, *tail, *tmp;
5868
5869
    assert(PyList_CheckExact(names));
5870
    assert(len >= 1);
5871
    /* Deal with the joys of natural language. */
5872
    switch (len) {
5873
    case 1:
  Branch (5873:5): [True: 554, False: 85]
5874
        name_str = PyList_GET_ITEM(names, 0);
5875
        Py_INCREF(name_str);
5876
        break;
5877
    case 2:
  Branch (5877:5): [True: 79, False: 560]
5878
        name_str = PyUnicode_FromFormat("%U and %U",
5879
                                        PyList_GET_ITEM(names, len - 2),
5880
                                        PyList_GET_ITEM(names, len - 1));
5881
        break;
5882
    default:
  Branch (5882:5): [True: 6, False: 633]
5883
        tail = PyUnicode_FromFormat(", %U, and %U",
5884
                                    PyList_GET_ITEM(names, len - 2),
5885
                                    PyList_GET_ITEM(names, len - 1));
5886
        if (tail == NULL)
  Branch (5886:13): [True: 0, False: 6]
5887
            return;
5888
        /* Chop off the last two objects in the list. This shouldn't actually
5889
           fail, but we can't be too careful. */
5890
        err = PyList_SetSlice(names, len - 2, len, NULL);
5891
        if (err == -1) {
  Branch (5891:13): [True: 0, False: 6]
5892
            Py_DECREF(tail);
5893
            return;
5894
        }
5895
        /* Stitch everything up into a nice comma-separated list. */
5896
        comma = PyUnicode_FromString(", ");
5897
        if (comma == NULL) {
  Branch (5897:13): [True: 0, False: 6]
5898
            Py_DECREF(tail);
5899
            return;
5900
        }
5901
        tmp = PyUnicode_Join(comma, names);
5902
        Py_DECREF(comma);
5903
        if (tmp == NULL) {
  Branch (5903:13): [True: 0, False: 6]
5904
            Py_DECREF(tail);
5905
            return;
5906
        }
5907
        name_str = PyUnicode_Concat(tmp, tail);
5908
        Py_DECREF(tmp);
5909
        Py_DECREF(tail);
5910
        break;
5911
    }
5912
    if (name_str == NULL)
  Branch (5912:9): [True: 0, False: 639]
5913
        return;
5914
    _PyErr_Format(tstate, PyExc_TypeError,
5915
                  "%U() missing %i required %s argument%s: %U",
5916
                  qualname,
5917
                  len,
5918
                  kind,
5919
                  len == 1 ? 
""554
:
"s"85
,
  Branch (5919:19): [True: 554, False: 85]
5920
                  name_str);
5921
    Py_DECREF(name_str);
5922
}
5923
5924
static void
5925
missing_arguments(PyThreadState *tstate, PyCodeObject *co,
5926
                  Py_ssize_t missing, Py_ssize_t defcount,
5927
                  PyObject **localsplus, PyObject *qualname)
5928
{
5929
    Py_ssize_t i, j = 0;
5930
    Py_ssize_t start, end;
5931
    int positional = (defcount != -1);
5932
    const char *kind = positional ? 
"positional"621
:
"keyword-only"18
;
  Branch (5932:24): [True: 621, False: 18]
5933
    PyObject *missing_names;
5934
5935
    /* Compute the names of the arguments that are missing. */
5936
    missing_names = PyList_New(missing);
5937
    if (missing_names == NULL)
  Branch (5937:9): [True: 0, False: 639]
5938
        return;
5939
    if (positional) {
  Branch (5939:9): [True: 621, False: 18]
5940
        start = 0;
5941
        end = co->co_argcount - defcount;
5942
    }
5943
    else {
5944
        start = co->co_argcount;
5945
        end = start + co->co_kwonlyargcount;
5946
    }
5947
    for (i = start; i < end; 
i++1.22k
) {
  Branch (5947:21): [True: 1.22k, False: 639]
5948
        if (localsplus[i] == NULL) {
  Branch (5948:13): [True: 734, False: 490]
5949
            PyObject *raw = PyTuple_GET_ITEM(co->co_localsplusnames, i);
5950
            PyObject *name = PyObject_Repr(raw);
5951
            if (name == NULL) {
  Branch (5951:17): [True: 0, False: 734]
5952
                Py_DECREF(missing_names);
5953
                return;
5954
            }
5955
            PyList_SET_ITEM(missing_names, j++, name);
5956
        }
5957
    }
5958
    assert(j == missing);
5959
    format_missing(tstate, kind, co, missing_names, qualname);
5960
    Py_DECREF(missing_names);
5961
}
5962
5963
static void
5964
too_many_positional(PyThreadState *tstate, PyCodeObject *co,
5965
                    Py_ssize_t given, PyObject *defaults,
5966
                    PyObject **localsplus, PyObject *qualname)
5967
{
5968
    int plural;
5969
    Py_ssize_t kwonly_given = 0;
5970
    Py_ssize_t i;
5971
    PyObject *sig, *kwonly_sig;
5972
    Py_ssize_t co_argcount = co->co_argcount;
5973
5974
    assert((co->co_flags & CO_VARARGS) == 0);
5975
    /* Count missing keyword-only args. */
5976
    for (i = co_argcount; i < co_argcount + co->co_kwonlyargcount; 
i++79
) {
  Branch (5976:27): [True: 79, False: 293]
5977
        if (localsplus[i] != NULL) {
  Branch (5977:13): [True: 7, False: 72]
5978
            kwonly_given++;
5979
        }
5980
    }
5981
    Py_ssize_t defcount = defaults == NULL ? 
0207
:
PyTuple_GET_SIZE86
(defaults);
  Branch (5981:27): [True: 207, False: 86]
5982
    if (defcount) {
  Branch (5982:9): [True: 85, False: 208]
5983
        Py_ssize_t atleast = co_argcount - defcount;
5984
        plural = 1;
5985
        sig = PyUnicode_FromFormat("from %zd to %zd", atleast, co_argcount);
5986
    }
5987
    else {
5988
        plural = (co_argcount != 1);
5989
        sig = PyUnicode_FromFormat("%zd", co_argcount);
5990
    }
5991
    if (sig == NULL)
  Branch (5991:9): [True: 0, False: 293]
5992
        return;
5993
    if (kwonly_given) {
  Branch (5993:9): [True: 5, False: 288]
5994
        const char *format = " positional argument%s (and %zd keyword-only argument%s)";
5995
        kwonly_sig = PyUnicode_FromFormat(format,
5996
                                          given != 1 ? 
"s"4
:
""1
,
  Branch (5996:43): [True: 4, False: 1]
5997
                                          kwonly_given,
5998
                                          kwonly_given != 1 ? 
"s"2
:
""3
);
  Branch (5998:43): [True: 2, False: 3]
5999
        if (kwonly_sig == NULL) {
  Branch (5999:13): [True: 0, False: 5]
6000
            Py_DECREF(sig);
6001
            return;
6002
        }
6003
    }
6004
    else {
6005
        /* This will not fail. */
6006
        kwonly_sig = PyUnicode_FromString("");
6007
        assert(kwonly_sig != NULL);
6008
    }
6009
    _PyErr_Format(tstate, PyExc_TypeError,
6010
                  "%U() takes %U positional argument%s but %zd%U %s given",
6011
                  qualname,
6012
                  sig,
6013
                  plural ? 
"s"153
:
""140
,
  Branch (6013:19): [True: 153, False: 140]
6014
                  given,
6015
                  kwonly_sig,
6016
                  given == 1 && 
!kwonly_given10
?
"was"9
:
"were"284
);
  Branch (6016:19): [True: 10, False: 283]
  Branch (6016:33): [True: 9, False: 1]
6017
    Py_DECREF(sig);
6018
    Py_DECREF(kwonly_sig);
6019
}
6020
6021
static int
6022
positional_only_passed_as_keyword(PyThreadState *tstate, PyCodeObject *co,
6023
                                  Py_ssize_t kwcount, PyObject* kwnames,
6024
                                  PyObject *qualname)
6025
{
6026
    int posonly_conflicts = 0;
6027
    PyObject* posonly_names = PyList_New(0);
6028
6029
    for(int k=0; k < co->co_posonlyargcount; 
k++29
){
  Branch (6029:18): [True: 29, False: 18]
6030
        PyObject* posonly_name = PyTuple_GET_ITEM(co->co_localsplusnames, k);
6031
6032
        for (int k2=0; k2<kwcount; 
k2++48
){
  Branch (6032:24): [True: 48, False: 29]
6033
            /* Compare the pointers first and fallback to PyObject_RichCompareBool*/
6034
            PyObject* kwname = PyTuple_GET_ITEM(kwnames, k2);
6035
            if (kwname == posonly_name){
  Branch (6035:17): [True: 19, False: 29]
6036
                if(PyList_Append(posonly_names, kwname) != 0) {
  Branch (6036:20): [True: 0, False: 19]
6037
                    goto fail;
6038
                }
6039
                posonly_conflicts++;
6040
                continue;
6041
            }
6042
6043
            int cmp = PyObject_RichCompareBool(posonly_name, kwname, Py_EQ);
6044
6045
            if ( cmp > 0) {
  Branch (6045:18): [True: 0, False: 29]
6046
                if(PyList_Append(posonly_names, kwname) != 0) {
  Branch (6046:20): [True: 0, False: 0]
6047
                    goto fail;
6048
                }
6049
                posonly_conflicts++;
6050
            } else if (cmp < 0) {
  Branch (6050:24): [True: 0, False: 29]
6051
                goto fail;
6052
            }
6053
6054
        }
6055
    }
6056
    if (posonly_conflicts) {
  Branch (6056:9): [True: 17, False: 1]
6057
        PyObject* comma = PyUnicode_FromString(", ");
6058
        if (comma == NULL) {
  Branch (6058:13): [True: 0, False: 17]
6059
            goto fail;
6060
        }
6061
        PyObject* error_names = PyUnicode_Join(comma, posonly_names);
6062
        Py_DECREF(comma);
6063
        if (error_names == NULL) {
  Branch (6063:13): [True: 0, False: 17]
6064
            goto fail;
6065
        }
6066
        _PyErr_Format(tstate, PyExc_TypeError,
6067
                      "%U() got some positional-only arguments passed"
6068
                      " as keyword arguments: '%U'",
6069
                      qualname, error_names);
6070
        Py_DECREF(error_names);
6071
        goto fail;
6072
    }
6073
6074
    Py_DECREF(posonly_names);
6075
    return 0;
6076
6077
fail:
6078
    Py_XDECREF(posonly_names);
6079
    return 1;
6080
6081
}
6082
6083
/* Exception table parsing code.
6084
 * See Objects/exception_table_notes.txt for details.
6085
 */
6086
6087
static inline unsigned char *
6088
parse_varint(unsigned char *p, int *result) {
6089
    int val = p[0] & 63;
6090
    while (p[0] & 64) {
  Branch (6090:12): [True: 8.11M, False: 22.5M]
6091
        p++;
6092
        val = (val << 6) | (p[0] & 63);
6093
    }
6094
    *result = val;
6095
    return p+1;
6096
}
6097
6098
static inline unsigned char *
6099
scan_back_to_entry_start(unsigned char *p) {
6100
    for (; (p[0]&128) == 0; 
p--4.43M
)
;4.43M
  Branch (6100:12): [True: 4.43M, False: 2.02M]
6101
    return p;
6102
}
6103
6104
static inline unsigned char *
6105
skip_to_next_entry(unsigned char *p, unsigned char *end) {
6106
    while (p < end && 
((p[0] & 128) == 0)11.2M
) {
  Branch (6106:12): [True: 11.2M, False: 262k]
  Branch (6106:23): [True: 8.57M, False: 2.69M]
6107
        p++;
6108
    }
6109
    return p;
6110
}
6111
6112
6113
#define MAX_LINEAR_SEARCH 40
6114
6115
static int
6116
get_exception_handler(PyCodeObject *code, int index, int *level, int *handler, int *lasti)
6117
{
6118
    unsigned char *start = (unsigned char *)PyBytes_AS_STRING(code->co_exceptiontable);
6119
    unsigned char *end = start + PyBytes_GET_SIZE(code->co_exceptiontable);
6120
    /* Invariants:
6121
     * start_table == end_table OR
6122
     * start_table points to a legal entry and end_table points
6123
     * beyond the table or to a legal entry that is after index.
6124
     */
6125
    if (end - start > MAX_LINEAR_SEARCH) {
  Branch (6125:9): [True: 1.64M, False: 2.69M]
6126
        int offset;
6127
        parse_varint(start, &offset);
6128
        if (offset > index) {
  Branch (6128:13): [True: 1.18k, False: 1.64M]
6129
            return 0;
6130
        }
6131
        
do 1.64M
{
6132
            unsigned char * mid = start + ((end-start)>>1);
6133
            mid = scan_back_to_entry_start(mid);
6134
            parse_varint(mid, &offset);
6135
            if (offset > index) {
  Branch (6135:17): [True: 1.61M, False: 405k]
6136
                end = mid;
6137
            }
6138
            else {
6139
                start = mid;
6140
            }
6141
6142
        } while (end - start > MAX_LINEAR_SEARCH);
  Branch (6142:18): [True: 376k, False: 1.64M]
6143
    }
6144
    unsigned char *scan = start;
6145
    while (scan < end) {
  Branch (6145:12): [True: 6.25M, False: 1.04M]
6146
        int start_offset, size;
6147
        scan = parse_varint(scan, &start_offset);
6148
        if (start_offset > index) {
  Branch (6148:13): [True: 65.0k, False: 6.18M]
6149
            break;
6150
        }
6151
        scan = parse_varint(scan, &size);
6152
        if (start_offset + size > index) {
  Branch (6152:13): [True: 3.23M, False: 2.95M]
6153
            scan = parse_varint(scan, handler);
6154
            int depth_and_lasti;
6155
            parse_varint(scan, &depth_and_lasti);
6156
            *level = depth_and_lasti >> 1;
6157
            *lasti = depth_and_lasti & 1;
6158
            return 1;
6159
        }
6160
        scan = skip_to_next_entry(scan, end);
6161
    }
6162
    return 0;
6163
}
6164
6165
static int
6166
initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
6167
    PyObject **localsplus, PyObject *const *args,
6168
    Py_ssize_t argcount, PyObject *kwnames)
6169
{
6170
    PyCodeObject *co = (PyCodeObject*)func->func_code;
6171
    const Py_ssize_t total_args = co->co_argcount + co->co_kwonlyargcount;
6172
6173
    /* Create a dictionary for keyword parameters (**kwags) */
6174
    PyObject *kwdict;
6175
    Py_ssize_t i;
6176
    if (co->co_flags & CO_VARKEYWORDS) {
  Branch (6176:9): [True: 6.03M, False: 75.2M]
6177
        kwdict = PyDict_New();
6178
        if (kwdict == NULL) {
  Branch (6178:13): [True: 0, False: 6.03M]
6179
            goto fail_pre_positional;
6180
        }
6181
        i = total_args;
6182
        if (co->co_flags & CO_VARARGS) {
  Branch (6182:13): [True: 5.39M, False: 639k]
6183
            i++;
6184
        }
6185
        assert(localsplus[i] == NULL);
6186
        localsplus[i] = kwdict;
6187
    }
6188
    else {
6189
        kwdict = NULL;
6190
    }
6191
6192
    /* Copy all positional arguments into local variables */
6193
    Py_ssize_t j, n;
6194
    if (argcount > co->co_argcount) {
  Branch (6194:9): [True: 9.64M, False: 71.5M]
6195
        n = co->co_argcount;
6196
    }
6197
    else {
6198
        n = argcount;
6199
    }
6200
    for (j = 0; j < n; 
j++153M
) {
  Branch (6200:17): [True: 153M, False: 81.2M]
6201
        PyObject *x = args[j];
6202
        assert(localsplus[j] == NULL);
6203
        localsplus[j] = x;
6204
    }
6205
6206
    /* Pack other positional arguments into the *args argument */
6207
    if (co->co_flags & CO_VARARGS) {
  Branch (6207:9): [True: 11.7M, False: 69.5M]
6208
        PyObject *u = NULL;
6209
        u = _PyTuple_FromArraySteal(args + n, argcount - n);
6210
        if (u == NULL) {
  Branch (6210:13): [True: 0, False: 11.7M]
6211
            goto fail_post_positional;
6212
        }
6213
        assert(localsplus[total_args] == NULL);
6214
        localsplus[total_args] = u;
6215
    }
6216
    else if (argcount > n) {
  Branch (6216:14): [True: 315, False: 69.5M]
6217
        /* Too many postional args. Error is reported later */
6218
        for (j = n; j < argcount; 
j++369
) {
  Branch (6218:21): [True: 369, False: 315]
6219
            Py_DECREF(args[j]);
6220
        }
6221
    }
6222
6223
    /* Handle keyword arguments */
6224
    if (kwnames != NULL) {
  Branch (6224:9): [True: 14.5M, False: 66.6M]
6225
        Py_ssize_t kwcount = PyTuple_GET_SIZE(kwnames);
6226
        for (i = 0; i < kwcount; 
i++16.6M
) {
  Branch (6226:21): [True: 16.6M, False: 14.5M]
6227
            PyObject **co_varnames;
6228
            PyObject *keyword = PyTuple_GET_ITEM(kwnames, i);
6229
            PyObject *value = args[i+argcount];
6230
            Py_ssize_t j;
6231
6232
            if (keyword == NULL || !PyUnicode_Check(keyword)) {
  Branch (6232:17): [True: 0, False: 16.6M]
  Branch (6232:36): [True: 0, False: 16.6M]
6233
                _PyErr_Format(tstate, PyExc_TypeError,
6234
                            "%U() keywords must be strings",
6235
                          func->func_qualname);
6236
                goto kw_fail;
6237
            }
6238
6239
            /* Speed hack: do raw pointer compares. As names are
6240
            normally interned this should almost always hit. */
6241
            co_varnames = ((PyTupleObject *)(co->co_localsplusnames))->ob_item;
6242
            for (j = co->co_posonlyargcount; j < total_args; 
j++45.6M
) {
  Branch (6242:46): [True: 60.8M, False: 1.53M]
6243
                PyObject *varname = co_varnames[j];
6244
                if (varname == keyword) {
  Branch (6244:21): [True: 15.1M, False: 45.6M]
6245
                    goto kw_found;
6246
                }
6247
            }
6248
6249
            /* Slow fallback, just in case */
6250
            
for (j = co->co_posonlyargcount; 1.53M
j < total_args;
j++1.37M
) {
  Branch (6250:46): [True: 1.40M, False: 1.49M]
6251
                PyObject *varname = co_varnames[j];
6252
                int cmp = PyObject_RichCompareBool( keyword, varname, Py_EQ);
6253
                if (cmp > 0) {
  Branch (6253:21): [True: 32.1k, False: 1.37M]
6254
                    goto kw_found;
6255
                }
6256
                else if (cmp < 0) {
  Branch (6256:26): [True: 0, False: 1.37M]
6257
                    goto kw_fail;
6258
                }
6259
            }
6260
6261
            assert(j >= total_args);
6262
            if (kwdict == NULL) {
  Branch (6262:17): [True: 165, False: 1.49M]
6263
6264
                if (co->co_posonlyargcount
  Branch (6264:21): [True: 18, False: 147]
6265
                    && positional_only_passed_as_keyword(tstate, co,
  Branch (6265:24): [True: 17, False: 1]
6266
                                                        kwcount, kwnames,
6267
                                                        func->func_qualname))
6268
                {
6269
                    goto kw_fail;
6270
                }
6271
6272
                _PyErr_Format(tstate, PyExc_TypeError,
6273
                            "%U() got an unexpected keyword argument '%S'",
6274
                          func->func_qualname, keyword);
6275
                goto kw_fail;
6276
            }
6277
6278
            if (PyDict_SetItem(kwdict, keyword, value) == -1) {
  Branch (6278:17): [True: 0, False: 1.49M]
6279
                goto kw_fail;
6280
            }
6281
            Py_DECREF(value);
6282
            continue;
6283
6284
        kw_fail:
6285
            for (;i < kwcount; 
i++374
) {
  Branch (6285:19): [True: 374, False: 226]
6286
                PyObject *value = args[i+argcount];
6287
                Py_DECREF(value);
6288
            }
6289
            goto fail_post_args;
6290
6291
        kw_found:
6292
            if (localsplus[j] != NULL) {
  Branch (6292:17): [True: 61, False: 15.1M]
6293
                _PyErr_Format(tstate, PyExc_TypeError,
6294
                            "%U() got multiple values for argument '%S'",
6295
                          func->func_qualname, keyword);
6296
                goto kw_fail;
6297
            }
6298
            localsplus[j] = value;
6299
        }
6300
    }
6301
6302
    /* Check the number of positional arguments */
6303
    if ((argcount > co->co_argcount) && 
!(co->co_flags & 9.64M
CO_VARARGS9.64M
)) {
  Branch (6303:9): [True: 9.64M, False: 71.5M]
  Branch (6303:41): [True: 293, False: 9.64M]
6304
        too_many_positional(tstate, co, argcount, func->func_defaults, localsplus,
6305
                            func->func_qualname);
6306
        goto fail_post_args;
6307
    }
6308
6309
    /* Add missing positional arguments (copy default values from defs) */
6310
    if (argcount < co->co_argcount) {
  Branch (6310:9): [True: 21.2M, False: 59.9M]
6311
        Py_ssize_t defcount = func->func_defaults == NULL ? 
049.1k
:
PyTuple_GET_SIZE21.2M
(func->func_defaults);
  Branch (6311:31): [True: 49.1k, False: 21.2M]
6312
        Py_ssize_t m = co->co_argcount - defcount;
6313
        Py_ssize_t missing = 0;
6314
        for (i = argcount; i < m; 
i++164k
) {
  Branch (6314:28): [True: 164k, False: 21.2M]
6315
            if (localsplus[i] == NULL) {
  Branch (6315:17): [True: 711, False: 163k]
6316
                missing++;
6317
            }
6318
        }
6319
        if (missing) {
  Branch (6319:13): [True: 621, False: 21.2M]
6320
            missing_arguments(tstate, co, missing, defcount, localsplus,
6321
                              func->func_qualname);
6322
            goto fail_post_args;
6323
        }
6324
        if (n > m)
  Branch (6324:13): [True: 3.36M, False: 17.8M]
6325
            i = n - m;
6326
        else
6327
            i = 0;
6328
        if (defcount) {
  Branch (6328:13): [True: 21.2M, False: 48.7k]
6329
            PyObject **defs = &PyTuple_GET_ITEM(func->func_defaults, 0);
6330
            for (; i < defcount; 
i++36.6M
) {
  Branch (6330:20): [True: 36.6M, False: 21.2M]
6331
                if (localsplus[m+i] == NULL) {
  Branch (6331:21): [True: 24.0M, False: 12.6M]
6332
                    PyObject *def = defs[i];
6333
                    Py_INCREF(def);
6334
                    localsplus[m+i] = def;
6335
                }
6336
            }
6337
        }
6338
    }
6339
6340
    /* Add missing keyword arguments (copy default values from kwdefs) */
6341
    if (co->co_kwonlyargcount > 0) {
  Branch (6341:9): [True: 2.59M, False: 78.6M]
6342
        Py_ssize_t missing = 0;
6343
        for (i = co->co_argcount; i < total_args; 
i++6.06M
) {
  Branch (6343:35): [True: 6.06M, False: 2.59M]
6344
            if (localsplus[i] != NULL)
  Branch (6344:17): [True: 2.36M, False: 3.69M]
6345
                continue;
6346
            PyObject *varname = PyTuple_GET_ITEM(co->co_localsplusnames, i);
6347
            if (func->func_kwdefaults != NULL) {
  Branch (6347:17): [True: 3.69M, False: 10]
6348
                PyObject *def = PyDict_GetItemWithError(func->func_kwdefaults, varname);
6349
                if (def) {
  Branch (6349:21): [True: 3.69M, False: 13]
6350
                    Py_INCREF(def);
6351
                    localsplus[i] = def;
6352
                    continue;
6353
                }
6354
                else if (_PyErr_Occurred(tstate)) {
  Branch (6354:26): [True: 0, False: 13]
6355
                    goto fail_post_args;
6356
                }
6357
            }
6358
            missing++;
6359
        }
6360
        if (missing) {
  Branch (6360:13): [True: 18, False: 2.59M]
6361
            missing_arguments(tstate, co, missing, -1, localsplus,
6362
                              func->func_qualname);
6363
            goto fail_post_args;
6364
        }
6365
    }
6366
    return 0;
6367
6368
fail_pre_positional:
6369
    for (j = 0; j < argcount; j++) {
  Branch (6369:17): [True: 0, False: 0]
6370
        Py_DECREF(args[j]);
6371
    }
6372
    /* fall through */
6373
fail_post_positional:
6374
    if (kwnames) {
  Branch (6374:9): [True: 0, False: 0]
6375
        Py_ssize_t kwcount = PyTuple_GET_SIZE(kwnames);
6376
        for (j = argcount; j < argcount+kwcount; j++) {
  Branch (6376:28): [True: 0, False: 0]
6377
            Py_DECREF(args[j]);
6378
        }
6379
    }
6380
    /* fall through */
6381
fail_post_args:
6382
    return -1;
6383
}
6384
6385
/* Consumes references to func, locals and all the args */
6386
static _PyInterpreterFrame *
6387
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
6388
                        PyObject *locals, PyObject* const* args,
6389
                        size_t argcount, PyObject *kwnames)
6390
{
6391
    PyCodeObject * code = (PyCodeObject *)func->func_code;
6392
    CALL_STAT_INC(frames_pushed);
6393
    _PyInterpreterFrame *frame = _PyThreadState_PushFrame(tstate, code->co_framesize);
6394
    if (frame == NULL) {
  Branch (6394:9): [True: 0, False: 81.2M]
6395
        goto fail;
6396
    }
6397
    _PyFrame_InitializeSpecials(frame, func, locals, code);
6398
    PyObject **localsarray = &frame->localsplus[0];
6399
    for (int i = 0; i < code->co_nlocalsplus; 
i++336M
) {
  Branch (6399:21): [True: 336M, False: 81.2M]
6400
        localsarray[i] = NULL;
6401
    }
6402
    if (initialize_locals(tstate, func, localsarray, args, argcount, kwnames)) {
  Branch (6402:9): [True: 1.15k, False: 81.2M]
6403
        assert(frame->owner != FRAME_OWNED_BY_GENERATOR);
6404
        _PyFrame_Clear(frame);
6405
        return NULL;
6406
    }
6407
    return frame;
6408
fail:
6409
    /* Consume the references */
6410
    for (size_t i = 0; i < argcount; i++) {
  Branch (6410:24): [True: 0, False: 0]
6411
        Py_DECREF(args[i]);
6412
    }
6413
    if (kwnames) {
  Branch (6413:9): [True: 0, False: 0]
6414
        Py_ssize_t kwcount = PyTuple_GET_SIZE(kwnames);
6415
        for (Py_ssize_t i = 0; i < kwcount; i++) {
  Branch (6415:32): [True: 0, False: 0]
6416
            Py_DECREF(args[i+argcount]);
6417
        }
6418
    }
6419
    PyErr_NoMemory();
6420
    return NULL;
6421
}
6422
6423
static void
6424
_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame * frame)
6425
{
6426
    tstate->recursion_remaining--;
6427
    assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
6428
    assert(frame->owner == FRAME_OWNED_BY_THREAD);
6429
    _PyFrame_Clear(frame);
6430
    tstate->recursion_remaining++;
6431
    _PyThreadState_PopFrame(tstate, frame);
6432
}
6433
6434
PyObject *
6435
_PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func,
6436
               PyObject *locals,
6437
               PyObject* const* args, size_t argcount,
6438
               PyObject *kwnames)
6439
{
6440
    /* _PyEvalFramePushAndInit consumes the references
6441
     * to func, locals and all its arguments */
6442
    Py_INCREF(func);
6443
    Py_XINCREF(locals);
6444
    for (size_t i = 0; i < argcount; 
i++121M
) {
  Branch (6444:24): [True: 121M, False: 53.2M]
6445
        Py_INCREF(args[i]);
6446
    }
6447
    if (kwnames) {
  Branch (6447:9): [True: 3.44M, False: 49.7M]
6448
        Py_ssize_t kwcount = PyTuple_GET_SIZE(kwnames);
6449
        for (Py_ssize_t i = 0; i < kwcount; 
i++4.65M
) {
  Branch (6449:32): [True: 4.65M, False: 3.44M]
6450
            Py_INCREF(args[i+argcount]);
6451
        }
6452
    }
6453
    _PyInterpreterFrame *frame = _PyEvalFramePushAndInit(
6454
        tstate, func, locals, args, argcount, kwnames);
6455
    if (frame == NULL) {
  Branch (6455:9): [True: 846, False: 53.2M]
6456
        return NULL;
6457
    }
6458
    EVAL_CALL_STAT_INC(EVAL_CALL_VECTOR);
6459
    PyObject *retval = _PyEval_EvalFrame(tstate, frame, 0);
6460
    assert(
6461
        _PyFrame_GetStackPointer(frame) == _PyFrame_Stackbase(frame) ||
6462
        _PyFrame_GetStackPointer(frame) == frame->localsplus
6463
    );
6464
    _PyEvalFrameClearAndPop(tstate, frame);
6465
    return retval;
6466
}
6467
6468
/* Legacy API */
6469
PyObject *
6470
PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
6471
                  PyObject *const *args, int argcount,
6472
                  PyObject *const *kws, int kwcount,
6473
                  PyObject *const *defs, int defcount,
6474
                  PyObject *kwdefs, PyObject *closure)
6475
{
6476
    PyThreadState *tstate = _PyThreadState_GET();
6477
    PyObject *res = NULL;
6478
    PyObject *defaults = _PyTuple_FromArray(defs, defcount);
6479
    if (defaults == NULL) {
  Branch (6479:9): [True: 0, False: 2]
6480
        return NULL;
6481
    }
6482
    PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
6483
    if (builtins == NULL) {
  Branch (6483:9): [True: 0, False: 2]
6484
        Py_DECREF(defaults);
6485
        return NULL;
6486
    }
6487
    if (locals == NULL) {
  Branch (6487:9): [True: 0, False: 2]
6488
        locals = globals;
6489
    }
6490
    PyObject *kwnames = NULL;
6491
    PyObject *const *allargs;
6492
    PyObject **newargs = NULL;
6493
    PyFunctionObject *func = NULL;
6494
    if (kwcount == 0) {
  Branch (6494:9): [True: 2, False: 0]
6495
        allargs = args;
6496
    }
6497
    else {
6498
        kwnames = PyTuple_New(kwcount);
6499
        if (kwnames == NULL) {
  Branch (6499:13): [True: 0, False: 0]
6500
            goto fail;
6501
        }
6502
        newargs = PyMem_Malloc(sizeof(PyObject *)*(kwcount+argcount));
6503
        if (newargs == NULL) {
  Branch (6503:13): [True: 0, False: 0]
6504
            goto fail;
6505
        }
6506
        for (int i = 0; i < argcount; i++) {
  Branch (6506:25): [True: 0, False: 0]
6507
            newargs[i] = args[i];
6508
        }
6509
        for (int i = 0; i < kwcount; i++) {
  Branch (6509:25): [True: 0, False: 0]
6510
            Py_INCREF(kws[2*i]);
6511
            PyTuple_SET_ITEM(kwnames, i, kws[2*i]);
6512
            newargs[argcount+i] = kws[2*i+1];
6513
        }
6514
        allargs = newargs;
6515
    }
6516
    for (int i = 0; i < kwcount; 
i++0
) {
  Branch (6516:21): [True: 0, False: 2]
6517
        Py_INCREF(kws[2*i]);
6518
        PyTuple_SET_ITEM(kwnames, i, kws[2*i]);
6519
    }
6520
    PyFrameConstructor constr = {
6521
        .fc_globals = globals,
6522
        .fc_builtins = builtins,
6523
        .fc_name = ((PyCodeObject *)_co)->co_name,
6524
        .fc_qualname = ((PyCodeObject *)_co)->co_name,
6525
        .fc_code = _co,
6526
        .fc_defaults = defaults,
6527
        .fc_kwdefaults = kwdefs,
6528
        .fc_closure = closure
6529
    };
6530
    func = _PyFunction_FromConstructor(&constr);
6531
    if (func == NULL) {
  Branch (6531:9): [True: 0, False: 2]
6532
        goto fail;
6533
    }
6534
    EVAL_CALL_STAT_INC(EVAL_CALL_LEGACY);
6535
    res = _PyEval_Vector(tstate, func, locals,
6536
                         allargs, argcount,
6537
                         kwnames);
6538
fail:
6539
    Py_XDECREF(func);
6540
    Py_XDECREF(kwnames);
6541
    PyMem_Free(newargs);
6542
    Py_DECREF(defaults);
6543
    return res;
6544
}
6545
6546
6547
/* Logic for the raise statement (too complicated for inlining).
6548
   This *consumes* a reference count to each of its arguments. */
6549
static int
6550
do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause)
6551
{
6552
    PyObject *type = NULL, *value = NULL;
6553
6554
    if (exc == NULL) {
  Branch (6554:9): [True: 6.19k, False: 284k]
6555
        /* Reraise */
6556
        _PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate);
6557
        value = exc_info->exc_value;
6558
        if (Py_IsNone(value) || 
value == NULL6.19k
) {
  Branch (6558:33): [True: 1, False: 6.18k]
6559
            _PyErr_SetString(tstate, PyExc_RuntimeError,
6560
                             "No active exception to reraise");
6561
            return 0;
6562
        }
6563
        assert(PyExceptionInstance_Check(value));
6564
        type = PyExceptionInstance_Class(value);
6565
        Py_XINCREF(type);
6566
        Py_XINCREF(value);
6567
        PyObject *tb = PyException_GetTraceback(value); /* new ref */
6568
        _PyErr_Restore(tstate, type, value, tb);
6569
        return 1;
6570
    }
6571
6572
    /* We support the following forms of raise:
6573
       raise
6574
       raise <instance>
6575
       raise <type> */
6576
6577
    if (PyExceptionClass_Check(exc)) {
6578
        type = exc;
6579
        value = _PyObject_CallNoArgs(exc);
6580
        if (value == NULL)
  Branch (6580:13): [True: 1, False: 22.8k]
6581
            goto raise_error;
6582
        if (!PyExceptionInstance_Check(value)) {
  Branch (6582:13): [True: 1, False: 22.8k]
6583
            _PyErr_Format(tstate, PyExc_TypeError,
6584
                          "calling %R should have returned an instance of "
6585
                          "BaseException, not %R",
6586
                          type, Py_TYPE(value));
6587
             goto raise_error;
6588
        }
6589
    }
6590
    else if (PyExceptionInstance_Check(exc)) {
6591
        value = exc;
6592
        type = PyExceptionInstance_Class(exc);
6593
        Py_INCREF(type);
6594
    }
6595
    else {
6596
        /* Not something you can raise.  You get an exception
6597
           anyway, just not what you specified :-) */
6598
        Py_DECREF(exc);
6599
        _PyErr_SetString(tstate, PyExc_TypeError,
6600
                         "exceptions must derive from BaseException");
6601
        goto raise_error;
6602
    }
6603
6604
    assert(type != NULL);
6605
    assert(value != NULL);
6606
6607
    if (cause) {
  Branch (6607:9): [True: 122k, False: 162k]
6608
        PyObject *fixed_cause;
6609
        if (PyExceptionClass_Check(cause)) {
6610
            fixed_cause = _PyObject_CallNoArgs(cause);
6611
            if (fixed_cause == NULL)
  Branch (6611:17): [True: 1, False: 2]
6612
                goto raise_error;
6613
            Py_DECREF(cause);
6614
        }
6615
        else if (PyExceptionInstance_Check(cause)) {
6616
            fixed_cause = cause;
6617
        }
6618
        else if (Py_IsNone(cause)) {
6619
            Py_DECREF(cause);
6620
            fixed_cause = NULL;
6621
        }
6622
        else {
6623
            _PyErr_SetString(tstate, PyExc_TypeError,
6624
                             "exception causes must derive from "
6625
                             "BaseException");
6626
            goto raise_error;
6627
        }
6628
        PyException_SetCause(value, fixed_cause);
6629
    }
6630
6631
    _PyErr_SetObject(tstate, type, value);
6632
    /* _PyErr_SetObject incref's its arguments */
6633
    Py_DECREF(value);
6634
    Py_DECREF(type);
6635
    return 0;
6636
6637
raise_error:
6638
    Py_XDECREF(value);
6639
    Py_XDECREF(type);
6640
    Py_XDECREF(cause);
6641
    return 0;
6642
}
6643
6644
/* Logic for matching an exception in an except* clause (too
6645
   complicated for inlining).
6646
*/
6647
6648
static int
6649
exception_group_match(PyObject* exc_value, PyObject *match_type,
6650
                      PyObject **match, PyObject **rest)
6651
{
6652
    if (Py_IsNone(exc_value)) {
6653
        *match = Py_NewRef(Py_None);
6654
        *rest = Py_NewRef(Py_None);
6655
        return 0;
6656
    }
6657
    assert(PyExceptionInstance_Check(exc_value));
6658
6659
    if (PyErr_GivenExceptionMatches(exc_value, match_type)) {
  Branch (6659:9): [True: 56, False: 117]
6660
        /* Full match of exc itself */
6661
        bool is_eg = _PyBaseExceptionGroup_Check(exc_value);
6662
        if (is_eg) {
  Branch (6662:13): [True: 18, False: 38]
6663
            *match = Py_NewRef(exc_value);
6664
        }
6665
        else {
6666
            /* naked exception - wrap it */
6667
            PyObject *excs = PyTuple_Pack(1, exc_value);
6668
            if (excs == NULL) {
  Branch (6668:17): [True: 0, False: 38]
6669
                return -1;
6670
            }
6671
            PyObject *wrapped = _PyExc_CreateExceptionGroup("", excs);
6672
            Py_DECREF(excs);
6673
            if (wrapped == NULL) {
  Branch (6673:17): [True: 0, False: 38]
6674
                return -1;
6675
            }
6676
            *match = wrapped;
6677
        }
6678
        *rest = Py_NewRef(Py_None);
6679
        return 0;
6680
    }
6681
6682
    /* exc_value does not match match_type.
6683
     * Check for partial match if it's an exception group.
6684
     */
6685
    if (_PyBaseExceptionGroup_Check(exc_value)) {
6686
        PyObject *pair = PyObject_CallMethod(exc_value, "split", "(O)",
6687
                                             match_type);
6688
        if (pair == NULL) {
  Branch (6688:13): [True: 0, False: 101]
6689
            return -1;
6690
        }
6691
        assert(PyTuple_CheckExact(pair));
6692
        assert(PyTuple_GET_SIZE(pair) == 2);
6693
        *match = Py_NewRef(PyTuple_GET_ITEM(pair, 0));
6694
        *rest = Py_NewRef(PyTuple_GET_ITEM(pair, 1));
6695
        Py_DECREF(pair);
6696
        return 0;
6697
    }
6698
    /* no match */
6699
    *match = Py_NewRef(Py_None);
6700
    *rest = Py_NewRef(Py_None);
6701
    return 0;
6702
}
6703
6704
/* Iterate v argcnt times and store the results on the stack (via decreasing
6705
   sp).  Return 1 for success, 0 if error.
6706
6707
   If argcntafter == -1, do a simple unpack. If it is >= 0, do an unpack
6708
   with a variable target.
6709
*/
6710
6711
static int
6712
unpack_iterable(PyThreadState *tstate, PyObject *v,
6713
                int argcnt, int argcntafter, PyObject **sp)
6714
{
6715
    int i = 0, j = 0;
6716
    Py_ssize_t ll = 0;
6717
    PyObject *it;  /* iter(v) */
6718
    PyObject *w;
6719
    PyObject *l = NULL; /* variable list */
6720
6721
    assert(v != NULL);
6722
6723
    it = PyObject_GetIter(v);
6724
    if (it == NULL) {
  Branch (6724:9): [True: 12, False: 666k]
6725
        if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
  Branch (6725:13): [True: 9, False: 3]
6726
            
Py_TYPE9
(v)->tp_iter == NULL9
&&
!PySequence_Check(v)9
)
  Branch (6726:13): [True: 9, False: 0]
  Branch (6726:44): [True: 9, False: 0]
6727
        {
6728
            _PyErr_Format(tstate, PyExc_TypeError,
6729
                          "cannot unpack non-iterable %.200s object",
6730
                          Py_TYPE(v)->tp_name);
6731
        }
6732
        return 0;
6733
    }
6734
6735
    
for (; 666k
i < argcnt;
i++2.10M
) {
  Branch (6735:12): [True: 2.10M, False: 664k]
6736
        w = PyIter_Next(it);
6737
        if (w == NULL) {
  Branch (6737:13): [True: 1.36k, False: 2.10M]
6738
            /* Iterator done, via error or exhaustion. */
6739
            if (!_PyErr_Occurred(tstate)) {
  Branch (6739:17): [True: 1.33k, False: 22]
6740
                if (argcntafter == -1) {
  Branch (6740:21): [True: 1.33k, False: 1]
6741
                    _PyErr_Format(tstate, PyExc_ValueError,
6742
                                  "not enough values to unpack "
6743
                                  "(expected %d, got %d)",
6744
                                  argcnt, i);
6745
                }
6746
                else {
6747
                    _PyErr_Format(tstate, PyExc_ValueError,
6748
                                  "not enough values to unpack "
6749
                                  "(expected at least %d, got %d)",
6750
                                  argcnt + argcntafter, i);
6751
                }
6752
            }
6753
            goto Error;
6754
        }
6755
        *--sp = w;
6756
    }
6757
6758
    if (argcntafter == -1) {
  Branch (6758:9): [True: 560k, False: 104k]
6759
        /* We better have exhausted the iterator now. */
6760
        w = PyIter_Next(it);
6761
        if (w == NULL) {
  Branch (6761:13): [True: 560k, False: 55]
6762
            if (_PyErr_Occurred(tstate))
  Branch (6762:17): [True: 1, False: 560k]
6763
                goto Error;
6764
            Py_DECREF(it);
6765
            return 1;
6766
        }
6767
        Py_DECREF(w);
6768
        _PyErr_Format(tstate, PyExc_ValueError,
6769
                      "too many values to unpack (expected %d)",
6770
                      argcnt);
6771
        goto Error;
6772
    }
6773
6774
    l = PySequence_List(it);
6775
    if (l == NULL)
  Branch (6775:9): [True: 1, False: 104k]
6776
        goto Error;
6777
    *--sp = l;
6778
    i++;
6779
6780
    ll = PyList_GET_SIZE(l);
6781
    if (ll < argcntafter) {
  Branch (6781:9): [True: 1, False: 104k]
6782
        _PyErr_Format(tstate, PyExc_ValueError,
6783
            "not enough values to unpack (expected at least %d, got %zd)",
6784
            argcnt + argcntafter, argcnt + ll);
6785
        goto Error;
6786
    }
6787
6788
    /* Pop the "after-variable" args off the list. */
6789
    
for (j = argcntafter; 104k
j > 0;
j--, i++202
) {
  Branch (6789:27): [True: 202, False: 104k]
6790
        *--sp = PyList_GET_ITEM(l, ll - j);
6791
    }
6792
    /* Resize the list. */
6793
    Py_SET_SIZE(l, ll - argcntafter);
6794
    Py_DECREF(it);
6795
    return 1;
6796
6797
Error:
6798
    for (; i > 0; 
i--, sp++1.46k
)
  Branch (6798:12): [True: 1.46k, False: 1.41k]
6799
        Py_DECREF(*sp);
6800
    Py_XDECREF(it);
6801
    return 0;
6802
}
6803
6804
static void
6805
call_exc_trace(Py_tracefunc func, PyObject *self,
6806
               PyThreadState *tstate,
6807
               _PyInterpreterFrame *f)
6808
{
6809
    PyObject *type, *value, *traceback, *orig_traceback, *arg;
6810
    int err;
6811
    _PyErr_Fetch(tstate, &type, &value, &orig_traceback);
6812
    if (value == NULL) {
  Branch (6812:9): [True: 1.32k, False: 7.68k]
6813
        value = Py_None;
6814
        Py_INCREF(value);
6815
    }
6816
    _PyErr_NormalizeException(tstate, &type, &value, &orig_traceback);
6817
    traceback = (orig_traceback != NULL) ? 
orig_traceback8.92k
:
Py_None86
;
  Branch (6817:17): [True: 8.92k, False: 86]
6818
    arg = PyTuple_Pack(3, type, value, traceback);
6819
    if (arg == NULL) {
  Branch (6819:9): [True: 0, False: 9.00k]
6820
        _PyErr_Restore(tstate, type, value, orig_traceback);
6821
        return;
6822
    }
6823
    err = call_trace(func, self, tstate, f, PyTrace_EXCEPTION, arg);
6824
    Py_DECREF(arg);
6825
    if (err == 0) {
  Branch (6825:9): [True: 8.00k, False: 1.00k]
6826
        _PyErr_Restore(tstate, type, value, orig_traceback);
6827
    }
6828
    else {
6829
        Py_XDECREF(type);
6830
        Py_XDECREF(value);
6831
        Py_XDECREF(orig_traceback);
6832
    }
6833
}
6834
6835
static int
6836
call_trace_protected(Py_tracefunc func, PyObject *obj,
6837
                     PyThreadState *tstate, _PyInterpreterFrame *frame,
6838
                     int what, PyObject *arg)
6839
{
6840
    PyObject *type, *value, *traceback;
6841
    int err;
6842
    _PyErr_Fetch(tstate, &type, &value, &traceback);
6843
    err = call_trace(func, obj, tstate, frame, what, arg);
6844
    if (err == 0)
  Branch (6844:9): [True: 2.54M, False: 2.01k]
6845
    {
6846
        _PyErr_Restore(tstate, type, value, traceback);
6847
        return 0;
6848
    }
6849
    else {
6850
        Py_XDECREF(type);
6851
        Py_XDECREF(value);
6852
        Py_XDECREF(traceback);
6853
        return -1;
6854
    }
6855
}
6856
6857
static void
6858
initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *frame)
6859
{
6860
    PyCodeObject *code = frame->f_code;
6861
    if (trace_info->code != code) {
  Branch (6861:9): [True: 0, False: 0]
6862
        trace_info->code = code;
6863
        _PyCode_InitAddressRange(code, &trace_info->bounds);
6864
    }
6865
}
6866
6867
void
6868
PyThreadState_EnterTracing(PyThreadState *tstate)
6869
{
6870
    tstate->tracing++;
6871
}
6872
6873
void
6874
PyThreadState_LeaveTracing(PyThreadState *tstate)
6875
{
6876
    tstate->tracing--;
6877
}
6878
6879
static int
6880
call_trace(Py_tracefunc func, PyObject *obj,
6881
           PyThreadState *tstate, _PyInterpreterFrame *frame,
6882
           int what, PyObject *arg)
6883
{
6884
    int result;
6885
    if (tstate->tracing) {
  Branch (6885:9): [True: 2.29M, False: 1.55M]
6886
        return 0;
6887
    }
6888
    PyFrameObject *f = _PyFrame_GetFrameObject(frame);
6889
    if (f == NULL) {
  Branch (6889:9): [True: 0, False: 1.55M]
6890
        return -1;
6891
    }
6892
    int old_what = tstate->tracing_what;
6893
    tstate->tracing_what = what;
6894
    PyThreadState_EnterTracing(tstate);
6895
    assert(_PyInterpreterFrame_LASTI(frame) >= 0);
6896
    if (_PyCode_InitLineArray(frame->f_code)) {
  Branch (6896:9): [True: 0, False: 1.55M]
6897
        return -1;
6898
    }
6899
    f->f_lineno = _PyCode_LineNumberFromArray(frame->f_code, _PyInterpreterFrame_LASTI(frame));
6900
    result = func(obj, f, what, arg);
6901
    f->f_lineno = 0;
6902
    PyThreadState_LeaveTracing(tstate);
6903
    tstate->tracing_what = old_what;
6904
    return result;
6905
}
6906
6907
PyObject*
6908
_PyEval_CallTracing(PyObject *func, PyObject *args)
6909
{
6910
    // Save and disable tracing
6911
    PyThreadState *tstate = _PyThreadState_GET();
6912
    int save_tracing = tstate->tracing;
6913
    int save_use_tracing = tstate->cframe->use_tracing;
6914
    tstate->tracing = 0;
6915
6916
    // Call the tracing function
6917
    PyObject *result = PyObject_Call(func, args, NULL);
6918
6919
    // Restore tracing
6920
    tstate->tracing = save_tracing;
6921
    tstate->cframe->use_tracing = save_use_tracing;
6922
    return result;
6923
}
6924
6925
/* See Objects/lnotab_notes.txt for a description of how tracing works. */
6926
static int
6927
maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
6928
                      PyThreadState *tstate, _PyInterpreterFrame *frame, int instr_prev)
6929
{
6930
    int result = 0;
6931
6932
    /* If the last instruction falls at the start of a line or if it
6933
       represents a jump backwards, update the frame's line number and
6934
       then call the trace function if we're tracing source lines.
6935
    */
6936
    if (_PyCode_InitLineArray(frame->f_code)) {
  Branch (6936:9): [True: 0, False: 5.88M]
6937
        return -1;
6938
    }
6939
    int lastline;
6940
    if (instr_prev <= frame->f_code->_co_firsttraceable) {
  Branch (6940:9): [True: 128k, False: 5.75M]
6941
        lastline = -1;
6942
    }
6943
    else {
6944
        lastline = _PyCode_LineNumberFromArray(frame->f_code, instr_prev);
6945
    }
6946
    int line = _PyCode_LineNumberFromArray(frame->f_code, _PyInterpreterFrame_LASTI(frame));
6947
    PyFrameObject *f = _PyFrame_GetFrameObject(frame);
6948
    if (f == NULL) {
  Branch (6948:9): [True: 0, False: 5.88M]
6949
        return -1;
6950
    }
6951
    if (line != -1 && 
f->f_trace_lines5.87M
) {
  Branch (6951:9): [True: 5.87M, False: 3.61k]
  Branch (6951:23): [True: 5.87M, False: 1.27k]
6952
        /* Trace backward edges (except in 'yield from') or if line number has changed */
6953
        int trace = line != lastline ||
  Branch (6953:21): [True: 1.27M, False: 4.60M]
6954
            
(4.60M
_PyInterpreterFrame_LASTI4.60M
(frame) < instr_prev4.60M
&&
  Branch (6954:14): [True: 3.24k, False: 4.60M]
6955
             // SEND has no quickened forms, so no need to use _PyOpcode_Deopt
6956
             // here:
6957
             
_Py_OPCODE3.24k
(*frame->prev_instr) != 3.24k
SEND3.24k
);
  Branch (6957:14): [True: 2.87k, False: 370]
6958
        if (trace) {
  Branch (6958:13): [True: 1.27M, False: 4.60M]
6959
            result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None);
6960
        }
6961
    }
6962
    /* Always emit an opcode event if we're tracing all opcodes. */
6963
    if (f->f_trace_opcodes) {
  Branch (6963:9): [True: 1.38k, False: 5.87M]
6964
        result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None);
6965
    }
6966
    return result;
6967
}
6968
6969
int
6970
_PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
6971
{
6972
    assert(is_tstate_valid(tstate));
6973
    /* The caller must hold the GIL */
6974
    assert(PyGILState_Check());
6975
6976
    static int reentrant = 0;
6977
    if (reentrant) {
  Branch (6977:9): [True: 2, False: 147]
6978
        _PyErr_SetString(tstate, PyExc_RuntimeError, "Cannot install a profile function "
6979
                         "while another profile function is being installed");
6980
        reentrant = 0;
6981
        return -1;
6982
    }
6983
    reentrant = 1;
6984
6985
    /* Call _PySys_Audit() in the context of the current thread state,
6986
       even if tstate is not the current thread state. */
6987
    PyThreadState *current_tstate = _PyThreadState_GET();
6988
    if (_PySys_Audit(current_tstate, "sys.setprofile", NULL) < 0) {
  Branch (6988:9): [True: 0, False: 147]
6989
        reentrant = 0;
6990
        return -1;
6991
    }
6992
6993
    PyObject *profileobj = tstate->c_profileobj;
6994
6995
    tstate->c_profilefunc = NULL;
6996
    tstate->c_profileobj = NULL;
6997
    /* Must make sure that tracing is not ignored if 'profileobj' is freed */
6998
    _PyThreadState_UpdateTracingState(tstate);
6999
    Py_XDECREF(profileobj);
7000
7001
    Py_XINCREF(arg);
7002
    tstate->c_profileobj = arg;
7003
    tstate->c_profilefunc = func;
7004
7005
    /* Flag that tracing or profiling is turned on */
7006
    _PyThreadState_UpdateTracingState(tstate);
7007
    reentrant = 0;
7008
    return 0;
7009
}
7010
7011
void
7012
PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
7013
{
7014
    PyThreadState *tstate = _PyThreadState_GET();
7015
    if (_PyEval_SetProfile(tstate, func, arg) < 0) {
  Branch (7015:9): [True: 0, False: 0]
7016
        /* Log _PySys_Audit() error */
7017
        _PyErr_WriteUnraisableMsg("in PyEval_SetProfile", NULL);
7018
    }
7019
}
7020
7021
int
7022
_PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
7023
{
7024
    assert(is_tstate_valid(tstate));
7025
    /* The caller must hold the GIL */
7026
    assert(PyGILState_Check());
7027
7028
    static int reentrant = 0;
7029
7030
    if (reentrant) {
  Branch (7030:9): [True: 1, False: 11.1k]
7031
        _PyErr_SetString(tstate, PyExc_RuntimeError, "Cannot install a trace function "
7032
                         "while another trace function is being installed");
7033
        reentrant = 0;
7034
        return -1;
7035
    }
7036
    reentrant = 1;
7037
7038
    /* Call _PySys_Audit() in the context of the current thread state,
7039
       even if tstate is not the current thread state. */
7040
    PyThreadState *current_tstate = _PyThreadState_GET();
7041
    if (_PySys_Audit(current_tstate, "sys.settrace", NULL) < 0) {
  Branch (7041:9): [True: 0, False: 11.1k]
7042
        reentrant = 0;
7043
        return -1;
7044
    }
7045
7046
    PyObject *traceobj = tstate->c_traceobj;
7047
7048
    tstate->c_tracefunc = NULL;
7049
    tstate->c_traceobj = NULL;
7050
    /* Must make sure that profiling is not ignored if 'traceobj' is freed */
7051
    _PyThreadState_UpdateTracingState(tstate);
7052
    Py_XINCREF(arg);
7053
    Py_XDECREF(traceobj);
7054
    tstate->c_traceobj = arg;
7055
    tstate->c_tracefunc = func;
7056
7057
    /* Flag that tracing or profiling is turned on */
7058
    _PyThreadState_UpdateTracingState(tstate);
7059
7060
    reentrant = 0;
7061
    return 0;
7062
}
7063
7064
void
7065
PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
7066
{
7067
    PyThreadState *tstate = _PyThreadState_GET();
7068
    if (_PyEval_SetTrace(tstate, func, arg) < 0) {
  Branch (7068:9): [True: 0, False: 3]
7069
        /* Log _PySys_Audit() error */
7070
        _PyErr_WriteUnraisableMsg("in PyEval_SetTrace", NULL);
7071
    }
7072
}
7073
7074
7075
int
7076
_PyEval_SetCoroutineOriginTrackingDepth(int depth)
7077
{
7078
    PyThreadState *tstate = _PyThreadState_GET();
7079
    if (depth < 0) {
  Branch (7079:9): [True: 1, False: 2.45k]
7080
        _PyErr_SetString(tstate, PyExc_ValueError, "depth must be >= 0");
7081
        return -1;
7082
    }
7083
    tstate->coroutine_origin_tracking_depth = depth;
7084
    return 0;
7085
}
7086
7087
7088
int
7089
_PyEval_GetCoroutineOriginTrackingDepth(void)
7090
{
7091
    PyThreadState *tstate = _PyThreadState_GET();
7092
    return tstate->coroutine_origin_tracking_depth;
7093
}
7094
7095
int
7096
_PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
7097
{
7098
    PyThreadState *tstate = _PyThreadState_GET();
7099
7100
    if (_PySys_Audit(tstate, "sys.set_asyncgen_hook_firstiter", NULL) < 0) {
  Branch (7100:9): [True: 0, False: 10.3k]
7101
        return -1;
7102
    }
7103
7104
    Py_XINCREF(firstiter);
7105
    Py_XSETREF(tstate->async_gen_firstiter, firstiter);
7106
    return 0;
7107
}
7108
7109
PyObject *
7110
_PyEval_GetAsyncGenFirstiter(void)
7111
{
7112
    PyThreadState *tstate = _PyThreadState_GET();
7113
    return tstate->async_gen_firstiter;
7114
}
7115
7116
int
7117
_PyEval_SetAsyncGenFinalizer(PyObject *finalizer)
7118
{
7119
    PyThreadState *tstate = _PyThreadState_GET();
7120
7121
    if (_PySys_Audit(tstate, "sys.set_asyncgen_hook_finalizer", NULL) < 0) {
  Branch (7121:9): [True: 0, False: 10.3k]
7122
        return -1;
7123
    }
7124
7125
    Py_XINCREF(finalizer);
7126
    Py_XSETREF(tstate->async_gen_finalizer, finalizer);
7127
    return 0;
7128
}
7129
7130
PyObject *
7131
_PyEval_GetAsyncGenFinalizer(void)
7132
{
7133
    PyThreadState *tstate = _PyThreadState_GET();
7134
    return tstate->async_gen_finalizer;
7135
}
7136
7137
_PyInterpreterFrame *
7138
_PyEval_GetFrame(void)
7139
{
7140
    PyThreadState *tstate = _PyThreadState_GET();
7141
    return tstate->cframe->current_frame;
7142
}
7143
7144
PyFrameObject *
7145
PyEval_GetFrame(void)
7146
{
7147
    PyThreadState *tstate = _PyThreadState_GET();
7148
    if (tstate->cframe->current_frame == NULL) {
  Branch (7148:9): [True: 0, False: 0]
7149
        return NULL;
7150
    }
7151
    PyFrameObject *f = _PyFrame_GetFrameObject(tstate->cframe->current_frame);
7152
    if (f == NULL) {
  Branch (7152:9): [True: 0, False: 0]
7153
        PyErr_Clear();
7154
    }
7155
    return f;
7156
}
7157
7158
PyObject *
7159
_PyEval_GetBuiltins(PyThreadState *tstate)
7160
{
7161
    _PyInterpreterFrame *frame = tstate->cframe->current_frame;
7162
    if (frame != NULL) {
  Branch (7162:9): [True: 39.9k, False: 557]
7163
        return frame->f_builtins;
7164
    }
7165
    return tstate->interp->builtins;
7166
}
7167
7168
PyObject *
7169
PyEval_GetBuiltins(void)
7170
{
7171
    PyThreadState *tstate = _PyThreadState_GET();
7172
    return _PyEval_GetBuiltins(tstate);
7173
}
7174
7175
/* Convenience function to get a builtin from its name */
7176
PyObject *
7177
_PyEval_GetBuiltin(PyObject *name)
7178
{
7179
    PyThreadState *tstate = _PyThreadState_GET();
7180
    PyObject *attr = PyDict_GetItemWithError(PyEval_GetBuiltins(), name);
7181
    if (attr) {
  Branch (7181:9): [True: 3.54k, False: 0]
7182
        Py_INCREF(attr);
7183
    }
7184
    else if (!_PyErr_Occurred(tstate)) {
  Branch (7184:14): [True: 0, False: 0]
7185
        _PyErr_SetObject(tstate, PyExc_AttributeError, name);
7186
    }
7187
    return attr;
7188
}
7189
7190
PyObject *
7191
_PyEval_GetBuiltinId(_Py_Identifier *name)
7192
{
7193
    return _PyEval_GetBuiltin(_PyUnicode_FromId(name));
7194
}
7195
7196
PyObject *
7197
PyEval_GetLocals(void)
7198
{
7199
    PyThreadState *tstate = _PyThreadState_GET();
7200
     _PyInterpreterFrame *current_frame = tstate->cframe->current_frame;
7201
    if (current_frame == NULL) {
  Branch (7201:9): [True: 0, False: 12.1k]
7202
        _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist");
7203
        return NULL;
7204
    }
7205
7206
    if (_PyFrame_FastToLocalsWithError(current_frame) < 0) {
  Branch (7206:9): [True: 0, False: 12.1k]
7207
        return NULL;
7208
    }
7209
7210
    PyObject *locals = current_frame->f_locals;
7211
    assert(locals != NULL);
7212
    return locals;
7213
}
7214
7215
PyObject *
7216
PyEval_GetGlobals(void)
7217
{
7218
    PyThreadState *tstate = _PyThreadState_GET();
7219
    _PyInterpreterFrame *current_frame = tstate->cframe->current_frame;
7220
    if (current_frame == NULL) {
  Branch (7220:9): [True: 2.07k, False: 376k]
7221
        return NULL;
7222
    }
7223
    return current_frame->f_globals;
7224
}
7225
7226
int
7227
PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
7228
{
7229
    PyThreadState *tstate = _PyThreadState_GET();
7230
    _PyInterpreterFrame *current_frame = tstate->cframe->current_frame;
7231
    int result = cf->cf_flags != 0;
7232
7233
    if (current_frame != NULL) {
  Branch (7233:9): [True: 53.5k, False: 0]
7234
        const int codeflags = current_frame->f_code->co_flags;
7235
        const int compilerflags = codeflags & PyCF_MASK;
7236
        if (compilerflags) {
  Branch (7236:13): [True: 0, False: 53.5k]
7237
            result = 1;
7238
            cf->cf_flags |= compilerflags;
7239
        }
7240
    }
7241
    return result;
7242
}
7243
7244
7245
const char *
7246
PyEval_GetFuncName(PyObject *func)
7247
{
7248
    if (PyMethod_Check(func))
7249
        return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));
7250
    else if (PyFunction_Check(func))
7251
        return PyUnicode_AsUTF8(((PyFunctionObject*)func)->func_name);
7252
    else if (PyCFunction_Check(func))
7253
        return ((PyCFunctionObject*)func)->m_ml->ml_name;
7254
    else
7255
        return Py_TYPE(func)->tp_name;
7256
}
7257
7258
const char *
7259
PyEval_GetFuncDesc(PyObject *func)
7260
{
7261
    if (PyMethod_Check(func))
7262
        return "()";
7263
    else if (PyFunction_Check(func))
7264
        return "()";
7265
    else if (PyCFunction_Check(func))
7266
        return "()";
7267
    else
7268
        return " object";
7269
}
7270
7271
#define C_TRACE(x, call) \
7272
if (use_tracing && 
tstate->c_profilefunc1.85M
) { \
7273
    if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, \
7274
        tstate, tstate->cframe->current_frame, \
7275
        PyTrace_C_CALL, func)) { \
7276
        x = NULL; \
7277
    } \
7278
    else { \
7279
        x = call; \
7280
        if (tstate->c_profilefunc != NULL) { \
7281
            if (x == NULL) { \
7282
                call_trace_protected(tstate->c_profilefunc, \
7283
                    tstate->c_profileobj, \
7284
                    tstate, tstate->cframe->current_frame, \
7285
                    PyTrace_C_EXCEPTION, func); \
7286
                /* XXX should pass (type, value, tb) */ \
7287
            } else { \
7288
                if (call_trace(tstate->c_profilefunc, \
7289
                    tstate->c_profileobj, \
7290
                    tstate, tstate->cframe->current_frame, \
7291
                    PyTrace_C_RETURN, func)) { \
7292
                    Py_DECREF(x); \
7293
                    x = NULL; \
7294
                } \
7295
            } \
7296
        } \
7297
    } \
7298
} else { \
7299
    x = call; \
7300
    }
7301
7302
7303
static PyObject *
7304
trace_call_function(PyThreadState *tstate,
7305
                    PyObject *func,
7306
                    PyObject **args, Py_ssize_t nargs,
7307
                    PyObject *kwnames)
7308
{
7309
    int use_tracing = 1;
7310
    PyObject *x;
7311
    if (PyCFunction_CheckExact(func) || 
PyCMethod_CheckExact1.15M
(func)) {
7312
        C_TRACE(x, PyObject_Vectorcall(func, args, nargs, kwnames));
7313
        return x;
7314
    }
7315
    else if (Py_IS_TYPE(func, &PyMethodDescr_Type) && 
nargs > 01.07M
) {
  Branch (7315:55): [True: 1.07M, False: 1]
7316
        /* We need to create a temporary bound method as argument
7317
           for profiling.
7318
7319
           If nargs == 0, then this cannot work because we have no
7320
           "self". In any case, the call itself would raise
7321
           TypeError (foo needs an argument), so we just skip
7322
           profiling. */
7323
        PyObject *self = args[0];
7324
        func = Py_TYPE(func)->tp_descr_get(func, self, (PyObject*)Py_TYPE(self));
7325
        if (func == NULL) {
  Branch (7325:13): [True: 1, False: 1.07M]
7326
            return NULL;
7327
        }
7328
        C_TRACE(x, PyObject_Vectorcall(func,
7329
                                        args+1, nargs-1,
7330
                                        kwnames));
7331
        Py_DECREF(func);
7332
        return x;
7333
    }
7334
    return PyObject_Vectorcall(func, args, nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
7335
}
7336
7337
static PyObject *
7338
do_call_core(PyThreadState *tstate,
7339
             PyObject *func,
7340
             PyObject *callargs,
7341
             PyObject *kwdict,
7342
             int use_tracing
7343
            )
7344
{
7345
    PyObject *result;
7346
    if (PyCFunction_CheckExact(func) || 
PyCMethod_CheckExact6.98M
(func)) {
7347
        C_TRACE(result, PyObject_Call(func, callargs, kwdict));
7348
        return result;
7349
    }
7350
    else if (Py_IS_TYPE(func, &PyMethodDescr_Type)) {
7351
        Py_ssize_t nargs = PyTuple_GET_SIZE(callargs);
7352
        if (nargs > 0 && 
use_tracing302
) {
  Branch (7352:13): [True: 302, False: 9]
  Branch (7352:26): [True: 2, False: 300]
7353
            /* We need to create a temporary bound method as argument
7354
               for profiling.
7355
7356
               If nargs == 0, then this cannot work because we have no
7357
               "self". In any case, the call itself would raise
7358
               TypeError (foo needs an argument), so we just skip
7359
               profiling. */
7360
            PyObject *self = PyTuple_GET_ITEM(callargs, 0);
7361
            func = Py_TYPE(func)->tp_descr_get(func, self, (PyObject*)Py_TYPE(self));
7362
            if (func == NULL) {
  Branch (7362:17): [True: 1, False: 1]
7363
                return NULL;
7364
            }
7365
7366
            C_TRACE(result, _PyObject_FastCallDictTstate(
7367
                                    tstate, func,
7368
                                    &_PyTuple_ITEMS(callargs)[1],
7369
                                    nargs - 1,
7370
                                    kwdict));
7371
            Py_DECREF(func);
7372
            return result;
7373
        }
7374
    }
7375
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
7376
    return PyObject_Call(func, callargs, kwdict);
7377
}
7378
7379
/* Extract a slice index from a PyLong or an object with the
7380
   nb_index slot defined, and store in *pi.
7381
   Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
7382
   and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN.
7383
   Return 0 on error, 1 on success.
7384
*/
7385
int
7386
_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
7387
{
7388
    PyThreadState *tstate = _PyThreadState_GET();
7389
    if (!Py_IsNone(v)) {
  Branch (7389:9): [True: 16.4M, False: 0]
7390
        Py_ssize_t x;
7391
        if (_PyIndex_Check(v)) {
  Branch (7391:13): [True: 16.4M, False: 1]
7392
            x = PyNumber_AsSsize_t(v, NULL);
7393
            if (x == -1 && 
_PyErr_Occurred(tstate)529k
)
  Branch (7393:17): [True: 529k, False: 15.9M]
  Branch (7393:28): [True: 12, False: 529k]
7394
                return 0;
7395
        }
7396
        else {
7397
            _PyErr_SetString(tstate, PyExc_TypeError,
7398
                             "slice indices must be integers or "
7399
                             "None or have an __index__ method");
7400
            return 0;
7401
        }
7402
        *pi = x;
7403
    }
7404
    return 1;
7405
}
7406
7407
int
7408
_PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi)
7409
{
7410
    PyThreadState *tstate = _PyThreadState_GET();
7411
    Py_ssize_t x;
7412
    if (_PyIndex_Check(v)) {
  Branch (7412:9): [True: 272k, False: 0]
7413
        x = PyNumber_AsSsize_t(v, NULL);
7414
        if (x == -1 && 
_PyErr_Occurred(tstate)3.49k
)
  Branch (7414:13): [True: 3.49k, False: 269k]
  Branch (7414:24): [True: 0, False: 3.49k]
7415
            return 0;
7416
    }
7417
    else {
7418
        _PyErr_SetString(tstate, PyExc_TypeError,
7419
                         "slice indices must be integers or "
7420
                         "have an __index__ method");
7421
        return 0;
7422
    }
7423
    *pi = x;
7424
    return 1;
7425
}
7426
7427
static PyObject *
7428
import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
7429
            PyObject *name, PyObject *fromlist, PyObject *level)
7430
{
7431
    PyObject *import_func, *res;
7432
    PyObject* stack[5];
7433
7434
    import_func = _PyDict_GetItemWithError(frame->f_builtins, &_Py_ID(__import__));
7435
    if (import_func == NULL) {
  Branch (7435:9): [True: 0, False: 258k]
7436
        if (!_PyErr_Occurred(tstate)) {
  Branch (7436:13): [True: 0, False: 0]
7437
            _PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
7438
        }
7439
        return NULL;
7440
    }
7441
    PyObject *locals = frame->f_locals;
7442
    /* Fast path for not overloaded __import__. */
7443
    if (import_func == tstate->interp->import_func) {
  Branch (7443:9): [True: 258k, False: 2]
7444
        int ilevel = _PyLong_AsInt(level);
7445
        if (ilevel == -1 && 
_PyErr_Occurred(tstate)0
) {
  Branch (7445:13): [True: 0, False: 258k]
  Branch (7445:29): [True: 0, False: 0]
7446
            return NULL;
7447
        }
7448
        res = PyImport_ImportModuleLevelObject(
7449
                        name,
7450
                        frame->f_globals,
7451
                        locals == NULL ? 
Py_None221k
:
locals37.6k
,
  Branch (7451:25): [True: 221k, False: 37.6k]
7452
                        fromlist,
7453
                        ilevel);
7454
        return res;
7455
    }
7456
7457
    Py_INCREF(import_func);
7458
7459
    stack[0] = name;
7460
    stack[1] = frame->f_globals;
7461
    stack[2] = locals == NULL ? Py_None : 
locals0
;
  Branch (7461:16): [True: 2, False: 0]
7462
    stack[3] = fromlist;
7463
    stack[4] = level;
7464
    res = _PyObject_FastCall(import_func, stack, 5);
7465
    Py_DECREF(import_func);
7466
    return res;
7467
}
7468
7469
static PyObject *
7470
import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
7471
{
7472
    PyObject *x;
7473
    PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
7474
7475
    if (_PyObject_LookupAttr(v, name, &x) != 0) {
  Branch (7475:9): [True: 91.4k, False: 364]
7476
        return x;
7477
    }
7478
    /* Issue #17636: in case this failed because of a circular relative
7479
       import, try to fallback on reading the module directly from
7480
       sys.modules. */
7481
    pkgname = PyObject_GetAttr(v, &_Py_ID(__name__));
7482
    if (pkgname == NULL) {
  Branch (7482:9): [True: 1, False: 363]
7483
        goto error;
7484
    }
7485
    if (!PyUnicode_Check(pkgname)) {
  Branch (7485:9): [True: 1, False: 362]
7486
        Py_CLEAR(pkgname);
7487
        goto error;
7488
    }
7489
    fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name);
7490
    if (fullmodname == NULL) {
  Branch (7490:9): [True: 0, False: 362]
7491
        Py_DECREF(pkgname);
7492
        return NULL;
7493
    }
7494
    x = PyImport_GetModule(fullmodname);
7495
    Py_DECREF(fullmodname);
7496
    if (x == NULL && 
!_PyErr_Occurred(tstate)323
) {
  Branch (7496:9): [True: 323, False: 39]
  Branch (7496:22): [True: 323, False: 0]
7497
        goto error;
7498
    }
7499
    Py_DECREF(pkgname);
7500
    return x;
7501
 error:
7502
    pkgpath = PyModule_GetFilenameObject(v);
7503
    if (pkgname == NULL) {
  Branch (7503:9): [True: 2, False: 323]
7504
        pkgname_or_unknown = PyUnicode_FromString("<unknown module name>");
7505
        if (pkgname_or_unknown == NULL) {
  Branch (7505:13): [True: 0, False: 2]
7506
            Py_XDECREF(pkgpath);
7507
            return NULL;
7508
        }
7509
    } else {
7510
        pkgname_or_unknown = pkgname;
7511
    }
7512
7513
    if (pkgpath == NULL || 
!45
PyUnicode_Check45
(pkgpath)) {
  Branch (7513:9): [True: 280, False: 45]
  Branch (7513:28): [True: 0, False: 45]
7514
        _PyErr_Clear(tstate);
7515
        errmsg = PyUnicode_FromFormat(
7516
            "cannot import name %R from %R (unknown location)",
7517
            name, pkgname_or_unknown
7518
        );
7519
        /* NULL checks for errmsg and pkgname done by PyErr_SetImportError. */
7520
        PyErr_SetImportError(errmsg, pkgname, NULL);
7521
    }
7522
    else {
7523
        PyObject *spec = PyObject_GetAttr(v, &_Py_ID(__spec__));
7524
        const char *fmt =
7525
            _PyModuleSpec_IsInitializing(spec) ?
  Branch (7525:13): [True: 2, False: 43]
7526
            "cannot import name %R from partially initialized module %R "
7527
            "(most likely due to a circular import) (%S)" :
7528
            
"cannot import name %R from %R (%S)"43
;
7529
        Py_XDECREF(spec);
7530
7531
        errmsg = PyUnicode_FromFormat(fmt, name, pkgname_or_unknown, pkgpath);
7532
        /* NULL checks for errmsg and pkgname done by PyErr_SetImportError. */
7533
        PyErr_SetImportError(errmsg, pkgname, pkgpath);
7534
    }
7535
7536
    Py_XDECREF(errmsg);
7537
    Py_XDECREF(pkgname_or_unknown);
7538
    Py_XDECREF(pkgpath);
7539
    return NULL;
7540
}
7541
7542
static int
7543
import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
7544
{
7545
    PyObject *all, *dict, *name, *value;
7546
    int skip_leading_underscores = 0;
7547
    int pos, err;
7548
7549
    if (_PyObject_LookupAttr(v, &_Py_ID(__all__), &all) < 0) {
  Branch (7549:9): [True: 0, False: 1.87k]
7550
        return -1; /* Unexpected error */
7551
    }
7552
    if (all == NULL) {
  Branch (7552:9): [True: 1.20k, False: 672]
7553
        if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) {
  Branch (7553:13): [True: 0, False: 1.20k]
7554
            return -1;
7555
        }
7556
        if (dict == NULL) {
  Branch (7556:13): [True: 0, False: 1.20k]
7557
            _PyErr_SetString(tstate, PyExc_ImportError,
7558
                    "from-import-* object has no __dict__ and no __all__");
7559
            return -1;
7560
        }
7561
        all = PyMapping_Keys(dict);
7562
        Py_DECREF(dict);
7563
        if (all == NULL)
  Branch (7563:13): [True: 0, False: 1.20k]
7564
            return -1;
7565
        skip_leading_underscores = 1;
7566
    }
7567
7568
    
for (pos = 0, err = 0; ; 1.87k
pos++167k
) {
7569
        name = PySequence_GetItem(all, pos);
7570
        if (name == NULL) {
  Branch (7570:13): [True: 1.87k, False: 167k]
7571
            if (!_PyErr_ExceptionMatches(tstate, PyExc_IndexError)) {
  Branch (7571:17): [True: 0, False: 1.87k]
7572
                err = -1;
7573
            }
7574
            else {
7575
                _PyErr_Clear(tstate);
7576
            }
7577
            break;
7578
        }
7579
        if (!PyUnicode_Check(name)) {
  Branch (7579:13): [True: 2, False: 167k]
7580
            PyObject *modname = PyObject_GetAttr(v, &_Py_ID(__name__));
7581
            if (modname == NULL) {
  Branch (7581:17): [True: 0, False: 2]
7582
                Py_DECREF(name);
7583
                err = -1;
7584
                break;
7585
            }
7586
            if (!PyUnicode_Check(modname)) {
  Branch (7586:17): [True: 0, False: 2]
7587
                _PyErr_Format(tstate, PyExc_TypeError,
7588
                              "module __name__ must be a string, not %.100s",
7589
                              Py_TYPE(modname)->tp_name);
7590
            }
7591
            else {
7592
                _PyErr_Format(tstate, PyExc_TypeError,
7593
                              "%s in %U.%s must be str, not %.100s",
7594
                              skip_leading_underscores ? 
"Key"1
:
"Item"1
,
  Branch (7594:31): [True: 1, False: 1]
7595
                              modname,
7596
                              skip_leading_underscores ? 
"__dict__"1
:
"__all__"1
,
  Branch (7596:31): [True: 1, False: 1]
7597
                              Py_TYPE(name)->tp_name);
7598
            }
7599
            Py_DECREF(modname);
7600
            Py_DECREF(name);
7601
            err = -1;
7602
            break;
7603
        }
7604
        if (skip_leading_underscores) {
  Branch (7604:13): [True: 151k, False: 15.9k]
7605
            if (PyUnicode_READY(name) == -1) {
  Branch (7605:17): [True: 0, False: 151k]
7606
                Py_DECREF(name);
7607
                err = -1;
7608
                break;
7609
            }
7610
            if (PyUnicode_READ_CHAR(name, 0) == '_') {
  Branch (7610:17): [True: 9.30k, False: 142k]
7611
                Py_DECREF(name);
7612
                continue;
7613
            }
7614
        }
7615
        value = PyObject_GetAttr(v, name);
7616
        if (value == NULL)
  Branch (7616:13): [True: 0, False: 158k]
7617
            err = -1;
7618
        else if (PyDict_CheckExact(locals))
7619
            err = PyDict_SetItem(locals, name, value);
7620
        else
7621
            err = PyObject_SetItem(locals, name, value);
7622
        Py_DECREF(name);
7623
        Py_XDECREF(value);
7624
        if (err != 0)
  Branch (7624:13): [True: 0, False: 158k]
7625
            break;
7626
    }
7627
    Py_DECREF(all);
7628
    return err;
7629
}
7630
7631
#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\
7632
                         "BaseException is not allowed"
7633
7634
#define CANNOT_EXCEPT_STAR_EG "catching ExceptionGroup with except* "\
7635
                              "is not allowed. Use except instead."
7636
7637
static int
7638
check_except_type_valid(PyThreadState *tstate, PyObject* right)
7639
{
7640
    if (PyTuple_Check(right)) {
7641
        Py_ssize_t i, length;
7642
        length = PyTuple_GET_SIZE(right);
7643
        for (i = 0; i < length; 
i++287k
) {
  Branch (7643:21): [True: 287k, False: 142k]
7644
            PyObject *exc = PyTuple_GET_ITEM(right, i);
7645
            if (!PyExceptionClass_Check(exc)) {
7646
                _PyErr_SetString(tstate, PyExc_TypeError,
7647
                    CANNOT_CATCH_MSG);
7648
                return -1;
7649
            }
7650
        }
7651
    }
7652
    else {
7653
        if (!PyExceptionClass_Check(right)) {
7654
            _PyErr_SetString(tstate, PyExc_TypeError,
7655
                CANNOT_CATCH_MSG);
7656
            return -1;
7657
        }
7658
    }
7659
    return 0;
7660
}
7661
7662
static int
7663
check_except_star_type_valid(PyThreadState *tstate, PyObject* right)
7664
{
7665
    if (check_except_type_valid(tstate, right) < 0) {
  Branch (7665:9): [True: 2, False: 177]
7666
        return -1;
7667
    }
7668
7669
    /* reject except *ExceptionGroup */
7670
7671
    int is_subclass = 0;
7672
    if (PyTuple_Check(right)) {
7673
        Py_ssize_t length = PyTuple_GET_SIZE(right);
7674
        for (Py_ssize_t i = 0; i < length; 
i++27
) {
  Branch (7674:32): [True: 28, False: 12]
7675
            PyObject *exc = PyTuple_GET_ITEM(right, i);
7676
            is_subclass = PyObject_IsSubclass(exc, PyExc_BaseExceptionGroup);
7677
            if (is_subclass < 0) {
  Branch (7677:17): [True: 0, False: 28]
7678
                return -1;
7679
            }
7680
            if (is_subclass) {
  Branch (7680:17): [True: 1, False: 27]
7681
                break;
7682
            }
7683
        }
7684
    }
7685
    else {
7686
        is_subclass = PyObject_IsSubclass(right, PyExc_BaseExceptionGroup);
7687
        if (is_subclass < 0) {
  Branch (7687:13): [True: 0, False: 164]
7688
            return -1;
7689
        }
7690
    }
7691
    if (is_subclass) {
  Branch (7691:9): [True: 2, False: 175]
7692
        _PyErr_SetString(tstate, PyExc_TypeError,
7693
            CANNOT_EXCEPT_STAR_EG);
7694
            return -1;
7695
    }
7696
    return 0;
7697
}
7698
7699
static int
7700
check_args_iterable(PyThreadState *tstate, PyObject *func, PyObject *args)
7701
{
7702
    if (Py_TYPE(args)->tp_iter == NULL && 
!PySequence_Check(args)8
) {
  Branch (7702:9): [True: 8, False: 214k]
  Branch (7702:43): [True: 6, False: 2]
7703
        /* check_args_iterable() may be called with a live exception:
7704
         * clear it to prevent calling _PyObject_FunctionStr() with an
7705
         * exception set. */
7706
        _PyErr_Clear(tstate);
7707
        PyObject *funcstr = _PyObject_FunctionStr(func);
7708
        if (funcstr != NULL) {
  Branch (7708:13): [True: 6, False: 0]
7709
            _PyErr_Format(tstate, PyExc_TypeError,
7710
                          "%U argument after * must be an iterable, not %.200s",
7711
                          funcstr, Py_TYPE(args)->tp_name);
7712
            Py_DECREF(funcstr);
7713
        }
7714
        return -1;
7715
    }
7716
    return 0;
7717
}
7718
7719
static void
7720
format_kwargs_error(PyThreadState *tstate, PyObject *func, PyObject *kwargs)
7721
{
7722
    /* _PyDict_MergeEx raises attribute
7723
     * error (percolated from an attempt
7724
     * to get 'keys' attribute) instead of
7725
     * a type error if its second argument
7726
     * is not a mapping.
7727
     */
7728
    if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
  Branch (7728:9): [True: 9, False: 14]
7729
        _PyErr_Clear(tstate);
7730
        PyObject *funcstr = _PyObject_FunctionStr(func);
7731
        if (funcstr != NULL) {
  Branch (7731:13): [True: 9, False: 0]
7732
            _PyErr_Format(
7733
                tstate, PyExc_TypeError,
7734
                "%U argument after ** must be a mapping, not %.200s",
7735
                funcstr, Py_TYPE(kwargs)->tp_name);
7736
            Py_DECREF(funcstr);
7737
        }
7738
    }
7739
    else if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
  Branch (7739:14): [True: 13, False: 1]
7740
        PyObject *exc, *val, *tb;
7741
        _PyErr_Fetch(tstate, &exc, &val, &tb);
7742
        if (val && PyTuple_Check(val) && PyTuple_GET_SIZE(val) == 1) {
  Branch (7742:13): [True: 13, False: 0]
  Branch (7742:42): [True: 13, False: 0]
7743
            _PyErr_Clear(tstate);
7744
            PyObject *funcstr = _PyObject_FunctionStr(func);
7745
            if (funcstr != NULL) {
  Branch (7745:17): [True: 13, False: 0]
7746
                PyObject *key = PyTuple_GET_ITEM(val, 0);
7747
                _PyErr_Format(
7748
                    tstate, PyExc_TypeError,
7749
                    "%U got multiple values for keyword argument '%S'",
7750
                    funcstr, key);
7751
                Py_DECREF(funcstr);
7752
            }
7753
            Py_XDECREF(exc);
7754
            Py_XDECREF(val);
7755
            Py_XDECREF(tb);
7756
        }
7757
        else {
7758
            _PyErr_Restore(tstate, exc, val, tb);
7759
        }
7760
    }
7761
}
7762
7763
static void
7764
format_exc_check_arg(PyThreadState *tstate, PyObject *exc,
7765
                     const char *format_str, PyObject *obj)
7766
{
7767
    const char *obj_str;
7768
7769
    if (!obj)
  Branch (7769:9): [True: 0, False: 183]
7770
        return;
7771
7772
    obj_str = PyUnicode_AsUTF8(obj);
7773
    if (!obj_str)
  Branch (7773:9): [True: 0, False: 183]
7774
        return;
7775
7776
    _PyErr_Format(tstate, exc, format_str, obj_str);
7777
7778
    if (exc == PyExc_NameError) {
  Branch (7778:9): [True: 174, False: 9]
7779
        // Include the name in the NameError exceptions to offer suggestions later.
7780
        PyObject *type, *value, *traceback;
7781
        PyErr_Fetch(&type, &value, &traceback);
7782
        PyErr_NormalizeException(&type, &value, &traceback);
7783
        if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) {
  Branch (7783:13): [True: 174, False: 0]
7784
            PyNameErrorObject* exc = (PyNameErrorObject*) value;
7785
            if (exc->name == NULL) {
  Branch (7785:17): [True: 174, False: 0]
7786
                // We do not care if this fails because we are going to restore the
7787
                // NameError anyway.
7788
                (void)PyObject_SetAttr(value, &_Py_ID(name), obj);
7789
            }
7790
        }
7791
        PyErr_Restore(type, value, traceback);
7792
    }
7793
}
7794
7795
static void
7796
format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
7797
{
7798
    PyObject *name;
7799
    /* Don't stomp existing exception */
7800
    if (_PyErr_Occurred(tstate))
  Branch (7800:9): [True: 0, False: 8]
7801
        return;
7802
    name = PyTuple_GET_ITEM(co->co_localsplusnames, oparg);
7803
    if (oparg < co->co_nplaincellvars + co->co_nlocals) {
  Branch (7803:9): [True: 3, False: 5]
7804
        format_exc_check_arg(tstate, PyExc_UnboundLocalError,
7805
                             UNBOUNDLOCAL_ERROR_MSG, name);
7806
    } else {
7807
        format_exc_check_arg(tstate, PyExc_NameError,
7808
                             UNBOUNDFREE_ERROR_MSG, name);
7809
    }
7810
}
7811
7812
static void
7813
format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int oparg)
7814
{
7815
    if (type->tp_as_async == NULL || 
type->tp_as_async->am_await == NULL19
) {
  Branch (7815:9): [True: 9, False: 19]
  Branch (7815:38): [True: 14, False: 5]
7816
        if (oparg == 1) {
  Branch (7816:13): [True: 1, False: 22]
7817
            _PyErr_Format(tstate, PyExc_TypeError,
7818
                          "'async with' received an object from __aenter__ "
7819
                          "that does not implement __await__: %.100s",
7820
                          type->tp_name);
7821
        }
7822
        else if (oparg == 2) {
  Branch (7822:18): [True: 5, False: 17]
7823
            _PyErr_Format(tstate, PyExc_TypeError,
7824
                          "'async with' received an object from __aexit__ "
7825
                          "that does not implement __await__: %.100s",
7826
                          type->tp_name);
7827
        }
7828
    }
7829
}
7830
7831
#ifdef Py_STATS
7832
7833
static PyObject *
7834
getarray(uint64_t a[256])
7835
{
7836
    int i;
7837
    PyObject *l = PyList_New(256);
7838
    if (l == NULL) return NULL;
7839
    for (i = 0; i < 256; i++) {
7840
        PyObject *x = PyLong_FromUnsignedLongLong(a[i]);
7841
        if (x == NULL) {
7842
            Py_DECREF(l);
7843
            return NULL;
7844
        }
7845
        PyList_SET_ITEM(l, i, x);
7846
    }
7847
    for (i = 0; i < 256; i++)
7848
        a[i] = 0;
7849
    return l;
7850
}
7851
7852
PyObject *
7853
_Py_GetDXProfile(PyObject *self, PyObject *args)
7854
{
7855
    int i;
7856
    PyObject *l = PyList_New(257);
7857
    if (l == NULL) return NULL;
7858
    for (i = 0; i < 256; i++) {
7859
        PyObject *x = getarray(_py_stats_struct.opcode_stats[i].pair_count);
7860
        if (x == NULL) {
7861
            Py_DECREF(l);
7862
            return NULL;
7863
        }
7864
        PyList_SET_ITEM(l, i, x);
7865
    }
7866
    PyObject *counts = PyList_New(256);
7867
    if (counts == NULL) {
7868
        Py_DECREF(l);
7869
        return NULL;
7870
    }
7871
    for (i = 0; i < 256; i++) {
7872
        PyObject *x = PyLong_FromUnsignedLongLong(
7873
            _py_stats_struct.opcode_stats[i].execution_count);
7874
        if (x == NULL) {
7875
            Py_DECREF(counts);
7876
            Py_DECREF(l);
7877
            return NULL;
7878
        }
7879
        PyList_SET_ITEM(counts, i, x);
7880
    }
7881
    PyList_SET_ITEM(l, 256, counts);
7882
    return l;
7883
}
7884
7885
#endif
7886
7887
Py_ssize_t
7888
_PyEval_RequestCodeExtraIndex(freefunc free)
7889
{
7890
    PyInterpreterState *interp = _PyInterpreterState_GET();
7891
    Py_ssize_t new_index;
7892
7893
    if (interp->co_extra_user_count == MAX_CO_EXTRA_USERS - 1) {
  Branch (7893:9): [True: 0, False: 1]
7894
        return -1;
7895
    }
7896
    new_index = interp->co_extra_user_count++;
7897
    interp->co_extra_freefuncs[new_index] = free;
7898
    return new_index;
7899
}
7900
7901
static void
7902
dtrace_function_entry(_PyInterpreterFrame *frame)
7903
{
7904
    const char *filename;
7905
    const char *funcname;
7906
    int lineno;
7907
7908
    PyCodeObject *code = frame->f_code;
7909
    filename = PyUnicode_AsUTF8(code->co_filename);
7910
    funcname = PyUnicode_AsUTF8(code->co_name);
7911
    lineno = _PyInterpreterFrame_GetLine(frame);
7912
7913
    PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);
7914
}
7915
7916
static void
7917
dtrace_function_return(_PyInterpreterFrame *frame)
7918
{
7919
    const char *filename;
7920
    const char *funcname;
7921
    int lineno;
7922
7923
    PyCodeObject *code = frame->f_code;
7924
    filename = PyUnicode_AsUTF8(code->co_filename);
7925
    funcname = PyUnicode_AsUTF8(code->co_name);
7926
    lineno = _PyInterpreterFrame_GetLine(frame);
7927
7928
    PyDTrace_FUNCTION_RETURN(filename, funcname, lineno);
7929
}
7930
7931
/* DTrace equivalent of maybe_call_line_trace. */
7932
static void
7933
maybe_dtrace_line(_PyInterpreterFrame *frame,
7934
                  PyTraceInfo *trace_info,
7935
                  int instr_prev)
7936
{
7937
    const char *co_filename, *co_name;
7938
7939
    /* If the last instruction executed isn't in the current
7940
       instruction window, reset the window.
7941
    */
7942
    initialize_trace_info(trace_info, frame);
7943
    int lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &trace_info->bounds);
7944
    int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
7945
    int line = _PyCode_CheckLineNumber(addr, &trace_info->bounds);
7946
    if (line != -1) {
  Branch (7946:9): [True: 0, False: 0]
7947
        /* Trace backward edges or first instruction of a new line */
7948
        if (_PyInterpreterFrame_LASTI(frame) < instr_prev ||
  Branch (7948:13): [True: 0, False: 0]
7949
            (line != lastline && addr == trace_info->bounds.ar_start))
  Branch (7949:14): [True: 0, False: 0]
  Branch (7949:34): [True: 0, False: 0]
7950
        {
7951
            co_filename = PyUnicode_AsUTF8(frame->f_code->co_filename);
7952
            if (!co_filename) {
  Branch (7952:17): [True: 0, False: 0]
7953
                co_filename = "?";
7954
            }
7955
            co_name = PyUnicode_AsUTF8(frame->f_code->co_name);
7956
            if (!co_name) {
  Branch (7956:17): [True: 0, False: 0]
7957
                co_name = "?";
7958
            }
7959
            PyDTrace_LINE(co_filename, co_name, line);
7960
        }
7961
    }
7962
}
7963
7964
/* Implement Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() as functions
7965
   for the limited API. */
7966
7967
#undef Py_EnterRecursiveCall
7968
7969
int Py_EnterRecursiveCall(const char *where)
7970
{
7971
    return _Py_EnterRecursiveCall(where);
7972
}
7973
7974
#undef Py_LeaveRecursiveCall
7975
7976
void Py_LeaveRecursiveCall(void)
7977
{
7978
    _Py_LeaveRecursiveCall();
7979
}