From 68b5f08b72e02f62ec787bfbb7aa99bac661daec Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 18 May 2023 10:08:33 +0100 Subject: [PATCH 01/11] GH-104580: Don't cache eval breaker in interpreter (GH-104581) Move eval-breaker to the front of the interpreter state. --- Include/internal/pycore_ceval_state.h | 6 +- Include/internal/pycore_interp.h | 2 +- Python/bytecodes.c | 5 +- Python/ceval.c | 1 - Python/ceval_macros.h | 2 +- Python/generated_cases.c.h | 506 +++++++++++++------------- 6 files changed, 260 insertions(+), 262 deletions(-) diff --git a/Include/internal/pycore_ceval_state.h b/Include/internal/pycore_ceval_state.h index b352801673c40a..95d1fa16ba40dc 100644 --- a/Include/internal/pycore_ceval_state.h +++ b/Include/internal/pycore_ceval_state.h @@ -81,14 +81,14 @@ struct _pending_calls { }; struct _ceval_state { - int recursion_limit; - struct _gil_runtime_state *gil; - int own_gil; /* This single variable consolidates all requests to break out of the fast path in the eval loop. */ _Py_atomic_int eval_breaker; /* Request for dropping the GIL */ _Py_atomic_int gil_drop_request; + int recursion_limit; + struct _gil_runtime_state *gil; + int own_gil; /* The GC is ready to be executed */ _Py_atomic_int gc_scheduled; struct _pending_calls pending; diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index edc076fc04f6c3..04474c1da8855a 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -48,6 +48,7 @@ struct _Py_long_state { */ struct _is { + struct _ceval_state ceval; PyInterpreterState *next; uint64_t monitoring_version; @@ -92,7 +93,6 @@ struct _is { struct _obmalloc_state obmalloc; - struct _ceval_state ceval; struct _gc_runtime_state gc; struct _import_state imports; diff --git a/Python/bytecodes.c b/Python/bytecodes.c index e92c5d8b6f3b16..f71a62e051a34f 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -70,7 +70,6 @@ dummy_func( _PyInterpreterFrame *frame, unsigned char opcode, unsigned int oparg, - _Py_atomic_int * const eval_breaker, _PyCFrame cframe, _Py_CODEUNIT *next_instr, PyObject **stack_pointer, @@ -143,7 +142,7 @@ dummy_func( ERROR_IF(err, error); next_instr--; } - else if (_Py_atomic_load_relaxed_int32(eval_breaker) && oparg < 2) { + else if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) { goto handle_eval_breaker; } } @@ -170,7 +169,7 @@ dummy_func( next_instr = frame->prev_instr; DISPATCH(); } - if (_Py_atomic_load_relaxed_int32(eval_breaker) && oparg < 2) { + if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) { goto handle_eval_breaker; } } diff --git a/Python/ceval.c b/Python/ceval.c index e8534ec6598e2b..df997e1ed283d7 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -652,7 +652,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int // for the big switch below (in combination with the EXTRA_CASES macro). uint8_t opcode; /* Current opcode */ int oparg; /* Current opcode argument, if any */ - _Py_atomic_int * const eval_breaker = &tstate->interp->ceval.eval_breaker; #ifdef LLTRACE int lltrace = 0; #endif diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index e92ff0bd6fba6f..fccf9088cbd131 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -116,7 +116,7 @@ #define CHECK_EVAL_BREAKER() \ _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \ - if (_Py_atomic_load_relaxed_int32(eval_breaker)) { \ + if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker)) { \ goto handle_eval_breaker; \ } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 32fe7bcef42889..055fb5a0611b96 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -8,7 +8,7 @@ } TARGET(RESUME) { - #line 138 "Python/bytecodes.c" + #line 137 "Python/bytecodes.c" assert(tstate->cframe == &cframe); assert(frame == cframe.current_frame); /* Possibly combine this with eval breaker */ @@ -17,7 +17,7 @@ if (err) goto error; next_instr--; } - else if (_Py_atomic_load_relaxed_int32(eval_breaker) && oparg < 2) { + else if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) { goto handle_eval_breaker; } #line 24 "Python/generated_cases.c.h" @@ -25,7 +25,7 @@ } TARGET(INSTRUMENTED_RESUME) { - #line 152 "Python/bytecodes.c" + #line 151 "Python/bytecodes.c" /* Possible performance enhancement: * We need to check the eval breaker anyway, can we * combine the instrument verison check and the eval breaker test? @@ -47,7 +47,7 @@ next_instr = frame->prev_instr; DISPATCH(); } - if (_Py_atomic_load_relaxed_int32(eval_breaker) && oparg < 2) { + if (_Py_atomic_load_relaxed_int32(&tstate->interp->ceval.eval_breaker) && oparg < 2) { goto handle_eval_breaker; } } @@ -57,7 +57,7 @@ TARGET(LOAD_CLOSURE) { PyObject *value; - #line 180 "Python/bytecodes.c" + #line 179 "Python/bytecodes.c" /* We keep LOAD_CLOSURE so that the bytecode stays more readable. */ value = GETLOCAL(oparg); if (value == NULL) goto unbound_local_error; @@ -70,7 +70,7 @@ TARGET(LOAD_FAST_CHECK) { PyObject *value; - #line 187 "Python/bytecodes.c" + #line 186 "Python/bytecodes.c" value = GETLOCAL(oparg); if (value == NULL) goto unbound_local_error; Py_INCREF(value); @@ -82,7 +82,7 @@ TARGET(LOAD_FAST) { PyObject *value; - #line 193 "Python/bytecodes.c" + #line 192 "Python/bytecodes.c" value = GETLOCAL(oparg); assert(value != NULL); Py_INCREF(value); @@ -94,7 +94,7 @@ TARGET(LOAD_FAST_AND_CLEAR) { PyObject *value; - #line 199 "Python/bytecodes.c" + #line 198 "Python/bytecodes.c" value = GETLOCAL(oparg); // do not use SETLOCAL here, it decrefs the old value GETLOCAL(oparg) = NULL; @@ -107,7 +107,7 @@ TARGET(LOAD_CONST) { PREDICTED(LOAD_CONST); PyObject *value; - #line 205 "Python/bytecodes.c" + #line 204 "Python/bytecodes.c" value = GETITEM(frame->f_code->co_consts, oparg); Py_INCREF(value); #line 114 "Python/generated_cases.c.h" @@ -118,7 +118,7 @@ TARGET(STORE_FAST) { PyObject *value = stack_pointer[-1]; - #line 210 "Python/bytecodes.c" + #line 209 "Python/bytecodes.c" SETLOCAL(oparg, value); #line 124 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -130,7 +130,7 @@ PyObject *_tmp_2; { PyObject *value; - #line 193 "Python/bytecodes.c" + #line 192 "Python/bytecodes.c" value = GETLOCAL(oparg); assert(value != NULL); Py_INCREF(value); @@ -140,7 +140,7 @@ oparg = (next_instr++)->op.arg; { PyObject *value; - #line 193 "Python/bytecodes.c" + #line 192 "Python/bytecodes.c" value = GETLOCAL(oparg); assert(value != NULL); Py_INCREF(value); @@ -158,7 +158,7 @@ PyObject *_tmp_2; { PyObject *value; - #line 193 "Python/bytecodes.c" + #line 192 "Python/bytecodes.c" value = GETLOCAL(oparg); assert(value != NULL); Py_INCREF(value); @@ -168,7 +168,7 @@ oparg = (next_instr++)->op.arg; { PyObject *value; - #line 205 "Python/bytecodes.c" + #line 204 "Python/bytecodes.c" value = GETITEM(frame->f_code->co_consts, oparg); Py_INCREF(value); #line 175 "Python/generated_cases.c.h" @@ -184,14 +184,14 @@ PyObject *_tmp_1 = stack_pointer[-1]; { PyObject *value = _tmp_1; - #line 210 "Python/bytecodes.c" + #line 209 "Python/bytecodes.c" SETLOCAL(oparg, value); #line 190 "Python/generated_cases.c.h" } oparg = (next_instr++)->op.arg; { PyObject *value; - #line 193 "Python/bytecodes.c" + #line 192 "Python/bytecodes.c" value = GETLOCAL(oparg); assert(value != NULL); Py_INCREF(value); @@ -207,14 +207,14 @@ PyObject *_tmp_2 = stack_pointer[-2]; { PyObject *value = _tmp_1; - #line 210 "Python/bytecodes.c" + #line 209 "Python/bytecodes.c" SETLOCAL(oparg, value); #line 213 "Python/generated_cases.c.h" } oparg = (next_instr++)->op.arg; { PyObject *value = _tmp_2; - #line 210 "Python/bytecodes.c" + #line 209 "Python/bytecodes.c" SETLOCAL(oparg, value); #line 220 "Python/generated_cases.c.h" } @@ -227,7 +227,7 @@ PyObject *_tmp_2; { PyObject *value; - #line 205 "Python/bytecodes.c" + #line 204 "Python/bytecodes.c" value = GETITEM(frame->f_code->co_consts, oparg); Py_INCREF(value); #line 234 "Python/generated_cases.c.h" @@ -236,7 +236,7 @@ oparg = (next_instr++)->op.arg; { PyObject *value; - #line 193 "Python/bytecodes.c" + #line 192 "Python/bytecodes.c" value = GETLOCAL(oparg); assert(value != NULL); Py_INCREF(value); @@ -251,7 +251,7 @@ TARGET(POP_TOP) { PyObject *value = stack_pointer[-1]; - #line 220 "Python/bytecodes.c" + #line 219 "Python/bytecodes.c" #line 256 "Python/generated_cases.c.h" Py_DECREF(value); STACK_SHRINK(1); @@ -260,7 +260,7 @@ TARGET(PUSH_NULL) { PyObject *res; - #line 224 "Python/bytecodes.c" + #line 223 "Python/bytecodes.c" res = NULL; #line 266 "Python/generated_cases.c.h" STACK_GROW(1); @@ -273,13 +273,13 @@ PyObject *_tmp_2 = stack_pointer[-2]; { PyObject *value = _tmp_1; - #line 220 "Python/bytecodes.c" + #line 219 "Python/bytecodes.c" #line 278 "Python/generated_cases.c.h" Py_DECREF(value); } { PyObject *value = _tmp_2; - #line 220 "Python/bytecodes.c" + #line 219 "Python/bytecodes.c" #line 284 "Python/generated_cases.c.h" Py_DECREF(value); } @@ -290,7 +290,7 @@ TARGET(INSTRUMENTED_END_FOR) { PyObject *value = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; - #line 230 "Python/bytecodes.c" + #line 229 "Python/bytecodes.c" /* Need to create a fake StopIteration error here, * to conform to PEP 380 */ if (PyGen_Check(receiver)) { @@ -310,7 +310,7 @@ TARGET(END_SEND) { PyObject *value = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; - #line 243 "Python/bytecodes.c" + #line 242 "Python/bytecodes.c" Py_DECREF(receiver); #line 316 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -321,7 +321,7 @@ TARGET(INSTRUMENTED_END_SEND) { PyObject *value = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; - #line 247 "Python/bytecodes.c" + #line 246 "Python/bytecodes.c" if (PyGen_Check(receiver) || PyCoro_CheckExact(receiver)) { PyErr_SetObject(PyExc_StopIteration, value); if (monitor_stop_iteration(tstate, frame, next_instr-1)) { @@ -339,11 +339,11 @@ TARGET(UNARY_NEGATIVE) { PyObject *value = stack_pointer[-1]; PyObject *res; - #line 258 "Python/bytecodes.c" + #line 257 "Python/bytecodes.c" res = PyNumber_Negative(value); #line 345 "Python/generated_cases.c.h" Py_DECREF(value); - #line 260 "Python/bytecodes.c" + #line 259 "Python/bytecodes.c" if (res == NULL) goto pop_1_error; #line 349 "Python/generated_cases.c.h" stack_pointer[-1] = res; @@ -353,11 +353,11 @@ TARGET(UNARY_NOT) { PyObject *value = stack_pointer[-1]; PyObject *res; - #line 264 "Python/bytecodes.c" + #line 263 "Python/bytecodes.c" int err = PyObject_IsTrue(value); #line 359 "Python/generated_cases.c.h" Py_DECREF(value); - #line 266 "Python/bytecodes.c" + #line 265 "Python/bytecodes.c" if (err < 0) goto pop_1_error; if (err == 0) { res = Py_True; @@ -373,11 +373,11 @@ TARGET(UNARY_INVERT) { PyObject *value = stack_pointer[-1]; PyObject *res; - #line 276 "Python/bytecodes.c" + #line 275 "Python/bytecodes.c" res = PyNumber_Invert(value); #line 379 "Python/generated_cases.c.h" Py_DECREF(value); - #line 278 "Python/bytecodes.c" + #line 277 "Python/bytecodes.c" if (res == NULL) goto pop_1_error; #line 383 "Python/generated_cases.c.h" stack_pointer[-1] = res; @@ -388,7 +388,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *prod; - #line 295 "Python/bytecodes.c" + #line 294 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP); DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -407,7 +407,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *prod; - #line 305 "Python/bytecodes.c" + #line 304 "Python/bytecodes.c" DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP); DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -425,7 +425,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *sub; - #line 314 "Python/bytecodes.c" + #line 313 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP); DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -444,7 +444,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *sub; - #line 324 "Python/bytecodes.c" + #line 323 "Python/bytecodes.c" DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP); DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -461,7 +461,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 332 "Python/bytecodes.c" + #line 331 "Python/bytecodes.c" DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP); DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -479,7 +479,7 @@ TARGET(BINARY_OP_INPLACE_ADD_UNICODE) { PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; - #line 348 "Python/bytecodes.c" + #line 347 "Python/bytecodes.c" DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP); DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP); _Py_CODEUNIT true_next = next_instr[INLINE_CACHE_ENTRIES_BINARY_OP]; @@ -515,7 +515,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *sum; - #line 377 "Python/bytecodes.c" + #line 376 "Python/bytecodes.c" DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP); DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -533,7 +533,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *sum; - #line 386 "Python/bytecodes.c" + #line 385 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP); DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP); STAT_INC(BINARY_OP, hit); @@ -554,7 +554,7 @@ PyObject *sub = stack_pointer[-1]; PyObject *container = stack_pointer[-2]; PyObject *res; - #line 404 "Python/bytecodes.c" + #line 403 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -569,7 +569,7 @@ #line 570 "Python/generated_cases.c.h" Py_DECREF(container); Py_DECREF(sub); - #line 416 "Python/bytecodes.c" + #line 415 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; #line 575 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -583,7 +583,7 @@ PyObject *start = stack_pointer[-2]; PyObject *container = stack_pointer[-3]; PyObject *res; - #line 420 "Python/bytecodes.c" + #line 419 "Python/bytecodes.c" PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop); // Can't use ERROR_IF() here, because we haven't // DECREF'ed container yet, and we still own slice. @@ -607,7 +607,7 @@ PyObject *start = stack_pointer[-2]; PyObject *container = stack_pointer[-3]; PyObject *v = stack_pointer[-4]; - #line 435 "Python/bytecodes.c" + #line 434 "Python/bytecodes.c" PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop); int err; if (slice == NULL) { @@ -629,7 +629,7 @@ PyObject *sub = stack_pointer[-1]; PyObject *list = stack_pointer[-2]; PyObject *res; - #line 450 "Python/bytecodes.c" + #line 449 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR); DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR); @@ -654,7 +654,7 @@ PyObject *sub = stack_pointer[-1]; PyObject *tuple = stack_pointer[-2]; PyObject *res; - #line 466 "Python/bytecodes.c" + #line 465 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR); DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR); @@ -679,7 +679,7 @@ PyObject *sub = stack_pointer[-1]; PyObject *dict = stack_pointer[-2]; PyObject *res; - #line 482 "Python/bytecodes.c" + #line 481 "Python/bytecodes.c" DEOPT_IF(!PyDict_CheckExact(dict), BINARY_SUBSCR); STAT_INC(BINARY_SUBSCR, hit); res = PyDict_GetItemWithError(dict, sub); @@ -690,7 +690,7 @@ #line 691 "Python/generated_cases.c.h" Py_DECREF(dict); Py_DECREF(sub); - #line 490 "Python/bytecodes.c" + #line 489 "Python/bytecodes.c" if (true) goto pop_2_error; } Py_INCREF(res); // Do this before DECREF'ing dict, sub @@ -706,7 +706,7 @@ TARGET(BINARY_SUBSCR_GETITEM) { PyObject *sub = stack_pointer[-1]; PyObject *container = stack_pointer[-2]; - #line 497 "Python/bytecodes.c" + #line 496 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, BINARY_SUBSCR); PyTypeObject *tp = Py_TYPE(container); DEOPT_IF(!PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE), BINARY_SUBSCR); @@ -735,7 +735,7 @@ TARGET(LIST_APPEND) { PyObject *v = stack_pointer[-1]; PyObject *list = stack_pointer[-(2 + (oparg-1))]; - #line 522 "Python/bytecodes.c" + #line 521 "Python/bytecodes.c" if (_PyList_AppendTakeRef((PyListObject *)list, v) < 0) goto pop_1_error; #line 741 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -746,11 +746,11 @@ TARGET(SET_ADD) { PyObject *v = stack_pointer[-1]; PyObject *set = stack_pointer[-(2 + (oparg-1))]; - #line 527 "Python/bytecodes.c" + #line 526 "Python/bytecodes.c" int err = PySet_Add(set, v); #line 752 "Python/generated_cases.c.h" Py_DECREF(v); - #line 529 "Python/bytecodes.c" + #line 528 "Python/bytecodes.c" if (err) goto pop_1_error; #line 756 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -765,7 +765,7 @@ PyObject *container = stack_pointer[-2]; PyObject *v = stack_pointer[-3]; uint16_t counter = read_u16(&next_instr[0].cache); - #line 540 "Python/bytecodes.c" + #line 539 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION if (ADAPTIVE_COUNTER_IS_ZERO(counter)) { next_instr--; @@ -784,7 +784,7 @@ Py_DECREF(v); Py_DECREF(container); Py_DECREF(sub); - #line 555 "Python/bytecodes.c" + #line 554 "Python/bytecodes.c" if (err) goto pop_3_error; #line 790 "Python/generated_cases.c.h" STACK_SHRINK(3); @@ -796,7 +796,7 @@ PyObject *sub = stack_pointer[-1]; PyObject *list = stack_pointer[-2]; PyObject *value = stack_pointer[-3]; - #line 559 "Python/bytecodes.c" + #line 558 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(sub), STORE_SUBSCR); DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR); @@ -823,7 +823,7 @@ PyObject *sub = stack_pointer[-1]; PyObject *dict = stack_pointer[-2]; PyObject *value = stack_pointer[-3]; - #line 578 "Python/bytecodes.c" + #line 577 "Python/bytecodes.c" DEOPT_IF(!PyDict_CheckExact(dict), STORE_SUBSCR); STAT_INC(STORE_SUBSCR, hit); int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, value); @@ -838,13 +838,13 @@ TARGET(DELETE_SUBSCR) { PyObject *sub = stack_pointer[-1]; PyObject *container = stack_pointer[-2]; - #line 586 "Python/bytecodes.c" + #line 585 "Python/bytecodes.c" /* del container[sub] */ int err = PyObject_DelItem(container, sub); #line 845 "Python/generated_cases.c.h" Py_DECREF(container); Py_DECREF(sub); - #line 589 "Python/bytecodes.c" + #line 588 "Python/bytecodes.c" if (err) goto pop_2_error; #line 850 "Python/generated_cases.c.h" STACK_SHRINK(2); @@ -854,12 +854,12 @@ TARGET(CALL_INTRINSIC_1) { PyObject *value = stack_pointer[-1]; PyObject *res; - #line 593 "Python/bytecodes.c" + #line 592 "Python/bytecodes.c" assert(oparg <= MAX_INTRINSIC_1); res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value); #line 861 "Python/generated_cases.c.h" Py_DECREF(value); - #line 596 "Python/bytecodes.c" + #line 595 "Python/bytecodes.c" if (res == NULL) goto pop_1_error; #line 865 "Python/generated_cases.c.h" stack_pointer[-1] = res; @@ -870,13 +870,13 @@ PyObject *value1 = stack_pointer[-1]; PyObject *value2 = stack_pointer[-2]; PyObject *res; - #line 600 "Python/bytecodes.c" + #line 599 "Python/bytecodes.c" assert(oparg <= MAX_INTRINSIC_2); res = _PyIntrinsics_BinaryFunctions[oparg](tstate, value2, value1); #line 877 "Python/generated_cases.c.h" Py_DECREF(value2); Py_DECREF(value1); - #line 603 "Python/bytecodes.c" + #line 602 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; #line 882 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -886,7 +886,7 @@ TARGET(RAISE_VARARGS) { PyObject **args = (stack_pointer - oparg); - #line 607 "Python/bytecodes.c" + #line 606 "Python/bytecodes.c" PyObject *cause = NULL, *exc = NULL; switch (oparg) { case 2: @@ -909,7 +909,7 @@ TARGET(INTERPRETER_EXIT) { PyObject *retval = stack_pointer[-1]; - #line 627 "Python/bytecodes.c" + #line 626 "Python/bytecodes.c" assert(frame == &entry_frame); assert(_PyFrame_IsIncomplete(frame)); STACK_SHRINK(1); // Since we're not going to DISPATCH() @@ -925,7 +925,7 @@ TARGET(RETURN_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 640 "Python/bytecodes.c" + #line 639 "Python/bytecodes.c" STACK_SHRINK(1); assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); @@ -943,7 +943,7 @@ TARGET(INSTRUMENTED_RETURN_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 655 "Python/bytecodes.c" + #line 654 "Python/bytecodes.c" int err = _Py_call_instrumentation_arg( tstate, PY_MONITORING_EVENT_PY_RETURN, frame, next_instr-1, retval); @@ -964,7 +964,7 @@ } TARGET(RETURN_CONST) { - #line 674 "Python/bytecodes.c" + #line 673 "Python/bytecodes.c" PyObject *retval = GETITEM(frame->f_code->co_consts, oparg); Py_INCREF(retval); assert(EMPTY()); @@ -982,7 +982,7 @@ } TARGET(INSTRUMENTED_RETURN_CONST) { - #line 690 "Python/bytecodes.c" + #line 689 "Python/bytecodes.c" PyObject *retval = GETITEM(frame->f_code->co_consts, oparg); int err = _Py_call_instrumentation_arg( tstate, PY_MONITORING_EVENT_PY_RETURN, @@ -1006,7 +1006,7 @@ TARGET(GET_AITER) { PyObject *obj = stack_pointer[-1]; PyObject *iter; - #line 710 "Python/bytecodes.c" + #line 709 "Python/bytecodes.c" unaryfunc getter = NULL; PyTypeObject *type = Py_TYPE(obj); @@ -1021,14 +1021,14 @@ type->tp_name); #line 1023 "Python/generated_cases.c.h" Py_DECREF(obj); - #line 723 "Python/bytecodes.c" + #line 722 "Python/bytecodes.c" if (true) goto pop_1_error; } iter = (*getter)(obj); #line 1030 "Python/generated_cases.c.h" Py_DECREF(obj); - #line 728 "Python/bytecodes.c" + #line 727 "Python/bytecodes.c" if (iter == NULL) goto pop_1_error; if (Py_TYPE(iter)->tp_as_async == NULL || @@ -1049,7 +1049,7 @@ TARGET(GET_ANEXT) { PyObject *aiter = stack_pointer[-1]; PyObject *awaitable; - #line 743 "Python/bytecodes.c" + #line 742 "Python/bytecodes.c" unaryfunc getter = NULL; PyObject *next_iter = NULL; PyTypeObject *type = Py_TYPE(aiter); @@ -1104,7 +1104,7 @@ PREDICTED(GET_AWAITABLE); PyObject *iterable = stack_pointer[-1]; PyObject *iter; - #line 790 "Python/bytecodes.c" + #line 789 "Python/bytecodes.c" iter = _PyCoro_GetAwaitableIter(iterable); if (iter == NULL) { @@ -1113,7 +1113,7 @@ #line 1115 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 797 "Python/bytecodes.c" + #line 796 "Python/bytecodes.c" if (iter != NULL && PyCoro_CheckExact(iter)) { PyObject *yf = _PyGen_yf((PyGenObject*)iter); @@ -1143,7 +1143,7 @@ PyObject *v = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; PyObject *retval; - #line 823 "Python/bytecodes.c" + #line 822 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PySendCache *cache = (_PySendCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -1199,7 +1199,7 @@ TARGET(SEND_GEN) { PyObject *v = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; - #line 872 "Python/bytecodes.c" + #line 871 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, SEND); PyGenObject *gen = (PyGenObject *)receiver; DEOPT_IF(Py_TYPE(gen) != &PyGen_Type && @@ -1220,7 +1220,7 @@ TARGET(INSTRUMENTED_YIELD_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 890 "Python/bytecodes.c" + #line 889 "Python/bytecodes.c" assert(frame != &entry_frame); PyGenObject *gen = _PyFrame_GetGenerator(frame); gen->gi_frame_state = FRAME_SUSPENDED; @@ -1242,7 +1242,7 @@ TARGET(YIELD_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 909 "Python/bytecodes.c" + #line 908 "Python/bytecodes.c" // NOTE: It's important that YIELD_VALUE never raises an exception! // The compiler treats any exception raised here as a failed close() // or throw() call. @@ -1263,7 +1263,7 @@ TARGET(POP_EXCEPT) { PyObject *exc_value = stack_pointer[-1]; - #line 927 "Python/bytecodes.c" + #line 926 "Python/bytecodes.c" _PyErr_StackItem *exc_info = tstate->exc_info; Py_XSETREF(exc_info->exc_value, exc_value); #line 1270 "Python/generated_cases.c.h" @@ -1274,7 +1274,7 @@ TARGET(RERAISE) { PyObject *exc = stack_pointer[-1]; PyObject **values = (stack_pointer - (1 + oparg)); - #line 932 "Python/bytecodes.c" + #line 931 "Python/bytecodes.c" assert(oparg >= 0 && oparg <= 2); if (oparg) { PyObject *lasti = values[0]; @@ -1298,13 +1298,13 @@ TARGET(END_ASYNC_FOR) { PyObject *exc = stack_pointer[-1]; PyObject *awaitable = stack_pointer[-2]; - #line 952 "Python/bytecodes.c" + #line 951 "Python/bytecodes.c" assert(exc && PyExceptionInstance_Check(exc)); if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) { #line 1305 "Python/generated_cases.c.h" Py_DECREF(awaitable); Py_DECREF(exc); - #line 955 "Python/bytecodes.c" + #line 954 "Python/bytecodes.c" } else { Py_INCREF(exc); @@ -1322,7 +1322,7 @@ PyObject *sub_iter = stack_pointer[-3]; PyObject *none; PyObject *value; - #line 964 "Python/bytecodes.c" + #line 963 "Python/bytecodes.c" assert(throwflag); assert(exc_value && PyExceptionInstance_Check(exc_value)); if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) { @@ -1331,7 +1331,7 @@ Py_DECREF(sub_iter); Py_DECREF(last_sent_val); Py_DECREF(exc_value); - #line 969 "Python/bytecodes.c" + #line 968 "Python/bytecodes.c" none = Py_None; } else { @@ -1347,7 +1347,7 @@ TARGET(LOAD_ASSERTION_ERROR) { PyObject *value; - #line 978 "Python/bytecodes.c" + #line 977 "Python/bytecodes.c" value = Py_NewRef(PyExc_AssertionError); #line 1353 "Python/generated_cases.c.h" STACK_GROW(1); @@ -1357,7 +1357,7 @@ TARGET(LOAD_BUILD_CLASS) { PyObject *bc; - #line 982 "Python/bytecodes.c" + #line 981 "Python/bytecodes.c" if (PyDict_CheckExact(BUILTINS())) { bc = _PyDict_GetItemWithError(BUILTINS(), &_Py_ID(__build_class__)); @@ -1387,7 +1387,7 @@ TARGET(STORE_NAME) { PyObject *v = stack_pointer[-1]; - #line 1007 "Python/bytecodes.c" + #line 1006 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); PyObject *ns = LOCALS(); int err; @@ -1396,7 +1396,7 @@ "no locals found when storing %R", name); #line 1398 "Python/generated_cases.c.h" Py_DECREF(v); - #line 1014 "Python/bytecodes.c" + #line 1013 "Python/bytecodes.c" if (true) goto pop_1_error; } if (PyDict_CheckExact(ns)) @@ -1405,7 +1405,7 @@ err = PyObject_SetItem(ns, name, v); #line 1407 "Python/generated_cases.c.h" Py_DECREF(v); - #line 1021 "Python/bytecodes.c" + #line 1020 "Python/bytecodes.c" if (err) goto pop_1_error; #line 1411 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -1413,7 +1413,7 @@ } TARGET(DELETE_NAME) { - #line 1025 "Python/bytecodes.c" + #line 1024 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); PyObject *ns = LOCALS(); int err; @@ -1438,7 +1438,7 @@ PREDICTED(UNPACK_SEQUENCE); static_assert(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE == 1, "incorrect cache size"); PyObject *seq = stack_pointer[-1]; - #line 1051 "Python/bytecodes.c" + #line 1050 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -1453,7 +1453,7 @@ int res = unpack_iterable(tstate, seq, oparg, -1, top); #line 1455 "Python/generated_cases.c.h" Py_DECREF(seq); - #line 1064 "Python/bytecodes.c" + #line 1063 "Python/bytecodes.c" if (res == 0) goto pop_1_error; #line 1459 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -1465,7 +1465,7 @@ TARGET(UNPACK_SEQUENCE_TWO_TUPLE) { PyObject *seq = stack_pointer[-1]; PyObject **values = stack_pointer - (1); - #line 1068 "Python/bytecodes.c" + #line 1067 "Python/bytecodes.c" DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE); assert(oparg == 2); @@ -1483,7 +1483,7 @@ TARGET(UNPACK_SEQUENCE_TUPLE) { PyObject *seq = stack_pointer[-1]; PyObject **values = stack_pointer - (1); - #line 1078 "Python/bytecodes.c" + #line 1077 "Python/bytecodes.c" DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyTuple_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE); STAT_INC(UNPACK_SEQUENCE, hit); @@ -1502,7 +1502,7 @@ TARGET(UNPACK_SEQUENCE_LIST) { PyObject *seq = stack_pointer[-1]; PyObject **values = stack_pointer - (1); - #line 1089 "Python/bytecodes.c" + #line 1088 "Python/bytecodes.c" DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE); STAT_INC(UNPACK_SEQUENCE, hit); @@ -1520,13 +1520,13 @@ TARGET(UNPACK_EX) { PyObject *seq = stack_pointer[-1]; - #line 1100 "Python/bytecodes.c" + #line 1099 "Python/bytecodes.c" int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8); PyObject **top = stack_pointer + totalargs - 1; int res = unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top); #line 1528 "Python/generated_cases.c.h" Py_DECREF(seq); - #line 1104 "Python/bytecodes.c" + #line 1103 "Python/bytecodes.c" if (res == 0) goto pop_1_error; #line 1532 "Python/generated_cases.c.h" STACK_GROW((oparg & 0xFF) + (oparg >> 8)); @@ -1539,7 +1539,7 @@ PyObject *owner = stack_pointer[-1]; PyObject *v = stack_pointer[-2]; uint16_t counter = read_u16(&next_instr[0].cache); - #line 1115 "Python/bytecodes.c" + #line 1114 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION if (ADAPTIVE_COUNTER_IS_ZERO(counter)) { PyObject *name = GETITEM(frame->f_code->co_names, oparg); @@ -1558,7 +1558,7 @@ #line 1559 "Python/generated_cases.c.h" Py_DECREF(v); Py_DECREF(owner); - #line 1131 "Python/bytecodes.c" + #line 1130 "Python/bytecodes.c" if (err) goto pop_2_error; #line 1564 "Python/generated_cases.c.h" STACK_SHRINK(2); @@ -1568,12 +1568,12 @@ TARGET(DELETE_ATTR) { PyObject *owner = stack_pointer[-1]; - #line 1135 "Python/bytecodes.c" + #line 1134 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); int err = PyObject_SetAttr(owner, name, (PyObject *)NULL); #line 1575 "Python/generated_cases.c.h" Py_DECREF(owner); - #line 1138 "Python/bytecodes.c" + #line 1137 "Python/bytecodes.c" if (err) goto pop_1_error; #line 1579 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -1582,12 +1582,12 @@ TARGET(STORE_GLOBAL) { PyObject *v = stack_pointer[-1]; - #line 1142 "Python/bytecodes.c" + #line 1141 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); int err = PyDict_SetItem(GLOBALS(), name, v); #line 1589 "Python/generated_cases.c.h" Py_DECREF(v); - #line 1145 "Python/bytecodes.c" + #line 1144 "Python/bytecodes.c" if (err) goto pop_1_error; #line 1593 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -1595,7 +1595,7 @@ } TARGET(DELETE_GLOBAL) { - #line 1149 "Python/bytecodes.c" + #line 1148 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); int err; err = PyDict_DelItem(GLOBALS(), name); @@ -1615,7 +1615,7 @@ PyObject *_tmp_1; { PyObject *locals; - #line 1163 "Python/bytecodes.c" + #line 1162 "Python/bytecodes.c" locals = LOCALS(); if (locals == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, @@ -1635,7 +1635,7 @@ PyObject *_tmp_1; { PyObject *locals; - #line 1163 "Python/bytecodes.c" + #line 1162 "Python/bytecodes.c" locals = LOCALS(); if (locals == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, @@ -1649,7 +1649,7 @@ { PyObject *mod_or_class_dict = _tmp_1; PyObject *v; - #line 1175 "Python/bytecodes.c" + #line 1174 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); if (PyDict_CheckExact(mod_or_class_dict)) { v = PyDict_GetItemWithError(mod_or_class_dict, name); @@ -1719,7 +1719,7 @@ { PyObject *mod_or_class_dict = _tmp_1; PyObject *v; - #line 1175 "Python/bytecodes.c" + #line 1174 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); if (PyDict_CheckExact(mod_or_class_dict)) { v = PyDict_GetItemWithError(mod_or_class_dict, name); @@ -1788,7 +1788,7 @@ static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 4, "incorrect cache size"); PyObject *null = NULL; PyObject *v; - #line 1244 "Python/bytecodes.c" + #line 1243 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -1854,7 +1854,7 @@ PyObject *res; uint16_t index = read_u16(&next_instr[1].cache); uint16_t version = read_u16(&next_instr[2].cache); - #line 1298 "Python/bytecodes.c" + #line 1297 "Python/bytecodes.c" DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL); PyDictObject *dict = (PyDictObject *)GLOBALS(); DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL); @@ -1880,7 +1880,7 @@ uint16_t index = read_u16(&next_instr[1].cache); uint16_t mod_version = read_u16(&next_instr[2].cache); uint16_t bltn_version = read_u16(&next_instr[3].cache); - #line 1311 "Python/bytecodes.c" + #line 1310 "Python/bytecodes.c" DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL); DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL); PyDictObject *mdict = (PyDictObject *)GLOBALS(); @@ -1905,7 +1905,7 @@ } TARGET(DELETE_FAST) { - #line 1328 "Python/bytecodes.c" + #line 1327 "Python/bytecodes.c" PyObject *v = GETLOCAL(oparg); if (v == NULL) goto unbound_local_error; SETLOCAL(oparg, NULL); @@ -1914,7 +1914,7 @@ } TARGET(MAKE_CELL) { - #line 1334 "Python/bytecodes.c" + #line 1333 "Python/bytecodes.c" // "initial" is probably NULL but not if it's an arg (or set // via PyFrame_LocalsToFast() before MAKE_CELL has run). PyObject *initial = GETLOCAL(oparg); @@ -1928,7 +1928,7 @@ } TARGET(DELETE_DEREF) { - #line 1345 "Python/bytecodes.c" + #line 1344 "Python/bytecodes.c" PyObject *cell = GETLOCAL(oparg); PyObject *oldobj = PyCell_GET(cell); // Can't use ERROR_IF here. @@ -1946,7 +1946,7 @@ TARGET(LOAD_FROM_DICT_OR_DEREF) { PyObject *class_dict = stack_pointer[-1]; PyObject *value; - #line 1358 "Python/bytecodes.c" + #line 1357 "Python/bytecodes.c" PyObject *name; assert(class_dict); assert(oparg >= 0 && oparg < frame->f_code->co_nlocalsplus); @@ -1988,7 +1988,7 @@ TARGET(LOAD_DEREF) { PyObject *value; - #line 1395 "Python/bytecodes.c" + #line 1394 "Python/bytecodes.c" PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { @@ -2004,7 +2004,7 @@ TARGET(STORE_DEREF) { PyObject *v = stack_pointer[-1]; - #line 1405 "Python/bytecodes.c" + #line 1404 "Python/bytecodes.c" PyObject *cell = GETLOCAL(oparg); PyObject *oldobj = PyCell_GET(cell); PyCell_SET(cell, v); @@ -2015,7 +2015,7 @@ } TARGET(COPY_FREE_VARS) { - #line 1412 "Python/bytecodes.c" + #line 1411 "Python/bytecodes.c" /* Copy closure variables to free variables */ PyCodeObject *co = frame->f_code; assert(PyFunction_Check(frame->f_funcobj)); @@ -2033,13 +2033,13 @@ TARGET(BUILD_STRING) { PyObject **pieces = (stack_pointer - oparg); PyObject *str; - #line 1425 "Python/bytecodes.c" + #line 1424 "Python/bytecodes.c" str = _PyUnicode_JoinArray(&_Py_STR(empty), pieces, oparg); #line 2039 "Python/generated_cases.c.h" for (int _i = oparg; --_i >= 0;) { Py_DECREF(pieces[_i]); } - #line 1427 "Python/bytecodes.c" + #line 1426 "Python/bytecodes.c" if (str == NULL) { STACK_SHRINK(oparg); goto error; } #line 2045 "Python/generated_cases.c.h" STACK_SHRINK(oparg); @@ -2051,7 +2051,7 @@ TARGET(BUILD_TUPLE) { PyObject **values = (stack_pointer - oparg); PyObject *tup; - #line 1431 "Python/bytecodes.c" + #line 1430 "Python/bytecodes.c" tup = _PyTuple_FromArraySteal(values, oparg); if (tup == NULL) { STACK_SHRINK(oparg); goto error; } #line 2058 "Python/generated_cases.c.h" @@ -2064,7 +2064,7 @@ TARGET(BUILD_LIST) { PyObject **values = (stack_pointer - oparg); PyObject *list; - #line 1436 "Python/bytecodes.c" + #line 1435 "Python/bytecodes.c" list = _PyList_FromArraySteal(values, oparg); if (list == NULL) { STACK_SHRINK(oparg); goto error; } #line 2071 "Python/generated_cases.c.h" @@ -2077,7 +2077,7 @@ TARGET(LIST_EXTEND) { PyObject *iterable = stack_pointer[-1]; PyObject *list = stack_pointer[-(2 + (oparg-1))]; - #line 1441 "Python/bytecodes.c" + #line 1440 "Python/bytecodes.c" PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable); if (none_val == NULL) { if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) && @@ -2090,7 +2090,7 @@ } #line 2092 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 1452 "Python/bytecodes.c" + #line 1451 "Python/bytecodes.c" if (true) goto pop_1_error; } assert(Py_IsNone(none_val)); @@ -2103,11 +2103,11 @@ TARGET(SET_UPDATE) { PyObject *iterable = stack_pointer[-1]; PyObject *set = stack_pointer[-(2 + (oparg-1))]; - #line 1459 "Python/bytecodes.c" + #line 1458 "Python/bytecodes.c" int err = _PySet_Update(set, iterable); #line 2109 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 1461 "Python/bytecodes.c" + #line 1460 "Python/bytecodes.c" if (err < 0) goto pop_1_error; #line 2113 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -2117,7 +2117,7 @@ TARGET(BUILD_SET) { PyObject **values = (stack_pointer - oparg); PyObject *set; - #line 1465 "Python/bytecodes.c" + #line 1464 "Python/bytecodes.c" set = PySet_New(NULL); if (set == NULL) goto error; @@ -2142,7 +2142,7 @@ TARGET(BUILD_MAP) { PyObject **values = (stack_pointer - oparg*2); PyObject *map; - #line 1482 "Python/bytecodes.c" + #line 1481 "Python/bytecodes.c" map = _PyDict_FromItems( values, 2, values+1, 2, @@ -2154,7 +2154,7 @@ for (int _i = oparg*2; --_i >= 0;) { Py_DECREF(values[_i]); } - #line 1490 "Python/bytecodes.c" + #line 1489 "Python/bytecodes.c" if (map == NULL) { STACK_SHRINK(oparg*2); goto error; } #line 2160 "Python/generated_cases.c.h" STACK_SHRINK(oparg*2); @@ -2164,7 +2164,7 @@ } TARGET(SETUP_ANNOTATIONS) { - #line 1494 "Python/bytecodes.c" + #line 1493 "Python/bytecodes.c" int err; PyObject *ann_dict; if (LOCALS() == NULL) { @@ -2212,7 +2212,7 @@ PyObject *keys = stack_pointer[-1]; PyObject **values = (stack_pointer - (1 + oparg)); PyObject *map; - #line 1536 "Python/bytecodes.c" + #line 1535 "Python/bytecodes.c" if (!PyTuple_CheckExact(keys) || PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) { _PyErr_SetString(tstate, PyExc_SystemError, @@ -2227,7 +2227,7 @@ Py_DECREF(values[_i]); } Py_DECREF(keys); - #line 1546 "Python/bytecodes.c" + #line 1545 "Python/bytecodes.c" if (map == NULL) { STACK_SHRINK(oparg); goto pop_1_error; } #line 2233 "Python/generated_cases.c.h" STACK_SHRINK(oparg); @@ -2237,7 +2237,7 @@ TARGET(DICT_UPDATE) { PyObject *update = stack_pointer[-1]; - #line 1550 "Python/bytecodes.c" + #line 1549 "Python/bytecodes.c" PyObject *dict = PEEK(oparg + 1); // update is still on the stack if (PyDict_Update(dict, update) < 0) { if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) { @@ -2247,7 +2247,7 @@ } #line 2249 "Python/generated_cases.c.h" Py_DECREF(update); - #line 1558 "Python/bytecodes.c" + #line 1557 "Python/bytecodes.c" if (true) goto pop_1_error; } #line 2254 "Python/generated_cases.c.h" @@ -2258,14 +2258,14 @@ TARGET(DICT_MERGE) { PyObject *update = stack_pointer[-1]; - #line 1564 "Python/bytecodes.c" + #line 1563 "Python/bytecodes.c" PyObject *dict = PEEK(oparg + 1); // update is still on the stack if (_PyDict_MergeEx(dict, update, 2) < 0) { format_kwargs_error(tstate, PEEK(3 + oparg), update); #line 2267 "Python/generated_cases.c.h" Py_DECREF(update); - #line 1569 "Python/bytecodes.c" + #line 1568 "Python/bytecodes.c" if (true) goto pop_1_error; } #line 2272 "Python/generated_cases.c.h" @@ -2278,7 +2278,7 @@ TARGET(MAP_ADD) { PyObject *value = stack_pointer[-1]; PyObject *key = stack_pointer[-2]; - #line 1576 "Python/bytecodes.c" + #line 1575 "Python/bytecodes.c" PyObject *dict = PEEK(oparg + 2); // key, value are still on the stack assert(PyDict_CheckExact(dict)); /* dict[key] = value */ @@ -2291,7 +2291,7 @@ } TARGET(INSTRUMENTED_LOAD_SUPER_ATTR) { - #line 1585 "Python/bytecodes.c" + #line 1584 "Python/bytecodes.c" _PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr; // cancel out the decrement that will happen in LOAD_SUPER_ATTR; we // don't want to specialize instrumented instructions @@ -2308,7 +2308,7 @@ PyObject *global_super = stack_pointer[-3]; PyObject *res2 = NULL; PyObject *res; - #line 1599 "Python/bytecodes.c" + #line 1598 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2); int load_method = oparg & 1; #if ENABLE_SPECIALIZATION @@ -2354,7 +2354,7 @@ Py_DECREF(global_super); Py_DECREF(class); Py_DECREF(self); - #line 1641 "Python/bytecodes.c" + #line 1640 "Python/bytecodes.c" if (super == NULL) goto pop_3_error; res = PyObject_GetAttr(super, name); Py_DECREF(super); @@ -2374,7 +2374,7 @@ PyObject *global_super = stack_pointer[-3]; PyObject *res2 = NULL; PyObject *res; - #line 1648 "Python/bytecodes.c" + #line 1647 "Python/bytecodes.c" assert(!(oparg & 1)); DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR); DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR); @@ -2385,7 +2385,7 @@ Py_DECREF(global_super); Py_DECREF(class); Py_DECREF(self); - #line 1655 "Python/bytecodes.c" + #line 1654 "Python/bytecodes.c" if (res == NULL) goto pop_3_error; #line 2391 "Python/generated_cases.c.h" STACK_SHRINK(2); @@ -2402,7 +2402,7 @@ PyObject *global_super = stack_pointer[-3]; PyObject *res2; PyObject *res; - #line 1659 "Python/bytecodes.c" + #line 1658 "Python/bytecodes.c" assert(oparg & 1); DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR); DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR); @@ -2437,7 +2437,7 @@ PyObject *owner = stack_pointer[-1]; PyObject *res2 = NULL; PyObject *res; - #line 1696 "Python/bytecodes.c" + #line 1695 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyAttrCache *cache = (_PyAttrCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -2473,7 +2473,7 @@ */ #line 2475 "Python/generated_cases.c.h" Py_DECREF(owner); - #line 1730 "Python/bytecodes.c" + #line 1729 "Python/bytecodes.c" if (meth == NULL) goto pop_1_error; res2 = NULL; res = meth; @@ -2484,7 +2484,7 @@ res = PyObject_GetAttr(owner, name); #line 2486 "Python/generated_cases.c.h" Py_DECREF(owner); - #line 1739 "Python/bytecodes.c" + #line 1738 "Python/bytecodes.c" if (res == NULL) goto pop_1_error; } #line 2491 "Python/generated_cases.c.h" @@ -2501,7 +2501,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1744 "Python/bytecodes.c" + #line 1743 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR); @@ -2529,7 +2529,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1760 "Python/bytecodes.c" + #line 1759 "Python/bytecodes.c" DEOPT_IF(!PyModule_CheckExact(owner), LOAD_ATTR); PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner)->md_dict; assert(dict != NULL); @@ -2557,7 +2557,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1776 "Python/bytecodes.c" + #line 1775 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR); @@ -2599,7 +2599,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1806 "Python/bytecodes.c" + #line 1805 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR); @@ -2624,7 +2624,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 1819 "Python/bytecodes.c" + #line 1818 "Python/bytecodes.c" DEOPT_IF(!PyType_Check(cls), LOAD_ATTR); DEOPT_IF(((PyTypeObject *)cls)->tp_version_tag != type_version, @@ -2650,7 +2650,7 @@ uint32_t type_version = read_u32(&next_instr[1].cache); uint32_t func_version = read_u32(&next_instr[3].cache); PyObject *fget = read_obj(&next_instr[5].cache); - #line 1834 "Python/bytecodes.c" + #line 1833 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR); PyTypeObject *cls = Py_TYPE(owner); @@ -2682,7 +2682,7 @@ uint32_t type_version = read_u32(&next_instr[1].cache); uint32_t func_version = read_u32(&next_instr[3].cache); PyObject *getattribute = read_obj(&next_instr[5].cache); - #line 1860 "Python/bytecodes.c" + #line 1859 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR); PyTypeObject *cls = Py_TYPE(owner); DEOPT_IF(cls->tp_version_tag != type_version, LOAD_ATTR); @@ -2716,7 +2716,7 @@ PyObject *value = stack_pointer[-2]; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1888 "Python/bytecodes.c" + #line 1887 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR); @@ -2745,7 +2745,7 @@ PyObject *value = stack_pointer[-2]; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t hint = read_u16(&next_instr[3].cache); - #line 1908 "Python/bytecodes.c" + #line 1907 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR); @@ -2795,7 +2795,7 @@ PyObject *value = stack_pointer[-2]; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1949 "Python/bytecodes.c" + #line 1948 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR); @@ -2817,7 +2817,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1968 "Python/bytecodes.c" + #line 1967 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -2833,7 +2833,7 @@ #line 2834 "Python/generated_cases.c.h" Py_DECREF(left); Py_DECREF(right); - #line 1981 "Python/bytecodes.c" + #line 1980 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; #line 2839 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -2846,7 +2846,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1985 "Python/bytecodes.c" + #line 1984 "Python/bytecodes.c" DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP); DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP); STAT_INC(COMPARE_OP, hit); @@ -2868,7 +2868,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1999 "Python/bytecodes.c" + #line 1998 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP); DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP); DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP); @@ -2894,7 +2894,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 2017 "Python/bytecodes.c" + #line 2016 "Python/bytecodes.c" DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP); DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP); STAT_INC(COMPARE_OP, hit); @@ -2917,12 +2917,12 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *b; - #line 2031 "Python/bytecodes.c" + #line 2030 "Python/bytecodes.c" int res = Py_Is(left, right) ^ oparg; #line 2923 "Python/generated_cases.c.h" Py_DECREF(left); Py_DECREF(right); - #line 2033 "Python/bytecodes.c" + #line 2032 "Python/bytecodes.c" b = res ? Py_True : Py_False; #line 2928 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -2934,12 +2934,12 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *b; - #line 2037 "Python/bytecodes.c" + #line 2036 "Python/bytecodes.c" int res = PySequence_Contains(right, left); #line 2940 "Python/generated_cases.c.h" Py_DECREF(left); Py_DECREF(right); - #line 2039 "Python/bytecodes.c" + #line 2038 "Python/bytecodes.c" if (res < 0) goto pop_2_error; b = (res ^ oparg) ? Py_True : Py_False; #line 2946 "Python/generated_cases.c.h" @@ -2953,12 +2953,12 @@ PyObject *exc_value = stack_pointer[-2]; PyObject *rest; PyObject *match; - #line 2044 "Python/bytecodes.c" + #line 2043 "Python/bytecodes.c" if (check_except_star_type_valid(tstate, match_type) < 0) { #line 2959 "Python/generated_cases.c.h" Py_DECREF(exc_value); Py_DECREF(match_type); - #line 2046 "Python/bytecodes.c" + #line 2045 "Python/bytecodes.c" if (true) goto pop_2_error; } @@ -2969,7 +2969,7 @@ #line 2970 "Python/generated_cases.c.h" Py_DECREF(exc_value); Py_DECREF(match_type); - #line 2054 "Python/bytecodes.c" + #line 2053 "Python/bytecodes.c" if (res < 0) goto pop_2_error; assert((match == NULL) == (rest == NULL)); @@ -2988,19 +2988,19 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *b; - #line 2065 "Python/bytecodes.c" + #line 2064 "Python/bytecodes.c" assert(PyExceptionInstance_Check(left)); if (check_except_type_valid(tstate, right) < 0) { #line 2995 "Python/generated_cases.c.h" Py_DECREF(right); - #line 2068 "Python/bytecodes.c" + #line 2067 "Python/bytecodes.c" if (true) goto pop_1_error; } int res = PyErr_GivenExceptionMatches(left, right); #line 3002 "Python/generated_cases.c.h" Py_DECREF(right); - #line 2073 "Python/bytecodes.c" + #line 2072 "Python/bytecodes.c" b = res ? Py_True : Py_False; #line 3006 "Python/generated_cases.c.h" stack_pointer[-1] = b; @@ -3011,13 +3011,13 @@ PyObject *fromlist = stack_pointer[-1]; PyObject *level = stack_pointer[-2]; PyObject *res; - #line 2077 "Python/bytecodes.c" + #line 2076 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); res = import_name(tstate, frame, name, fromlist, level); #line 3018 "Python/generated_cases.c.h" Py_DECREF(level); Py_DECREF(fromlist); - #line 2080 "Python/bytecodes.c" + #line 2079 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; #line 3023 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -3028,7 +3028,7 @@ TARGET(IMPORT_FROM) { PyObject *from = stack_pointer[-1]; PyObject *res; - #line 2084 "Python/bytecodes.c" + #line 2083 "Python/bytecodes.c" PyObject *name = GETITEM(frame->f_code->co_names, oparg); res = import_from(tstate, from, name); if (res == NULL) goto error; @@ -3039,7 +3039,7 @@ } TARGET(JUMP_FORWARD) { - #line 2090 "Python/bytecodes.c" + #line 2089 "Python/bytecodes.c" JUMPBY(oparg); #line 3045 "Python/generated_cases.c.h" DISPATCH(); @@ -3047,7 +3047,7 @@ TARGET(JUMP_BACKWARD) { PREDICTED(JUMP_BACKWARD); - #line 2094 "Python/bytecodes.c" + #line 2093 "Python/bytecodes.c" assert(oparg < INSTR_OFFSET()); JUMPBY(-oparg); #line 3054 "Python/generated_cases.c.h" @@ -3058,7 +3058,7 @@ TARGET(POP_JUMP_IF_FALSE) { PREDICTED(POP_JUMP_IF_FALSE); PyObject *cond = stack_pointer[-1]; - #line 2100 "Python/bytecodes.c" + #line 2099 "Python/bytecodes.c" if (Py_IsFalse(cond)) { JUMPBY(oparg); } @@ -3066,7 +3066,7 @@ int err = PyObject_IsTrue(cond); #line 3068 "Python/generated_cases.c.h" Py_DECREF(cond); - #line 2106 "Python/bytecodes.c" + #line 2105 "Python/bytecodes.c" if (err == 0) { JUMPBY(oparg); } @@ -3081,7 +3081,7 @@ TARGET(POP_JUMP_IF_TRUE) { PyObject *cond = stack_pointer[-1]; - #line 2116 "Python/bytecodes.c" + #line 2115 "Python/bytecodes.c" if (Py_IsTrue(cond)) { JUMPBY(oparg); } @@ -3089,7 +3089,7 @@ int err = PyObject_IsTrue(cond); #line 3091 "Python/generated_cases.c.h" Py_DECREF(cond); - #line 2122 "Python/bytecodes.c" + #line 2121 "Python/bytecodes.c" if (err > 0) { JUMPBY(oparg); } @@ -3104,11 +3104,11 @@ TARGET(POP_JUMP_IF_NOT_NONE) { PyObject *value = stack_pointer[-1]; - #line 2132 "Python/bytecodes.c" + #line 2131 "Python/bytecodes.c" if (!Py_IsNone(value)) { #line 3110 "Python/generated_cases.c.h" Py_DECREF(value); - #line 2134 "Python/bytecodes.c" + #line 2133 "Python/bytecodes.c" JUMPBY(oparg); } #line 3115 "Python/generated_cases.c.h" @@ -3118,14 +3118,14 @@ TARGET(POP_JUMP_IF_NONE) { PyObject *value = stack_pointer[-1]; - #line 2139 "Python/bytecodes.c" + #line 2138 "Python/bytecodes.c" if (Py_IsNone(value)) { JUMPBY(oparg); } else { #line 3127 "Python/generated_cases.c.h" Py_DECREF(value); - #line 2144 "Python/bytecodes.c" + #line 2143 "Python/bytecodes.c" } #line 3131 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -3133,7 +3133,7 @@ } TARGET(JUMP_BACKWARD_NO_INTERRUPT) { - #line 2148 "Python/bytecodes.c" + #line 2147 "Python/bytecodes.c" /* This bytecode is used in the `yield from` or `await` loop. * If there is an interrupt, we want it handled in the innermost * generator or coroutine, so we deliberately do not check it here. @@ -3147,7 +3147,7 @@ TARGET(GET_LEN) { PyObject *obj = stack_pointer[-1]; PyObject *len_o; - #line 2157 "Python/bytecodes.c" + #line 2156 "Python/bytecodes.c" // PUSH(len(TOS)) Py_ssize_t len_i = PyObject_Length(obj); if (len_i < 0) goto error; @@ -3164,7 +3164,7 @@ PyObject *type = stack_pointer[-2]; PyObject *subject = stack_pointer[-3]; PyObject *attrs; - #line 2165 "Python/bytecodes.c" + #line 2164 "Python/bytecodes.c" // Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or // None on failure. assert(PyTuple_CheckExact(names)); @@ -3173,7 +3173,7 @@ Py_DECREF(subject); Py_DECREF(type); Py_DECREF(names); - #line 2170 "Python/bytecodes.c" + #line 2169 "Python/bytecodes.c" if (attrs) { assert(PyTuple_CheckExact(attrs)); // Success! } @@ -3190,7 +3190,7 @@ TARGET(MATCH_MAPPING) { PyObject *subject = stack_pointer[-1]; PyObject *res; - #line 2180 "Python/bytecodes.c" + #line 2179 "Python/bytecodes.c" int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING; res = match ? Py_True : Py_False; #line 3197 "Python/generated_cases.c.h" @@ -3203,7 +3203,7 @@ TARGET(MATCH_SEQUENCE) { PyObject *subject = stack_pointer[-1]; PyObject *res; - #line 2186 "Python/bytecodes.c" + #line 2185 "Python/bytecodes.c" int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE; res = match ? Py_True : Py_False; #line 3210 "Python/generated_cases.c.h" @@ -3217,7 +3217,7 @@ PyObject *keys = stack_pointer[-1]; PyObject *subject = stack_pointer[-2]; PyObject *values_or_none; - #line 2192 "Python/bytecodes.c" + #line 2191 "Python/bytecodes.c" // On successful match, PUSH(values). Otherwise, PUSH(None). values_or_none = match_keys(tstate, subject, keys); if (values_or_none == NULL) goto error; @@ -3230,12 +3230,12 @@ TARGET(GET_ITER) { PyObject *iterable = stack_pointer[-1]; PyObject *iter; - #line 2198 "Python/bytecodes.c" + #line 2197 "Python/bytecodes.c" /* before: [obj]; after [getiter(obj)] */ iter = PyObject_GetIter(iterable); #line 3237 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 2201 "Python/bytecodes.c" + #line 2200 "Python/bytecodes.c" if (iter == NULL) goto pop_1_error; #line 3241 "Python/generated_cases.c.h" stack_pointer[-1] = iter; @@ -3245,7 +3245,7 @@ TARGET(GET_YIELD_FROM_ITER) { PyObject *iterable = stack_pointer[-1]; PyObject *iter; - #line 2205 "Python/bytecodes.c" + #line 2204 "Python/bytecodes.c" /* before: [obj]; after [getiter(obj)] */ if (PyCoro_CheckExact(iterable)) { /* `iterable` is a coroutine */ @@ -3270,7 +3270,7 @@ } #line 3272 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 2228 "Python/bytecodes.c" + #line 2227 "Python/bytecodes.c" } #line 3276 "Python/generated_cases.c.h" stack_pointer[-1] = iter; @@ -3283,7 +3283,7 @@ static_assert(INLINE_CACHE_ENTRIES_FOR_ITER == 1, "incorrect cache size"); PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2247 "Python/bytecodes.c" + #line 2246 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyForIterCache *cache = (_PyForIterCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -3322,7 +3322,7 @@ } TARGET(INSTRUMENTED_FOR_ITER) { - #line 2280 "Python/bytecodes.c" + #line 2279 "Python/bytecodes.c" _Py_CODEUNIT *here = next_instr-1; _Py_CODEUNIT *target; PyObject *iter = TOP(); @@ -3355,7 +3355,7 @@ TARGET(FOR_ITER_LIST) { PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2308 "Python/bytecodes.c" + #line 2307 "Python/bytecodes.c" DEOPT_IF(Py_TYPE(iter) != &PyListIter_Type, FOR_ITER); _PyListIterObject *it = (_PyListIterObject *)iter; STAT_INC(FOR_ITER, hit); @@ -3385,7 +3385,7 @@ TARGET(FOR_ITER_TUPLE) { PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2330 "Python/bytecodes.c" + #line 2329 "Python/bytecodes.c" _PyTupleIterObject *it = (_PyTupleIterObject *)iter; DEOPT_IF(Py_TYPE(it) != &PyTupleIter_Type, FOR_ITER); STAT_INC(FOR_ITER, hit); @@ -3415,7 +3415,7 @@ TARGET(FOR_ITER_RANGE) { PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2352 "Python/bytecodes.c" + #line 2351 "Python/bytecodes.c" _PyRangeIterObject *r = (_PyRangeIterObject *)iter; DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER); STAT_INC(FOR_ITER, hit); @@ -3442,7 +3442,7 @@ TARGET(FOR_ITER_GEN) { PyObject *iter = stack_pointer[-1]; - #line 2372 "Python/bytecodes.c" + #line 2371 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, FOR_ITER); PyGenObject *gen = (PyGenObject *)iter; DEOPT_IF(Py_TYPE(gen) != &PyGen_Type, FOR_ITER); @@ -3465,7 +3465,7 @@ PyObject *mgr = stack_pointer[-1]; PyObject *exit; PyObject *res; - #line 2390 "Python/bytecodes.c" + #line 2389 "Python/bytecodes.c" PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__)); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -3490,7 +3490,7 @@ } #line 3492 "Python/generated_cases.c.h" Py_DECREF(mgr); - #line 2413 "Python/bytecodes.c" + #line 2412 "Python/bytecodes.c" res = _PyObject_CallNoArgs(enter); Py_DECREF(enter); if (res == NULL) { @@ -3509,7 +3509,7 @@ PyObject *mgr = stack_pointer[-1]; PyObject *exit; PyObject *res; - #line 2423 "Python/bytecodes.c" + #line 2422 "Python/bytecodes.c" /* pop the context manager, push its __exit__ and the * value returned from calling its __enter__ */ @@ -3537,7 +3537,7 @@ } #line 3539 "Python/generated_cases.c.h" Py_DECREF(mgr); - #line 2449 "Python/bytecodes.c" + #line 2448 "Python/bytecodes.c" res = _PyObject_CallNoArgs(enter); Py_DECREF(enter); if (res == NULL) { @@ -3556,7 +3556,7 @@ PyObject *lasti = stack_pointer[-3]; PyObject *exit_func = stack_pointer[-4]; PyObject *res; - #line 2458 "Python/bytecodes.c" + #line 2457 "Python/bytecodes.c" /* At the top of the stack are 4 values: - val: TOP = exc_info() - unused: SECOND = previous exception @@ -3586,7 +3586,7 @@ TARGET(PUSH_EXC_INFO) { PyObject *new_exc = stack_pointer[-1]; PyObject *prev_exc; - #line 2481 "Python/bytecodes.c" + #line 2480 "Python/bytecodes.c" _PyErr_StackItem *exc_info = tstate->exc_info; if (exc_info->exc_value != NULL) { prev_exc = exc_info->exc_value; @@ -3610,7 +3610,7 @@ uint32_t type_version = read_u32(&next_instr[1].cache); uint32_t keys_version = read_u32(&next_instr[3].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 2493 "Python/bytecodes.c" + #line 2492 "Python/bytecodes.c" /* Cached method object */ PyTypeObject *self_cls = Py_TYPE(self); assert(type_version != 0); @@ -3641,7 +3641,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 2512 "Python/bytecodes.c" + #line 2511 "Python/bytecodes.c" PyTypeObject *self_cls = Py_TYPE(self); DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR); assert(self_cls->tp_dictoffset == 0); @@ -3665,7 +3665,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 2524 "Python/bytecodes.c" + #line 2523 "Python/bytecodes.c" PyTypeObject *self_cls = Py_TYPE(self); DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR); Py_ssize_t dictoffset = self_cls->tp_dictoffset; @@ -3688,7 +3688,7 @@ } TARGET(KW_NAMES) { - #line 2540 "Python/bytecodes.c" + #line 2539 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg < PyTuple_GET_SIZE(frame->f_code->co_consts)); kwnames = GETITEM(frame->f_code->co_consts, oparg); @@ -3697,7 +3697,7 @@ } TARGET(INSTRUMENTED_CALL) { - #line 2546 "Python/bytecodes.c" + #line 2545 "Python/bytecodes.c" int is_meth = PEEK(oparg+2) != NULL; int total_args = oparg + is_meth; PyObject *function = PEEK(total_args + 1); @@ -3720,7 +3720,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2591 "Python/bytecodes.c" + #line 2590 "Python/bytecodes.c" int is_meth = method != NULL; int total_args = oparg; if (is_meth) { @@ -3814,7 +3814,7 @@ TARGET(CALL_BOUND_METHOD_EXACT_ARGS) { PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; - #line 2679 "Python/bytecodes.c" + #line 2678 "Python/bytecodes.c" DEOPT_IF(method != NULL, CALL); DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type, CALL); STAT_INC(CALL, hit); @@ -3833,7 +3833,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; uint32_t func_version = read_u32(&next_instr[1].cache); - #line 2691 "Python/bytecodes.c" + #line 2690 "Python/bytecodes.c" assert(kwnames == NULL); DEOPT_IF(tstate->interp->eval_frame, CALL); int is_meth = method != NULL; @@ -3867,7 +3867,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; uint32_t func_version = read_u32(&next_instr[1].cache); - #line 2719 "Python/bytecodes.c" + #line 2718 "Python/bytecodes.c" assert(kwnames == NULL); DEOPT_IF(tstate->interp->eval_frame, CALL); int is_meth = method != NULL; @@ -3911,7 +3911,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *null = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2757 "Python/bytecodes.c" + #line 2756 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); DEOPT_IF(null != NULL, CALL); @@ -3934,7 +3934,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *null = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2769 "Python/bytecodes.c" + #line 2768 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); DEOPT_IF(null != NULL, CALL); @@ -3959,7 +3959,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *null = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2783 "Python/bytecodes.c" + #line 2782 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); DEOPT_IF(null != NULL, CALL); @@ -3984,7 +3984,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2797 "Python/bytecodes.c" + #line 2796 "Python/bytecodes.c" int is_meth = method != NULL; int total_args = oparg; if (is_meth) { @@ -4020,7 +4020,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2822 "Python/bytecodes.c" + #line 2821 "Python/bytecodes.c" /* Builtin METH_O functions */ assert(kwnames == NULL); int is_meth = method != NULL; @@ -4062,7 +4062,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2853 "Python/bytecodes.c" + #line 2852 "Python/bytecodes.c" /* Builtin METH_FASTCALL functions, without keywords */ assert(kwnames == NULL); int is_meth = method != NULL; @@ -4108,7 +4108,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2888 "Python/bytecodes.c" + #line 2887 "Python/bytecodes.c" /* Builtin METH_FASTCALL | METH_KEYWORDS functions */ int is_meth = method != NULL; int total_args = oparg; @@ -4154,7 +4154,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2923 "Python/bytecodes.c" + #line 2922 "Python/bytecodes.c" assert(kwnames == NULL); /* len(o) */ int is_meth = method != NULL; @@ -4192,7 +4192,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2950 "Python/bytecodes.c" + #line 2949 "Python/bytecodes.c" assert(kwnames == NULL); /* isinstance(o, o2) */ int is_meth = method != NULL; @@ -4231,7 +4231,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *self = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; - #line 2980 "Python/bytecodes.c" + #line 2979 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); assert(method != NULL); @@ -4256,7 +4256,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 3000 "Python/bytecodes.c" + #line 2999 "Python/bytecodes.c" assert(kwnames == NULL); int is_meth = method != NULL; int total_args = oparg; @@ -4300,7 +4300,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 3034 "Python/bytecodes.c" + #line 3033 "Python/bytecodes.c" int is_meth = method != NULL; int total_args = oparg; if (is_meth) { @@ -4342,7 +4342,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 3066 "Python/bytecodes.c" + #line 3065 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 0 || oparg == 1); int is_meth = method != NULL; @@ -4384,7 +4384,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 3098 "Python/bytecodes.c" + #line 3097 "Python/bytecodes.c" assert(kwnames == NULL); int is_meth = method != NULL; int total_args = oparg; @@ -4422,7 +4422,7 @@ } TARGET(INSTRUMENTED_CALL_FUNCTION_EX) { - #line 3129 "Python/bytecodes.c" + #line 3128 "Python/bytecodes.c" GO_TO_INSTRUCTION(CALL_FUNCTION_EX); #line 4428 "Python/generated_cases.c.h" } @@ -4433,7 +4433,7 @@ PyObject *callargs = stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))]; PyObject *func = stack_pointer[-(2 + ((oparg & 1) ? 1 : 0))]; PyObject *result; - #line 3133 "Python/bytecodes.c" + #line 3132 "Python/bytecodes.c" // DICT_MERGE is called before this opcode if there are kwargs. // It converts all dict subtypes in kwargs into regular dicts. assert(kwargs == NULL || PyDict_CheckExact(kwargs)); @@ -4499,7 +4499,7 @@ Py_DECREF(func); Py_DECREF(callargs); Py_XDECREF(kwargs); - #line 3195 "Python/bytecodes.c" + #line 3194 "Python/bytecodes.c" assert(PEEK(3 + (oparg & 1)) == NULL); if (result == NULL) { STACK_SHRINK(((oparg & 1) ? 1 : 0)); goto pop_3_error; } #line 4506 "Python/generated_cases.c.h" @@ -4517,7 +4517,7 @@ PyObject *kwdefaults = (oparg & 0x02) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0))] : NULL; PyObject *defaults = (oparg & 0x01) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x01) ? 1 : 0))] : NULL; PyObject *func; - #line 3205 "Python/bytecodes.c" + #line 3204 "Python/bytecodes.c" PyFunctionObject *func_obj = (PyFunctionObject *) PyFunction_New(codeobj, GLOBALS()); @@ -4553,7 +4553,7 @@ } TARGET(RETURN_GENERATOR) { - #line 3236 "Python/bytecodes.c" + #line 3235 "Python/bytecodes.c" assert(PyFunction_Check(frame->f_funcobj)); PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj; PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func); @@ -4582,13 +4582,13 @@ PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))]; PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))]; PyObject *slice; - #line 3259 "Python/bytecodes.c" + #line 3258 "Python/bytecodes.c" slice = PySlice_New(start, stop, step); #line 4588 "Python/generated_cases.c.h" Py_DECREF(start); Py_DECREF(stop); Py_XDECREF(step); - #line 3261 "Python/bytecodes.c" + #line 3260 "Python/bytecodes.c" if (slice == NULL) { STACK_SHRINK(((oparg == 3) ? 1 : 0)); goto pop_2_error; } #line 4594 "Python/generated_cases.c.h" STACK_SHRINK(((oparg == 3) ? 1 : 0)); @@ -4601,7 +4601,7 @@ PyObject *fmt_spec = ((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? stack_pointer[-((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))] : NULL; PyObject *value = stack_pointer[-(1 + (((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))]; PyObject *result; - #line 3265 "Python/bytecodes.c" + #line 3264 "Python/bytecodes.c" /* Handles f-string value formatting. */ PyObject *(*conv_fn)(PyObject *); int which_conversion = oparg & FVC_MASK; @@ -4645,7 +4645,7 @@ TARGET(COPY) { PyObject *bottom = stack_pointer[-(1 + (oparg-1))]; PyObject *top; - #line 3302 "Python/bytecodes.c" + #line 3301 "Python/bytecodes.c" assert(oparg > 0); top = Py_NewRef(bottom); #line 4652 "Python/generated_cases.c.h" @@ -4660,7 +4660,7 @@ PyObject *rhs = stack_pointer[-1]; PyObject *lhs = stack_pointer[-2]; PyObject *res; - #line 3307 "Python/bytecodes.c" + #line 3306 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -4678,7 +4678,7 @@ #line 4679 "Python/generated_cases.c.h" Py_DECREF(lhs); Py_DECREF(rhs); - #line 3322 "Python/bytecodes.c" + #line 3321 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; #line 4684 "Python/generated_cases.c.h" STACK_SHRINK(1); @@ -4690,7 +4690,7 @@ TARGET(SWAP) { PyObject *top = stack_pointer[-1]; PyObject *bottom = stack_pointer[-(2 + (oparg-2))]; - #line 3327 "Python/bytecodes.c" + #line 3326 "Python/bytecodes.c" assert(oparg >= 2); #line 4696 "Python/generated_cases.c.h" stack_pointer[-1] = bottom; @@ -4699,7 +4699,7 @@ } TARGET(INSTRUMENTED_INSTRUCTION) { - #line 3331 "Python/bytecodes.c" + #line 3330 "Python/bytecodes.c" int next_opcode = _Py_call_instrumentation_instruction( tstate, frame, next_instr-1); if (next_opcode < 0) goto error; @@ -4715,14 +4715,14 @@ } TARGET(INSTRUMENTED_JUMP_FORWARD) { - #line 3345 "Python/bytecodes.c" + #line 3344 "Python/bytecodes.c" INSTRUMENTED_JUMP(next_instr-1, next_instr+oparg, PY_MONITORING_EVENT_JUMP); #line 4721 "Python/generated_cases.c.h" DISPATCH(); } TARGET(INSTRUMENTED_JUMP_BACKWARD) { - #line 3349 "Python/bytecodes.c" + #line 3348 "Python/bytecodes.c" INSTRUMENTED_JUMP(next_instr-1, next_instr-oparg, PY_MONITORING_EVENT_JUMP); #line 4728 "Python/generated_cases.c.h" CHECK_EVAL_BREAKER(); @@ -4730,7 +4730,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_TRUE) { - #line 3354 "Python/bytecodes.c" + #line 3353 "Python/bytecodes.c" PyObject *cond = POP(); int err = PyObject_IsTrue(cond); Py_DECREF(cond); @@ -4744,7 +4744,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_FALSE) { - #line 3365 "Python/bytecodes.c" + #line 3364 "Python/bytecodes.c" PyObject *cond = POP(); int err = PyObject_IsTrue(cond); Py_DECREF(cond); @@ -4758,7 +4758,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_NONE) { - #line 3376 "Python/bytecodes.c" + #line 3375 "Python/bytecodes.c" PyObject *value = POP(); _Py_CODEUNIT *here = next_instr-1; int offset; @@ -4775,7 +4775,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_NOT_NONE) { - #line 3390 "Python/bytecodes.c" + #line 3389 "Python/bytecodes.c" PyObject *value = POP(); _Py_CODEUNIT *here = next_instr-1; int offset; @@ -4792,7 +4792,7 @@ } TARGET(EXTENDED_ARG) { - #line 3404 "Python/bytecodes.c" + #line 3403 "Python/bytecodes.c" assert(oparg); opcode = next_instr->op.code; oparg = oparg << 8 | next_instr->op.arg; @@ -4802,14 +4802,14 @@ } TARGET(CACHE) { - #line 3412 "Python/bytecodes.c" + #line 3411 "Python/bytecodes.c" assert(0 && "Executing a cache."); Py_UNREACHABLE(); #line 4809 "Python/generated_cases.c.h" } TARGET(RESERVED) { - #line 3417 "Python/bytecodes.c" + #line 3416 "Python/bytecodes.c" assert(0 && "Executing RESERVED instruction."); Py_UNREACHABLE(); #line 4816 "Python/generated_cases.c.h" From cfa517d5a68bae24cbe8d9fe6b8e0d4935e507d2 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 18 May 2023 10:10:15 +0100 Subject: [PATCH 02/11] GH-96803: Document and test new unstable internal frame API functions (GH-104211) Weaken contract of PyUnstable_InterpreterFrame_GetCode to return PyObject*. --- Doc/c-api/frame.rst | 35 ++++++++++++++++++++++++++++++++ Include/cpython/frameobject.h | 2 +- Lib/test/test_capi/test_misc.py | 24 ++++++++++++++++++++++ Modules/_testinternalcapi.c | 36 +++++++++++++++++++++++++++++++++ Python/frame.c | 4 ++-- 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/frame.rst b/Doc/c-api/frame.rst index 1ac8f03d6e48f8..9f7addfbbf3cb4 100644 --- a/Doc/c-api/frame.rst +++ b/Doc/c-api/frame.rst @@ -130,3 +130,38 @@ See also :ref:`Reflection `. .. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame) Return the line number that *frame* is currently executing. + + + +Internal Frames +--------------- + +Unless using :pep:`523`, you will not need this. + +.. c:struct:: _PyInterpreterFrame + + The interpreter's internal frame representation. + + .. versionadded:: 3.11 + +.. c:function:: PyObject* PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame); + + Return a :term:`strong reference` to the code object for the frame. + + .. versionadded:: 3.12 + + +.. c:function:: int PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame); + + Return the byte offset into the last executed instruction. + + .. versionadded:: 3.12 + + +.. c:function:: int PyUnstable_InterpreterFrame_GetLine(struct _PyInterpreterFrame *frame); + + Return the currently executing line number, or -1 if there is no line number. + + .. versionadded:: 3.12 + + diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index 6f3efe36ede5d8..a3dc6661786451 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -35,7 +35,7 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); /* Returns the code object of the frame (strong reference). * Does not raise an exception. */ -PyAPI_FUNC(PyCodeObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame); +PyAPI_FUNC(PyObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame); /* Returns a byte ofsset into the last executed instruction. * Does not raise an exception. */ diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 0ef0b5d8b65803..dc3441e4496a5d 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -1744,6 +1744,30 @@ class Subclass(BaseException, self.module.StateAccessType): self.assertIs(Subclass().get_defining_module(), self.module) +class TestInternalFrameApi(unittest.TestCase): + + @staticmethod + def func(): + return sys._getframe() + + def test_code(self): + frame = self.func() + code = _testinternalcapi.iframe_getcode(frame) + self.assertIs(code, self.func.__code__) + + def test_lasti(self): + frame = self.func() + lasti = _testinternalcapi.iframe_getlasti(frame) + self.assertGreater(lasti, 0) + self.assertLess(lasti, len(self.func.__code__.co_code)) + + def test_line(self): + frame = self.func() + line = _testinternalcapi.iframe_getline(frame) + firstline = self.func.__code__.co_firstlineno + self.assertEqual(line, firstline + 2) + + SUFFICIENT_TO_DEOPT_AND_SPECIALIZE = 100 class Test_Pep523API(unittest.TestCase): diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index ea9b6e72b3c924..5802f1d4ff5f50 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -12,6 +12,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "frameobject.h" #include "pycore_atomic_funcs.h" // _Py_atomic_int_get() #include "pycore_bitutils.h" // _Py_bswap32() #include "pycore_compile.h" // _PyCompile_CodeGen, _PyCompile_OptimizeCfg, _PyCompile_Assemble @@ -757,6 +758,38 @@ clear_extension(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject * +iframe_getcode(PyObject *self, PyObject *frame) +{ + if (!PyFrame_Check(frame)) { + PyErr_SetString(PyExc_TypeError, "argument must be a frame"); + return NULL; + } + struct _PyInterpreterFrame *f = ((PyFrameObject *)frame)->f_frame; + return PyUnstable_InterpreterFrame_GetCode(f); +} + +static PyObject * +iframe_getline(PyObject *self, PyObject *frame) +{ + if (!PyFrame_Check(frame)) { + PyErr_SetString(PyExc_TypeError, "argument must be a frame"); + return NULL; + } + struct _PyInterpreterFrame *f = ((PyFrameObject *)frame)->f_frame; + return PyLong_FromLong(PyUnstable_InterpreterFrame_GetLine(f)); +} + +static PyObject * +iframe_getlasti(PyObject *self, PyObject *frame) +{ + if (!PyFrame_Check(frame)) { + PyErr_SetString(PyExc_TypeError, "argument must be a frame"); + return NULL; + } + struct _PyInterpreterFrame *f = ((PyFrameObject *)frame)->f_frame; + return PyLong_FromLong(PyUnstable_InterpreterFrame_GetLasti(f)); +} static PyMethodDef module_functions[] = { {"get_configs", get_configs, METH_NOARGS}, @@ -781,6 +814,9 @@ static PyMethodDef module_functions[] = { _TESTINTERNALCAPI_ASSEMBLE_CODE_OBJECT_METHODDEF {"get_interp_settings", get_interp_settings, METH_VARARGS, NULL}, {"clear_extension", clear_extension, METH_VARARGS, NULL}, + {"iframe_getcode", iframe_getcode, METH_O, NULL}, + {"iframe_getline", iframe_getline, METH_O, NULL}, + {"iframe_getlasti", iframe_getlasti, METH_O, NULL}, {NULL, NULL} /* sentinel */ }; diff --git a/Python/frame.c b/Python/frame.c index d792b92fa57560..b84fd9b6a9380a 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -146,10 +146,10 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame) /* Unstable API functions */ -PyCodeObject * +PyObject * PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame) { - PyCodeObject *code = frame->f_code; + PyObject *code = (PyObject *)frame->f_code; Py_INCREF(code); return code; } From dcdc90d384723920e8dea0ee04eae8c219333634 Mon Sep 17 00:00:00 2001 From: thirumurugan <67573527+thirumurugan-git@users.noreply.github.com> Date: Thu, 18 May 2023 23:29:31 +0530 Subject: [PATCH 03/11] GH-104484: Add case_sensitive argument to `pathlib.PurePath.match()` (GH-104565) Co-authored-by: Barney Gale --- Doc/library/pathlib.rst | 7 ++++++- Doc/whatsnew/3.12.rst | 3 +++ Lib/pathlib.py | 20 +++++++++++++------ Lib/test/test_pathlib.py | 7 ++++++- ...-05-17-03-14-07.gh-issue-104484.y6KxL6.rst | 1 + 5 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-05-17-03-14-07.gh-issue-104484.y6KxL6.rst diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 93af07ae5ac10f..627f2df9263dec 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -546,7 +546,7 @@ Pure paths provide the following methods and properties: PureWindowsPath('c:/Program Files') -.. method:: PurePath.match(pattern) +.. method:: PurePath.match(pattern, *, case_sensitive=None) Match this path against the provided glob-style pattern. Return ``True`` if matching is successful, ``False`` otherwise. @@ -576,6 +576,11 @@ Pure paths provide the following methods and properties: >>> PureWindowsPath('b.py').match('*.PY') True + Set *case_sensitive* to ``True`` or ``False`` to override this behaviour. + + .. versionadded:: 3.12 + The *case_sensitive* argument. + .. method:: PurePath.relative_to(other, walk_up=False) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 3e55b3fa0f4734..25f0a4c3ca26da 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -395,6 +395,9 @@ pathlib * Add :meth:`pathlib.Path.is_junction` as a proxy to :func:`os.path.isjunction`. (Contributed by Charles Machalow in :gh:`99547`.) +* Add *case_sensitive* optional parameter to :meth:`pathlib.Path.glob`, + :meth:`pathlib.Path.rglob` and :meth:`pathlib.PurePath.match` for matching + the path's case sensitivity, allowing for more precise control over the matching process. dis --- diff --git a/Lib/pathlib.py b/Lib/pathlib.py index ef7c47c9e775e4..3d68c161603d08 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -86,6 +86,12 @@ def _make_selector(pattern_parts, flavour, case_sensitive): return cls(pat, child_parts, flavour, case_sensitive) +@functools.lru_cache(maxsize=256) +def _compile_pattern(pat, case_sensitive): + flags = re.NOFLAG if case_sensitive else re.IGNORECASE + return re.compile(fnmatch.translate(pat), flags).match + + class _Selector: """A selector matches a specific glob pattern part against the children of a given path.""" @@ -133,8 +139,7 @@ def __init__(self, pat, child_parts, flavour, case_sensitive): if case_sensitive is None: # TODO: evaluate case-sensitivity of each directory in _select_from() case_sensitive = _is_case_sensitive(flavour) - flags = re.NOFLAG if case_sensitive else re.IGNORECASE - self.match = re.compile(fnmatch.translate(pat), flags=flags).fullmatch + self.match = _compile_pattern(pat, case_sensitive) def _select_from(self, parent_path, scandir): try: @@ -680,22 +685,25 @@ def is_reserved(self): name = self._tail[-1].partition('.')[0].partition(':')[0].rstrip(' ') return name.upper() in _WIN_RESERVED_NAMES - def match(self, path_pattern): + def match(self, path_pattern, *, case_sensitive=None): """ Return True if this path matches the given pattern. """ + if case_sensitive is None: + case_sensitive = _is_case_sensitive(self._flavour) pat = self.with_segments(path_pattern) if not pat.parts: raise ValueError("empty pattern") - pat_parts = pat._parts_normcase - parts = self._parts_normcase + pat_parts = pat.parts + parts = self.parts if pat.drive or pat.root: if len(pat_parts) != len(parts): return False elif len(pat_parts) > len(parts): return False for part, pat in zip(reversed(parts), reversed(pat_parts)): - if not fnmatch.fnmatchcase(part, pat): + match = _compile_pattern(pat, case_sensitive) + if not match(part): return False return True diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 46a5248499c5d0..ab2c2b232a0411 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -312,6 +312,11 @@ def test_match_common(self): # Multi-part glob-style pattern. self.assertFalse(P('/a/b/c.py').match('/**/*.py')) self.assertTrue(P('/a/b/c.py').match('/a/**/*.py')) + # Case-sensitive flag + self.assertFalse(P('A.py').match('a.PY', case_sensitive=True)) + self.assertTrue(P('A.py').match('a.PY', case_sensitive=False)) + self.assertFalse(P('c:/a/B.Py').match('C:/A/*.pY', case_sensitive=True)) + self.assertTrue(P('/a/b/c.py').match('/A/*/*.Py', case_sensitive=False)) def test_ordering_common(self): # Ordering is tuple-alike. @@ -916,7 +921,7 @@ def test_as_uri(self): self.assertEqual(P('//some/share/a/b%#c\xe9').as_uri(), 'file://some/share/a/b%25%23c%C3%A9') - def test_match_common(self): + def test_match(self): P = self.cls # Absolute patterns. self.assertTrue(P('c:/b.py').match('*:/*.py')) diff --git a/Misc/NEWS.d/next/Library/2023-05-17-03-14-07.gh-issue-104484.y6KxL6.rst b/Misc/NEWS.d/next/Library/2023-05-17-03-14-07.gh-issue-104484.y6KxL6.rst new file mode 100644 index 00000000000000..6d42078c35dd26 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-17-03-14-07.gh-issue-104484.y6KxL6.rst @@ -0,0 +1 @@ +Added *case_sensitive* argument to :meth:`pathlib.PurePath.match` From 0589c6a4d3d822cace42050198cb9a5e99c879ad Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 18 May 2023 15:22:03 -0600 Subject: [PATCH 04/11] gh-104615: don't make unsafe swaps in apply_static_swaps (#104620) --- Include/internal/pycore_compile.h | 3 ++- .../pycore_global_objects_fini_generated.h | 1 + Include/internal/pycore_global_strings.h | 1 + .../internal/pycore_runtime_init_generated.h | 1 + .../internal/pycore_unicodeobject_generated.h | 3 +++ Lib/test/support/bytecode_helper.py | 4 ++-- Lib/test/test_compile.py | 18 +++++++++++++++ Lib/test/test_listcomps.py | 6 +++++ Lib/test/test_peepholer.py | 20 +++++++++++++--- ...-05-18-13-00-21.gh-issue-104615.h_rtw2.rst | 2 ++ Modules/_testinternalcapi.c | 7 +++--- Modules/clinic/_testinternalcapi.c.h | 23 +++++++++++-------- Python/compile.c | 4 ++-- Python/flowgraph.c | 22 ++++++++++++++++++ 14 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-05-18-13-00-21.gh-issue-104615.h_rtw2.rst diff --git a/Include/internal/pycore_compile.h b/Include/internal/pycore_compile.h index 499f55f3e276be..80a637e5bf9aed 100644 --- a/Include/internal/pycore_compile.h +++ b/Include/internal/pycore_compile.h @@ -105,7 +105,8 @@ PyAPI_FUNC(PyObject*) _PyCompile_CodeGen( PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg( PyObject *instructions, - PyObject *consts); + PyObject *consts, + int nlocals); PyAPI_FUNC(PyCodeObject*) _PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename, diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index 24a268ac8c43ec..eeaa2ad96c90d8 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -1071,6 +1071,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(newline)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(newlines)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(next)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(nlocals)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(node_depth)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(node_offset)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(ns)); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index c1005d05155271..5cc790d126bea7 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -559,6 +559,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(newline) STRUCT_FOR_ID(newlines) STRUCT_FOR_ID(next) + STRUCT_FOR_ID(nlocals) STRUCT_FOR_ID(node_depth) STRUCT_FOR_ID(node_offset) STRUCT_FOR_ID(ns) diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index ff1dee6eacfe5d..0cb24a92dffa3e 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -1065,6 +1065,7 @@ extern "C" { INIT_ID(newline), \ INIT_ID(newlines), \ INIT_ID(next), \ + INIT_ID(nlocals), \ INIT_ID(node_depth), \ INIT_ID(node_offset), \ INIT_ID(ns), \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index ba6b37f1bf55b3..fe2479beb8a3e4 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -1518,6 +1518,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(next); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); + string = &_Py_ID(nlocals); + assert(_PyUnicode_CheckConsistency(string, 1)); + _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(node_depth); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); diff --git a/Lib/test/support/bytecode_helper.py b/Lib/test/support/bytecode_helper.py index 7b577f54b8adc4..388d1266773c8a 100644 --- a/Lib/test/support/bytecode_helper.py +++ b/Lib/test/support/bytecode_helper.py @@ -130,10 +130,10 @@ def generate_code(self, ast): class CfgOptimizationTestCase(CompilationStepTestCase): - def get_optimized(self, insts, consts): + def get_optimized(self, insts, consts, nlocals=0): insts = self.normalize_insts(insts) insts = self.complete_insts_info(insts) - insts = optimize_cfg(insts, consts) + insts = optimize_cfg(insts, consts, nlocals) return insts, consts class AssemblerTestCase(CompilationStepTestCase): diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index c68b9ce388466e..784c0550cc09b1 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1168,6 +1168,24 @@ def foo(param, lambda_exp): """) compile(code, "", "exec") + def test_apply_static_swaps(self): + def f(x, y): + a, a = x, y + return a + self.assertEqual(f("x", "y"), "y") + + def test_apply_static_swaps_2(self): + def f(x, y, z): + a, b, a = x, y, z + return a + self.assertEqual(f("x", "y", "z"), "z") + + def test_apply_static_swaps_3(self): + def f(x, y, z): + a, a, b = x, y, z + return a + self.assertEqual(f("x", "y", "z"), "y") + @requires_debug_ranges() class TestSourcePositions(unittest.TestCase): diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index 985274dfd6cb93..ae63f4a3539451 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -484,6 +484,12 @@ def test_nested_listcomp_in_lambda(self): """ self._check_in_scopes(code, {"z": 1, "out": [(3, 2, 1)]}) + def test_assign_to_comp_iter_var_in_outer_function(self): + code = """ + a = [1 for a in [0]] + """ + self._check_in_scopes(code, {"a": [1]}, scopes=["function"]) + __test__ = {'doctests' : doctests} diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index bf7fc421a9df0a..255e9280421423 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -971,13 +971,14 @@ def trace(frame, event, arg): self.assertNotInBytecode(f, "LOAD_FAST_CHECK") -class DirectiCfgOptimizerTests(CfgOptimizationTestCase): +class DirectCfgOptimizerTests(CfgOptimizationTestCase): def cfg_optimization_test(self, insts, expected_insts, - consts=None, expected_consts=None): + consts=None, expected_consts=None, + nlocals=0): if expected_consts is None: expected_consts = consts - opt_insts, opt_consts = self.get_optimized(insts, consts) + opt_insts, opt_consts = self.get_optimized(insts, consts, nlocals) expected_insts = self.normalize_insts(expected_insts) self.assertInstructionsMatch(opt_insts, expected_insts) self.assertEqual(opt_consts, expected_consts) @@ -1058,6 +1059,19 @@ def test_conditional_jump_backward_const_condition(self): ] self.cfg_optimization_test(insts, expected_insts, consts=list(range(5))) + def test_no_unsafe_static_swap(self): + # We can't change order of two stores to the same location + insts = [ + ('LOAD_CONST', 0, 1), + ('LOAD_CONST', 1, 2), + ('LOAD_CONST', 2, 3), + ('SWAP', 3, 4), + ('STORE_FAST', 1, 4), + ('STORE_FAST', 1, 4), + ('POP_TOP', 0, 4), + ('RETURN_VALUE', 5) + ] + self.cfg_optimization_test(insts, insts, consts=list(range(3)), nlocals=1) if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-05-18-13-00-21.gh-issue-104615.h_rtw2.rst b/Misc/NEWS.d/next/Core and Builtins/2023-05-18-13-00-21.gh-issue-104615.h_rtw2.rst new file mode 100644 index 00000000000000..447291a619dd67 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-05-18-13-00-21.gh-issue-104615.h_rtw2.rst @@ -0,0 +1,2 @@ +Fix wrong ordering of assignments in code like ``a, a = x, y``. Contributed by +Carl Meyer. diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 5802f1d4ff5f50..3ee3323930836b 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -616,16 +616,17 @@ _testinternalcapi.optimize_cfg -> object instructions: object consts: object + nlocals: int Apply compiler optimizations to an instruction list. [clinic start generated code]*/ static PyObject * _testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions, - PyObject *consts) -/*[clinic end generated code: output=5412aeafca683c8b input=7e8a3de86ebdd0f9]*/ + PyObject *consts, int nlocals) +/*[clinic end generated code: output=57c53c3a3dfd1df0 input=6a96d1926d58d7e5]*/ { - return _PyCompile_OptimizeCfg(instructions, consts); + return _PyCompile_OptimizeCfg(instructions, consts, nlocals); } static int diff --git a/Modules/clinic/_testinternalcapi.c.h b/Modules/clinic/_testinternalcapi.c.h index 41dd50437956c4..f5124125874503 100644 --- a/Modules/clinic/_testinternalcapi.c.h +++ b/Modules/clinic/_testinternalcapi.c.h @@ -83,7 +83,7 @@ _testinternalcapi_compiler_codegen(PyObject *module, PyObject *const *args, Py_s } PyDoc_STRVAR(_testinternalcapi_optimize_cfg__doc__, -"optimize_cfg($module, /, instructions, consts)\n" +"optimize_cfg($module, /, instructions, consts, nlocals)\n" "--\n" "\n" "Apply compiler optimizations to an instruction list."); @@ -93,7 +93,7 @@ PyDoc_STRVAR(_testinternalcapi_optimize_cfg__doc__, static PyObject * _testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions, - PyObject *consts); + PyObject *consts, int nlocals); static PyObject * _testinternalcapi_optimize_cfg(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) @@ -101,14 +101,14 @@ _testinternalcapi_optimize_cfg(PyObject *module, PyObject *const *args, Py_ssize PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 2 + #define NUM_KEYWORDS 3 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD PyObject *ob_item[NUM_KEYWORDS]; } _kwtuple = { .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(instructions), &_Py_ID(consts), }, + .ob_item = { &_Py_ID(instructions), &_Py_ID(consts), &_Py_ID(nlocals), }, }; #undef NUM_KEYWORDS #define KWTUPLE (&_kwtuple.ob_base.ob_base) @@ -117,24 +117,29 @@ _testinternalcapi_optimize_cfg(PyObject *module, PyObject *const *args, Py_ssize # define KWTUPLE NULL #endif // !Py_BUILD_CORE - static const char * const _keywords[] = {"instructions", "consts", NULL}; + static const char * const _keywords[] = {"instructions", "consts", "nlocals", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, .fname = "optimize_cfg", .kwtuple = KWTUPLE, }; #undef KWTUPLE - PyObject *argsbuf[2]; + PyObject *argsbuf[3]; PyObject *instructions; PyObject *consts; + int nlocals; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); if (!args) { goto exit; } instructions = args[0]; consts = args[1]; - return_value = _testinternalcapi_optimize_cfg_impl(module, instructions, consts); + nlocals = _PyLong_AsInt(args[2]); + if (nlocals == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _testinternalcapi_optimize_cfg_impl(module, instructions, consts, nlocals); exit: return return_value; @@ -201,4 +206,4 @@ _testinternalcapi_assemble_code_object(PyObject *module, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=ab661d56a14b1a1c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2965f1578b986218 input=a9049054013a1b77]*/ diff --git a/Python/compile.c b/Python/compile.c index 07f8d6684770a4..96cd6daa29fa07 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -7996,7 +7996,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, } PyObject * -_PyCompile_OptimizeCfg(PyObject *instructions, PyObject *consts) +_PyCompile_OptimizeCfg(PyObject *instructions, PyObject *consts, int nlocals) { PyObject *res = NULL; PyObject *const_cache = PyDict_New(); @@ -8008,7 +8008,7 @@ _PyCompile_OptimizeCfg(PyObject *instructions, PyObject *consts) if (instructions_to_cfg(instructions, &g) < 0) { goto error; } - int code_flags = 0, nlocals = 0, nparams = 0, firstlineno = 1; + int code_flags = 0, nparams = 0, firstlineno = 1; if (_PyCfg_OptimizeCodeUnit(&g, consts, const_cache, code_flags, nlocals, nparams, firstlineno) < 0) { goto error; diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 7f790b79d2844f..f8039a4985d948 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -1293,6 +1293,11 @@ swaptimize(basicblock *block, int *ix) (opcode) == STORE_FAST_MAYBE_NULL || \ (opcode) == POP_TOP) +#define STORES_TO(instr) \ + (((instr).i_opcode == STORE_FAST || \ + (instr).i_opcode == STORE_FAST_MAYBE_NULL) \ + ? (instr).i_oparg : -1) + static int next_swappable_instruction(basicblock *block, int i, int lineno) { @@ -1344,6 +1349,23 @@ apply_static_swaps(basicblock *block, int i) return; } } + // The reordering is not safe if the two instructions to be swapped + // store to the same location, or if any intervening instruction stores + // to the same location as either of them. + int store_j = STORES_TO(block->b_instr[j]); + int store_k = STORES_TO(block->b_instr[k]); + if (store_j >= 0 || store_k >= 0) { + if (store_j == store_k) { + return; + } + for (int idx = j + 1; idx < k; idx++) { + int store_idx = STORES_TO(block->b_instr[idx]); + if (store_idx >= 0 && (store_idx == store_j || store_idx == store_k)) { + return; + } + } + } + // Success! INSTR_SET_OP0(swap, NOP); cfg_instr temp = block->b_instr[j]; From 61027c0211adf50e81b202075246509775808482 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 18 May 2023 23:52:59 +0200 Subject: [PATCH 05/11] gh-104146: Remove unused vars from Argument Clinic (#104627) Remove 'in_classes' and 'so_far' from DSLParser.directive_module() --- Tools/clinic/clinic.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 5fcf2bf485fc8a..ebee9782939499 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4230,10 +4230,8 @@ def directive_module(self, name): def directive_class(self, name, typedef, type_object): fields = name.split('.') - in_classes = False parent = self name = fields.pop() - so_far = [] module, cls = self.clinic._module_and_class(fields) parent = cls or module From 1c55e8d00728ceabd97cd1a5bd4906c9875a80c6 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 18 May 2023 22:58:42 +0100 Subject: [PATCH 06/11] gh-104050: Improve some typing around `default`s and sentinel values (#104626) - Convert `unspecified` and `unknown` to be members of a `Sentinels` enum, rather than instances of bespoke classes. - An enum feels more idiomatic here, and works better with type checkers. - Convert some `==` and `!=` checks for these values to identity checks, which are more idiomatic with sentinels. - _Don't_ do the same for `Null`, as this needs to be a distinct type due to its usage in `clinic.py`. - Use `object` as the annotation for `default` across `clinic.py`. `default` can be literally any object, so `object` is the correct annotation here. --- Co-authored-by: Erlend E. Aasland --- Tools/clinic/clinic.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index ebee9782939499..42aac7eb17f2ff 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -12,6 +12,7 @@ import contextlib import copy import cpp +import enum import functools import hashlib import inspect @@ -28,7 +29,7 @@ from collections.abc import Callable from types import FunctionType, NoneType -from typing import Any, NamedTuple, NoReturn, Literal, overload +from typing import Any, Final, NamedTuple, NoReturn, Literal, overload # TODO: # @@ -58,25 +59,26 @@ "return_value", } -class Unspecified: + +class Sentinels(enum.Enum): + unspecified = "unspecified" + unknown = "unknown" + def __repr__(self) -> str: - return '' + return f"<{self.value.capitalize()}>" + -unspecified = Unspecified() +unspecified: Final = Sentinels.unspecified +unknown: Final = Sentinels.unknown +# This one needs to be a distinct class, unlike the other two class Null: def __repr__(self) -> str: return '' -NULL = Null() - -class Unknown: - def __repr__(self) -> str: - return '' - -unknown = Unknown() +NULL = Null() sig_end_marker = '--' @@ -2600,7 +2602,7 @@ class CConverter(metaclass=CConverterAutoRegister): # Or the magic value "unknown" if this value is a cannot be evaluated # at Argument-Clinic-preprocessing time (but is presumed to be valid # at runtime). - default: bool | Unspecified = unspecified + default: object = unspecified # If not None, default must be isinstance() of this type. # (You can also specify a tuple of types.) @@ -2686,11 +2688,11 @@ def __init__(self, name: str, py_name: str, function, - default=unspecified, + default: object = unspecified, *, # Keyword only args: c_default: str | None = None, py_default: str | None = None, - annotation: str | Unspecified = unspecified, + annotation: str | Literal[Sentinels.unspecified] = unspecified, unused: bool = False, **kwargs ): @@ -2699,7 +2701,10 @@ def __init__(self, self.unused = unused if default is not unspecified: - if self.default_type and not isinstance(default, (self.default_type, Unknown)): + if (self.default_type + and default is not unknown + and not isinstance(default, self.default_type) + ): if isinstance(self.default_type, type): types_str = self.default_type.__name__ else: @@ -2713,7 +2718,7 @@ def __init__(self, if py_default: self.py_default = py_default - if annotation != unspecified: + if annotation is not unspecified: fail("The 'annotation' parameter is not currently permitted.") # this is deliberate, to prevent you from caching information @@ -3967,7 +3972,7 @@ class CReturnConverter(metaclass=CReturnConverterAutoRegister): # The Python default value for this parameter, as a Python value. # Or the magic value "unspecified" if there is no default. - default = None + default: object = None def __init__(self, *, py_default=None, **kwargs): self.py_default = py_default @@ -4767,7 +4772,7 @@ def bad_node(self, node): # but at least make an attempt at ensuring it's a valid expression. try: value = eval(default) - if value == unspecified: + if value is unspecified: fail("'unspecified' is not a legal default value!") except NameError: pass # probably a named constant From b9dce3aec46bf5190400bd8239fdd4ea9e64d674 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 18 May 2023 15:56:15 -0700 Subject: [PATCH 07/11] gh-104549: Set __module__ on TypeAliasType (#104550) --- Include/internal/pycore_global_objects.h | 1 - Include/internal/pycore_typevarobject.h | 2 + Lib/test/mod_generics_cache.py | 5 +- Lib/test/test_type_aliases.py | 20 +++++ Modules/_typingmodule.c | 5 +- Objects/object.c | 3 +- Objects/typevarobject.c | 83 ++++++++++++++------- Objects/unionobject.c | 7 +- Tools/c-analyzer/cpython/globals-to-fix.tsv | 1 + 9 files changed, 93 insertions(+), 34 deletions(-) diff --git a/Include/internal/pycore_global_objects.h b/Include/internal/pycore_global_objects.h index 40cc04d5d1702c..5a3fb132c745ab 100644 --- a/Include/internal/pycore_global_objects.h +++ b/Include/internal/pycore_global_objects.h @@ -75,7 +75,6 @@ struct _Py_interp_cached_objects { PyTypeObject *paramspec_type; PyTypeObject *paramspecargs_type; PyTypeObject *paramspeckwargs_type; - PyTypeObject *typealias_type; }; #define _Py_INTERP_STATIC_OBJECT(interp, NAME) \ diff --git a/Include/internal/pycore_typevarobject.h b/Include/internal/pycore_typevarobject.h index 2035e47e923059..c9fa97d6820757 100644 --- a/Include/internal/pycore_typevarobject.h +++ b/Include/internal/pycore_typevarobject.h @@ -16,6 +16,8 @@ extern PyObject *_Py_subscript_generic(PyThreadState *, PyObject *); extern int _Py_initialize_generic(PyInterpreterState *); extern void _Py_clear_generic_types(PyInterpreterState *); +extern PyTypeObject _PyTypeAlias_Type; + #ifdef __cplusplus } #endif diff --git a/Lib/test/mod_generics_cache.py b/Lib/test/mod_generics_cache.py index 9d8b56cf03c364..6c1ee2fec8374d 100644 --- a/Lib/test/mod_generics_cache.py +++ b/Lib/test/mod_generics_cache.py @@ -1,6 +1,6 @@ """Module for testing the behavior of generics across different modules.""" -from typing import TypeVar, Generic, Optional +from typing import TypeVar, Generic, Optional, TypeAliasType default_a: Optional['A'] = None default_b: Optional['B'] = None @@ -19,3 +19,6 @@ class A(Generic[T]): my_inner_a1: 'B.A' my_inner_a2: A my_outer_a: 'A' # unless somebody calls get_type_hints with localns=B.__dict__ + +type Alias = int +OldStyle = TypeAliasType("OldStyle", int) diff --git a/Lib/test/test_type_aliases.py b/Lib/test/test_type_aliases.py index d2abb932f589f7..56d150d67afb6f 100644 --- a/Lib/test/test_type_aliases.py +++ b/Lib/test/test_type_aliases.py @@ -1,6 +1,8 @@ +import pickle import types import unittest from test.support import check_syntax_error, run_code +from test import mod_generics_cache from typing import Callable, TypeAliasType, TypeVar, get_args @@ -155,6 +157,7 @@ def test_basic(self): self.assertEqual(TA.__name__, "TA") self.assertIs(TA.__value__, int) self.assertEqual(TA.__type_params__, ()) + self.assertEqual(TA.__module__, __name__) def test_generic(self): T = TypeVar("T") @@ -162,12 +165,14 @@ def test_generic(self): self.assertEqual(TA.__name__, "TA") self.assertEqual(TA.__value__, list[T]) self.assertEqual(TA.__type_params__, (T,)) + self.assertEqual(TA.__module__, __name__) def test_keywords(self): TA = TypeAliasType(name="TA", value=int) self.assertEqual(TA.__name__, "TA") self.assertIs(TA.__value__, int) self.assertEqual(TA.__type_params__, ()) + self.assertEqual(TA.__module__, __name__) def test_errors(self): with self.assertRaises(TypeError): @@ -202,3 +207,18 @@ def test_union(self): union3 = list[range] | Alias1 self.assertIsInstance(union3, types.UnionType) self.assertEqual(get_args(union3), (list[range], Alias1)) + + def test_module(self): + self.assertEqual(TypeAliasType.__module__, "typing") + type Alias = int + self.assertEqual(Alias.__module__, __name__) + self.assertEqual(mod_generics_cache.Alias.__module__, + mod_generics_cache.__name__) + self.assertEqual(mod_generics_cache.OldStyle.__module__, + mod_generics_cache.__name__) + + def test_pickling(self): + pickled = pickle.dumps(mod_generics_cache.Alias) + self.assertIs(pickle.loads(pickled), mod_generics_cache.Alias) + pickled = pickle.dumps(mod_generics_cache.OldStyle) + self.assertIs(pickle.loads(pickled), mod_generics_cache.OldStyle) diff --git a/Modules/_typingmodule.c b/Modules/_typingmodule.c index ed2999c0b68b24..39a124a26adf31 100644 --- a/Modules/_typingmodule.c +++ b/Modules/_typingmodule.c @@ -6,6 +6,7 @@ #include "Python.h" #include "internal/pycore_interp.h" +#include "internal/pycore_typevarobject.h" #include "clinic/_typingmodule.c.h" /*[clinic input] @@ -56,9 +57,11 @@ _typing_exec(PyObject *m) EXPORT_TYPE("ParamSpec", paramspec_type); EXPORT_TYPE("ParamSpecArgs", paramspecargs_type); EXPORT_TYPE("ParamSpecKwargs", paramspeckwargs_type); - EXPORT_TYPE("TypeAliasType", typealias_type); EXPORT_TYPE("Generic", generic_type); #undef EXPORT_TYPE + if (PyModule_AddObjectRef(m, "TypeAliasType", (PyObject *)&_PyTypeAlias_Type) < 0) { + return -1; + } return 0; } diff --git a/Objects/object.c b/Objects/object.c index f3118665430d9f..ece0c5e21e77fa 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -14,7 +14,7 @@ #include "pycore_pymem.h" // _PyMem_IsPtrFreed() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_symtable.h" // PySTEntry_Type -#include "pycore_typevarobject.h" // _PyTypeVar_Type etc., _Py_initialize_generic +#include "pycore_typevarobject.h" // _PyTypeAlias_Type, _Py_initialize_generic #include "pycore_typeobject.h" // _PyBufferWrapper_Type #include "pycore_unionobject.h" // _PyUnion_Type #include "pycore_interpreteridobject.h" // _PyInterpreterID_Type @@ -2112,6 +2112,7 @@ static PyTypeObject* static_types[] = { &_PyWeakref_CallableProxyType, &_PyWeakref_ProxyType, &_PyWeakref_RefType, + &_PyTypeAlias_Type, // subclasses: _PyTypes_FiniTypes() deallocates them before their base // class diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index 4464e7a9da89db..6730ebfc064e35 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -48,6 +48,7 @@ typedef struct { PyObject *type_params; PyObject *compute_value; PyObject *value; + PyObject *module; } typealiasobject; #include "clinic/typevarobject.c.h" @@ -1252,6 +1253,7 @@ typealias_dealloc(PyObject *self) Py_XDECREF(ta->type_params); Py_XDECREF(ta->compute_value); Py_XDECREF(ta->value); + Py_XDECREF(ta->module); Py_TYPE(self)->tp_free(self); Py_DECREF(tp); } @@ -1309,19 +1311,33 @@ typealias_type_params(PyObject *self, void *unused) return Py_NewRef(ta->type_params); } +static PyObject * +typealias_module(PyObject *self, void *unused) +{ + typealiasobject *ta = (typealiasobject *)self; + if (ta->module != NULL) { + return Py_NewRef(ta->module); + } + if (ta->compute_value != NULL) { + // PyFunction_GetModule() returns a borrowed reference + return Py_NewRef(PyFunction_GetModule(ta->compute_value)); + } + Py_RETURN_NONE; +} + static PyGetSetDef typealias_getset[] = { {"__parameters__", typealias_parameters, (setter)NULL, NULL, NULL}, {"__type_params__", typealias_type_params, (setter)NULL, NULL, NULL}, {"__value__", typealias_value, (setter)NULL, NULL, NULL}, + {"__module__", typealias_module, (setter)NULL, NULL, NULL}, {0} }; static typealiasobject * typealias_alloc(PyObject *name, PyObject *type_params, PyObject *compute_value, - PyObject *value) + PyObject *value, PyObject *module) { - PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typealias_type; - typealiasobject *ta = PyObject_GC_New(typealiasobject, tp); + typealiasobject *ta = PyObject_GC_New(typealiasobject, &_PyTypeAlias_Type); if (ta == NULL) { return NULL; } @@ -1329,6 +1345,7 @@ typealias_alloc(PyObject *name, PyObject *type_params, PyObject *compute_value, ta->type_params = Py_IsNone(type_params) ? NULL : Py_XNewRef(type_params); ta->compute_value = Py_XNewRef(compute_value); ta->value = Py_XNewRef(value); + ta->module = Py_XNewRef(module); _PyObject_GC_TRACK(ta); return ta; } @@ -1339,6 +1356,7 @@ typealias_traverse(typealiasobject *self, visitproc visit, void *arg) Py_VISIT(self->type_params); Py_VISIT(self->compute_value); Py_VISIT(self->value); + Py_VISIT(self->module); return 0; } @@ -1348,6 +1366,7 @@ typealias_clear(typealiasobject *self) Py_CLEAR(self->type_params); Py_CLEAR(self->compute_value); Py_CLEAR(self->value); + Py_CLEAR(self->module); return 0; } @@ -1401,7 +1420,14 @@ typealias_new_impl(PyTypeObject *type, PyObject *name, PyObject *value, PyErr_SetString(PyExc_TypeError, "type_params must be a tuple"); return NULL; } - return (PyObject *)typealias_alloc(name, type_params, NULL, value); + PyObject *module = caller(); + if (module == NULL) { + return NULL; + } + PyObject *ta = (PyObject *)typealias_alloc(name, type_params, NULL, value, + module); + Py_DECREF(module); + return ta; } PyDoc_STRVAR(typealias_doc, @@ -1412,28 +1438,32 @@ Type aliases are created through the type statement:\n\ type Alias = int\n\ "); -static PyType_Slot typealias_slots[] = { - {Py_tp_doc, (void *)typealias_doc}, - {Py_tp_members, typealias_members}, - {Py_tp_methods, typealias_methods}, - {Py_tp_getset, typealias_getset}, - {Py_mp_subscript, typealias_subscript}, - {Py_tp_dealloc, typealias_dealloc}, - {Py_tp_alloc, PyType_GenericAlloc}, - {Py_tp_new, typealias_new}, - {Py_tp_free, PyObject_GC_Del}, - {Py_tp_traverse, (traverseproc)typealias_traverse}, - {Py_tp_clear, (inquiry)typealias_clear}, - {Py_tp_repr, typealias_repr}, - {Py_nb_or, _Py_union_type_or}, - {0, 0}, +static PyNumberMethods typealias_as_number = { + .nb_or = _Py_union_type_or, +}; + +static PyMappingMethods typealias_as_mapping = { + .mp_subscript = typealias_subscript, }; -PyType_Spec typealias_spec = { - .name = "typing.TypeAliasType", - .basicsize = sizeof(typealiasobject), - .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC, - .slots = typealias_slots, +PyTypeObject _PyTypeAlias_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + .tp_name = "typing.TypeAliasType", + .tp_basicsize = sizeof(typealiasobject), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC, + .tp_doc = typealias_doc, + .tp_members = typealias_members, + .tp_methods = typealias_methods, + .tp_getset = typealias_getset, + .tp_alloc = PyType_GenericAlloc, + .tp_dealloc = typealias_dealloc, + .tp_new = typealias_new, + .tp_free = PyObject_GC_Del, + .tp_traverse = (traverseproc)typealias_traverse, + .tp_clear = (inquiry)typealias_clear, + .tp_repr = typealias_repr, + .tp_as_number = &typealias_as_number, + .tp_as_mapping = &typealias_as_mapping, }; PyObject * @@ -1445,7 +1475,8 @@ _Py_make_typealias(PyThreadState* unused, PyObject *args) assert(PyUnicode_Check(name)); PyObject *type_params = PyTuple_GET_ITEM(args, 1); PyObject *compute_value = PyTuple_GET_ITEM(args, 2); - return (PyObject *)typealias_alloc(name, type_params, compute_value, NULL); + assert(PyFunction_Check(compute_value)); + return (PyObject *)typealias_alloc(name, type_params, compute_value, NULL, NULL); } PyDoc_STRVAR(generic_doc, @@ -1603,7 +1634,6 @@ int _Py_initialize_generic(PyInterpreterState *interp) MAKE_TYPE(paramspec); MAKE_TYPE(paramspecargs); MAKE_TYPE(paramspeckwargs); - MAKE_TYPE(typealias); #undef MAKE_TYPE return 0; } @@ -1616,5 +1646,4 @@ void _Py_clear_generic_types(PyInterpreterState *interp) Py_CLEAR(interp->cached_objects.paramspec_type); Py_CLEAR(interp->cached_objects.paramspecargs_type); Py_CLEAR(interp->cached_objects.paramspeckwargs_type); - Py_CLEAR(interp->cached_objects.typealias_type); } diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 9806678b804857..f509a161bb9564 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -1,6 +1,7 @@ // types.UnionType -- used to represent e.g. Union[int, str], int | str #include "Python.h" #include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK +#include "pycore_typevarobject.h" // _PyTypeAlias_Type #include "pycore_unionobject.h" #include "structmember.h" @@ -150,11 +151,11 @@ is_unionable(PyObject *obj) if (obj == Py_None || PyType_Check(obj) || _PyGenericAlias_Check(obj) || - _PyUnion_Check(obj)) { + _PyUnion_Check(obj) || + Py_IS_TYPE(obj, &_PyTypeAlias_Type)) { return 1; } - PyInterpreterState *interp = PyInterpreterState_Get(); - return Py_IS_TYPE(obj, interp->cached_objects.typealias_type); + return 0; } PyObject * diff --git a/Tools/c-analyzer/cpython/globals-to-fix.tsv b/Tools/c-analyzer/cpython/globals-to-fix.tsv index e2b93a3a2ec274..622c98d16283a8 100644 --- a/Tools/c-analyzer/cpython/globals-to-fix.tsv +++ b/Tools/c-analyzer/cpython/globals-to-fix.tsv @@ -90,6 +90,7 @@ Objects/typeobject.c - _PyBufferWrapper_Type - Objects/typeobject.c - PyBaseObject_Type - Objects/typeobject.c - PySuper_Type - Objects/typeobject.c - PyType_Type - +Objects/typevarobject.c - _PyTypeAlias_Type - Objects/unicodeobject.c - PyUnicodeIter_Type - Objects/unicodeobject.c - PyUnicode_Type - Objects/weakrefobject.c - _PyWeakref_CallableProxyType - From 86ee49f469b84e4b746526a00d8191d0e374a268 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 19 May 2023 00:56:34 +0200 Subject: [PATCH 08/11] gh-104629: Don't skip test_clinic if _testclinic is missing (#104630) Just skip the tests that depend on the _testclinic extension module; we can still run the Python tests. --- Lib/test/test_clinic.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 28d9f650926427..f72cb0442f35ff 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -868,9 +868,12 @@ def test_external(self): self.assertEqual(new_mtime_ns, old_mtime_ns) -ac_tester = import_helper.import_module('_testclinic') - +try: + import _testclinic as ac_tester +except ImportError: + ac_tester = None +@unittest.skipIf(ac_tester is None, "_testclinic is missing") class ClinicFunctionalTest(unittest.TestCase): locals().update((name, getattr(ac_tester, name)) for name in dir(ac_tester) if name.startswith('test_')) From 94c8edabd3d6c8739aaae9b1cb0be822c754c742 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 19 May 2023 00:57:26 +0200 Subject: [PATCH 09/11] gh-104050: Add more type annotations to Argument Clinic (#104628) Annotate the following: - methods of class Class - methods of class Module - methods of class PythonParser - function compute_checksum() - function parse_file() - global variable unsupported_special_methods --- Tools/clinic/clinic.py | 53 +++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 42aac7eb17f2ff..3d4961e6e7d7dd 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -2229,7 +2229,12 @@ def _module_and_class(self, fields): return module, cls -def parse_file(filename, *, verify=True, output=None): +def parse_file( + filename: str, + *, + verify: bool = True, + output: str | None = None +) -> None: if not output: output = filename @@ -2261,7 +2266,10 @@ def parse_file(filename, *, verify=True, output=None): write_file(fn, data) -def compute_checksum(input, length=None): +def compute_checksum( + input: str | None, + length: int | None = None +) -> str: input = input or '' s = hashlib.sha1(input.encode('utf-8')).hexdigest() if length: @@ -2272,30 +2280,46 @@ def compute_checksum(input, length=None): class PythonParser: - def __init__(self, clinic): + def __init__(self, clinic: Clinic) -> None: pass - def parse(self, block): + def parse(self, block: Block) -> None: s = io.StringIO() with OverrideStdioWith(s): exec(block.input) block.output = s.getvalue() +ModuleDict = dict[str, "Module"] + class Module: - def __init__(self, name, module=None): + def __init__( + self, + name: str, + module = None + ) -> None: self.name = name self.module = self.parent = module - self.modules = collections.OrderedDict() - self.classes = collections.OrderedDict() - self.functions = [] + self.modules: ModuleDict = collections.OrderedDict() + self.classes: ClassDict = collections.OrderedDict() + self.functions: list[Function] = [] - def __repr__(self): + def __repr__(self) -> str: return "" + +ClassDict = dict[str, "Class"] + class Class: - def __init__(self, name, module=None, cls=None, typedef=None, type_object=None): + def __init__( + self, + name: str, + module: Module | None = None, + cls = None, + typedef: str | None = None, + type_object: str | None = None + ) -> None: self.name = name self.module = module self.cls = cls @@ -2303,13 +2327,14 @@ def __init__(self, name, module=None, cls=None, typedef=None, type_object=None): self.type_object = type_object self.parent = cls or module - self.classes = collections.OrderedDict() - self.functions = [] + self.classes: ClassDict = collections.OrderedDict() + self.functions: list[Function] = [] - def __repr__(self): + def __repr__(self) -> str: return "" -unsupported_special_methods = set(""" + +unsupported_special_methods: set[str] = set(""" __abs__ __add__ From aab2a366b7d6a5c123bc8d23d66db4d2277dfa09 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 19 May 2023 00:59:40 +0200 Subject: [PATCH 10/11] gh-104623: Update Windows installer to use SQLite 3.42.0 (#104625) --- .../next/Windows/2023-05-18-22-46-03.gh-issue-104623.HJZhm1.rst | 1 + PCbuild/get_externals.bat | 2 +- PCbuild/python.props | 2 +- PCbuild/readme.txt | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2023-05-18-22-46-03.gh-issue-104623.HJZhm1.rst diff --git a/Misc/NEWS.d/next/Windows/2023-05-18-22-46-03.gh-issue-104623.HJZhm1.rst b/Misc/NEWS.d/next/Windows/2023-05-18-22-46-03.gh-issue-104623.HJZhm1.rst new file mode 100644 index 00000000000000..3ffe8261e5a1b0 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2023-05-18-22-46-03.gh-issue-104623.HJZhm1.rst @@ -0,0 +1 @@ +Update Windows installer to use SQLite 3.42.0. diff --git a/PCbuild/get_externals.bat b/PCbuild/get_externals.bat index 30ee873af9af24..39003d954d705a 100644 --- a/PCbuild/get_externals.bat +++ b/PCbuild/get_externals.bat @@ -54,7 +54,7 @@ set libraries= set libraries=%libraries% bzip2-1.0.8 if NOT "%IncludeLibffiSrc%"=="false" set libraries=%libraries% libffi-3.4.4 if NOT "%IncludeSSLSrc%"=="false" set libraries=%libraries% openssl-1.1.1t -set libraries=%libraries% sqlite-3.41.2.0 +set libraries=%libraries% sqlite-3.42.0.0 if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tcl-core-8.6.13.0 if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tk-8.6.13.0 if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tix-8.4.3.6 diff --git a/PCbuild/python.props b/PCbuild/python.props index 29add07795f900..1d959699f3cfb0 100644 --- a/PCbuild/python.props +++ b/PCbuild/python.props @@ -68,7 +68,7 @@ - $(ExternalsDir)sqlite-3.41.2.0\ + $(ExternalsDir)sqlite-3.42.0.0\ $(ExternalsDir)bzip2-1.0.8\ $(ExternalsDir)xz-5.2.5\ $(ExternalsDir)libffi-3.4.4\ diff --git a/PCbuild/readme.txt b/PCbuild/readme.txt index 9df56685b76a87..3629525e33d56c 100644 --- a/PCbuild/readme.txt +++ b/PCbuild/readme.txt @@ -188,7 +188,7 @@ _ssl again when building. _sqlite3 - Wraps SQLite 3.41.2, which is itself built by sqlite3.vcxproj + Wraps SQLite 3.42.0, which is itself built by sqlite3.vcxproj Homepage: https://www.sqlite.org/ _tkinter From f7835fc7e9617cefd87e72002916e258f589c857 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 19 May 2023 00:34:40 +0100 Subject: [PATCH 11/11] gh-74690: Don't set special protocol attributes on non-protocol subclasses of protocols (#104622) Don't set special protocol attributes on non-protocol subclasses of protocols --- Lib/test/test_typing.py | 15 +++++++++++++++ Lib/typing.py | 13 +++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index bf038bf143a6c8..450c85967dd75a 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -3167,6 +3167,21 @@ def meth(self): pass self.assertIsInstance(NonPR(), PR) self.assertIsSubclass(NonPR, PR) + self.assertNotIn("__protocol_attrs__", vars(NonP)) + self.assertNotIn("__protocol_attrs__", vars(NonPR)) + self.assertNotIn("__callable_proto_members_only__", vars(NonP)) + self.assertNotIn("__callable_proto_members_only__", vars(NonPR)) + + acceptable_extra_attrs = { + '_is_protocol', '_is_runtime_protocol', '__parameters__', + '__subclasshook__', '__abstractmethods__', '_abc_impl', + '__init__', '__annotations__', + } + self.assertLessEqual(vars(NonP).keys(), vars(C).keys() | acceptable_extra_attrs) + self.assertLessEqual( + vars(NonPR).keys(), vars(D).keys() | acceptable_extra_attrs + ) + def test_custom_subclasshook(self): class P(Protocol): x = 1 diff --git a/Lib/typing.py b/Lib/typing.py index 91b5fe5b87e669..b60eb94351f9bb 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1779,12 +1779,13 @@ class _ProtocolMeta(ABCMeta): # but is necessary for several reasons... def __init__(cls, *args, **kwargs): super().__init__(*args, **kwargs) - cls.__protocol_attrs__ = _get_protocol_attrs(cls) - # PEP 544 prohibits using issubclass() - # with protocols that have non-method members. - cls.__callable_proto_members_only__ = all( - callable(getattr(cls, attr, None)) for attr in cls.__protocol_attrs__ - ) + if getattr(cls, "_is_protocol", False): + cls.__protocol_attrs__ = _get_protocol_attrs(cls) + # PEP 544 prohibits using issubclass() + # with protocols that have non-method members. + cls.__callable_proto_members_only__ = all( + callable(getattr(cls, attr, None)) for attr in cls.__protocol_attrs__ + ) def __subclasscheck__(cls, other): if (