@@ -1507,8 +1507,8 @@ dummy_func(
15071507 }
15081508
15091509 inst (LOAD_BUILD_CLASS , ( -- bc )) {
1510- PyObject * bc_o ;
1511- int err = PyMapping_GetOptionalItem (BUILTINS (), & _Py_ID (__build_class__ ), & bc_o );
1510+ int err ;
1511+ PyObject * bc_o = _PyMapping_GetOptionalItem2 (BUILTINS (), & _Py_ID (__build_class__ ), & err );
15121512 ERROR_IF (err < 0 );
15131513 if (bc_o == NULL ) {
15141514 _PyErr_SetString (tstate , PyExc_NameError ,
@@ -1711,8 +1711,9 @@ dummy_func(
17111711
17121712 inst (LOAD_FROM_DICT_OR_GLOBALS , (mod_or_class_dict -- v )) {
17131713 PyObject * name = GETITEM (FRAME_CO_NAMES , oparg );
1714- PyObject * v_o ;
1715- int err = PyMapping_GetOptionalItem (PyStackRef_AsPyObjectBorrow (mod_or_class_dict ), name , & v_o );
1714+ int err ;
1715+ PyObject * v_o = _PyMapping_GetOptionalItem2 (PyStackRef_AsPyObjectBorrow (mod_or_class_dict ), name , & err );
1716+
17161717 PyStackRef_CLOSE (mod_or_class_dict );
17171718 ERROR_IF (err < 0 );
17181719 if (v_o == NULL ) {
@@ -1735,11 +1736,11 @@ dummy_func(
17351736 else {
17361737 /* Slow-path if globals or builtins is not a dict */
17371738 /* namespace 1: globals */
1738- int err = PyMapping_GetOptionalItem (GLOBALS (), name , & v_o );
1739+ v_o = _PyMapping_GetOptionalItem2 (GLOBALS (), name , & err );
17391740 ERROR_IF (err < 0 );
17401741 if (v_o == NULL ) {
17411742 /* namespace 2: builtins */
1742- int err = PyMapping_GetOptionalItem (BUILTINS (), name , & v_o );
1743+ v_o = _PyMapping_GetOptionalItem2 (BUILTINS (), name , & err );
17431744 ERROR_IF (err < 0 );
17441745 if (v_o == NULL ) {
17451746 _PyEval_FormatExcCheckArg (
@@ -1898,14 +1899,14 @@ dummy_func(
18981899 }
18991900
19001901 inst (LOAD_FROM_DICT_OR_DEREF , (class_dict_st -- value )) {
1901- PyObject * value_o ;
19021902 PyObject * name ;
19031903 PyObject * class_dict = PyStackRef_AsPyObjectBorrow (class_dict_st );
19041904
19051905 assert (class_dict );
19061906 assert (oparg >= 0 && oparg < _PyFrame_GetCode (frame )-> co_nlocalsplus );
19071907 name = PyTuple_GET_ITEM (_PyFrame_GetCode (frame )-> co_localsplusnames , oparg );
1908- int err = PyMapping_GetOptionalItem (class_dict , name , & value_o );
1908+ int err ;
1909+ PyObject * value_o = _PyMapping_GetOptionalItem2 (class_dict , name , & err );
19091910 if (err < 0 ) {
19101911 ERROR_NO_POP ();
19111912 }
@@ -2074,14 +2075,14 @@ dummy_func(
20742075 }
20752076
20762077 inst (SETUP_ANNOTATIONS , (-- )) {
2077- PyObject * ann_dict ;
20782078 if (LOCALS () == NULL ) {
20792079 _PyErr_Format (tstate , PyExc_SystemError ,
20802080 "no locals found when setting up annotations" );
20812081 ERROR_IF (true);
20822082 }
20832083 /* check if __annotations__ in locals()... */
2084- int err = PyMapping_GetOptionalItem (LOCALS (), & _Py_ID (__annotations__ ), & ann_dict );
2084+ int err ;
2085+ PyObject * ann_dict = _PyMapping_GetOptionalItem2 (LOCALS (), & _Py_ID (__annotations__ ), & err );
20852086 ERROR_IF (err < 0 );
20862087 if (ann_dict == NULL ) {
20872088 ann_dict = PyDict_New ();
@@ -2185,8 +2186,12 @@ dummy_func(
21852186 }
21862187 // we make no attempt to optimize here; specializations should
21872188 // handle any case whose performance we care about
2188- PyObject * stack [] = {class , self };
2189- PyObject * super = PyObject_Vectorcall (global_super , stack , oparg & 2 , NULL );
2189+ PyObject * super ;
2190+ {
2191+ // scope to tell MSVC that stack is not escaping
2192+ PyObject * stack [] = {class , self };
2193+ super = PyObject_Vectorcall (global_super , stack , oparg & 2 , NULL );
2194+ }
21902195 if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR ) {
21912196 PyObject * arg = oparg & 2 ? class : & _PyInstrumentation_MISSING ;
21922197 if (super == NULL ) {
@@ -2245,8 +2250,13 @@ dummy_func(
22452250 PyObject * name = GETITEM (FRAME_CO_NAMES , oparg >> 2 );
22462251 PyTypeObject * cls = (PyTypeObject * )class ;
22472252 int method_found = 0 ;
2248- PyObject * attr_o = _PySuper_Lookup (cls , self , name ,
2249- Py_TYPE (self )-> tp_getattro == PyObject_GenericGetAttr ? & method_found : NULL );
2253+ PyObject * attr_o ;
2254+ {
2255+ // scope to tell MSVC that method_found_ptr is not escaping
2256+ int * method_found_ptr = & method_found ;
2257+ attr_o = _PySuper_Lookup (cls , self , name ,
2258+ Py_TYPE (self )-> tp_getattro == PyObject_GenericGetAttr ? method_found_ptr : NULL );
2259+ }
22502260 if (attr_o == NULL ) {
22512261 ERROR_NO_POP ();
22522262 }
@@ -3472,10 +3482,14 @@ dummy_func(
34723482 }
34733483 assert (PyStackRef_IsTaggedInt (lasti ));
34743484 (void )lasti ; // Shut up compiler warning if asserts are off
3475- PyObject * stack [5 ] = {NULL , PyStackRef_AsPyObjectBorrow (exit_self ), exc , val_o , tb };
3476- int has_self = !PyStackRef_IsNull (exit_self );
3477- PyObject * res_o = PyObject_Vectorcall (exit_func_o , stack + 2 - has_self ,
3478- (3 + has_self ) | PY_VECTORCALL_ARGUMENTS_OFFSET , NULL );
3485+ PyObject * res_o ;
3486+ {
3487+ // scope to tell MSVC that stack is not escaping
3488+ PyObject * stack [5 ] = {NULL , PyStackRef_AsPyObjectBorrow (exit_self ), exc , val_o , tb };
3489+ int has_self = !PyStackRef_IsNull (exit_self );
3490+ res_o = PyObject_Vectorcall (exit_func_o , stack + 2 - has_self ,
3491+ (3 + has_self ) | PY_VECTORCALL_ARGUMENTS_OFFSET , NULL );
3492+ }
34793493 Py_XDECREF (original_tb );
34803494 ERROR_IF (res_o == NULL );
34813495 res = PyStackRef_FromPyObjectSteal (res_o );
@@ -3707,36 +3721,18 @@ dummy_func(
37073721 frame -> return_offset = INSTRUCTION_SIZE ;
37083722 DISPATCH_INLINED (new_frame );
37093723 }
3710- /* Callable is not a normal Python function */
3711- STACKREFS_TO_PYOBJECTS (arguments , total_args , args_o );
3712- if (CONVERSION_FAILED (args_o )) {
3713- DECREF_INPUTS ();
3714- ERROR_IF (true);
3715- }
3716- PyObject * res_o = PyObject_Vectorcall (
3717- callable_o , args_o ,
3718- total_args | PY_VECTORCALL_ARGUMENTS_OFFSET ,
3719- NULL );
3720- STACKREFS_TO_PYOBJECTS_CLEANUP (args_o );
3721- if (opcode == INSTRUMENTED_CALL ) {
3722- PyObject * arg = total_args == 0 ?
3723- & _PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow (arguments [0 ]);
3724- if (res_o == NULL ) {
3725- _Py_call_instrumentation_exc2 (
3726- tstate , PY_MONITORING_EVENT_C_RAISE ,
3727- frame , this_instr , callable_o , arg );
3728- }
3729- else {
3730- int err = _Py_call_instrumentation_2args (
3731- tstate , PY_MONITORING_EVENT_C_RETURN ,
3732- frame , this_instr , callable_o , arg );
3733- if (err < 0 ) {
3734- Py_CLEAR (res_o );
3735- }
3736- }
3737- }
3738- assert ((res_o != NULL ) ^ (_PyErr_Occurred (tstate ) != NULL ));
3739- DECREF_INPUTS ();
3724+ PyObject * res_o = _Py_VectorCallInstrumentation_StackRefSteal (
3725+ callable ,
3726+ arguments ,
3727+ total_args ,
3728+ PyStackRef_NULL ,
3729+ opcode == INSTRUMENTED_CALL ,
3730+ frame ,
3731+ this_instr ,
3732+ tstate );
3733+ DEAD (args );
3734+ DEAD (self_or_null );
3735+ DEAD (callable );
37403736 ERROR_IF (res_o == NULL );
37413737 res = PyStackRef_FromPyObjectSteal (res_o );
37423738 }
@@ -4587,35 +4583,19 @@ dummy_func(
45874583 frame -> return_offset = INSTRUCTION_SIZE ;
45884584 DISPATCH_INLINED (new_frame );
45894585 }
4590- /* Callable is not a normal Python function */
4591- STACKREFS_TO_PYOBJECTS (arguments , total_args , args_o );
4592- if (CONVERSION_FAILED (args_o )) {
4593- DECREF_INPUTS ();
4594- ERROR_IF (true);
4595- }
4596- PyObject * res_o = PyObject_Vectorcall (
4597- callable_o , args_o ,
4598- positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET ,
4599- kwnames_o );
4600- STACKREFS_TO_PYOBJECTS_CLEANUP (args_o );
4601- if (opcode == INSTRUMENTED_CALL_KW ) {
4602- PyObject * arg = total_args == 0 ?
4603- & _PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow (arguments [0 ]);
4604- if (res_o == NULL ) {
4605- _Py_call_instrumentation_exc2 (
4606- tstate , PY_MONITORING_EVENT_C_RAISE ,
4607- frame , this_instr , callable_o , arg );
4608- }
4609- else {
4610- int err = _Py_call_instrumentation_2args (
4611- tstate , PY_MONITORING_EVENT_C_RETURN ,
4612- frame , this_instr , callable_o , arg );
4613- if (err < 0 ) {
4614- Py_CLEAR (res_o );
4615- }
4616- }
4617- }
4618- DECREF_INPUTS ();
4586+ PyObject * res_o = _Py_VectorCallInstrumentation_StackRefSteal (
4587+ callable ,
4588+ arguments ,
4589+ total_args ,
4590+ kwnames ,
4591+ opcode == INSTRUMENTED_CALL_KW ,
4592+ frame ,
4593+ this_instr ,
4594+ tstate );
4595+ DEAD (kwnames );
4596+ DEAD (args );
4597+ DEAD (self_or_null );
4598+ DEAD (callable );
46194599 ERROR_IF (res_o == NULL );
46204600 res = PyStackRef_FromPyObjectSteal (res_o );
46214601 }
0 commit comments