@@ -141,9 +141,11 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
141
141
return 1 ;
142
142
}
143
143
PyObject * globals = frame -> f_globals ;
144
- assert (PyFunction_Check (((PyFunctionObject * )frame -> f_funcobj )));
145
- assert (((PyFunctionObject * )frame -> f_funcobj )-> func_builtins == builtins );
146
- assert (((PyFunctionObject * )frame -> f_funcobj )-> func_globals == globals );
144
+ PyFunctionObject * function = (PyFunctionObject * )frame -> f_funcobj ;
145
+ assert (PyFunction_Check (function ));
146
+ assert (function -> func_builtins == builtins );
147
+ assert (function -> func_globals == globals );
148
+ uint32_t function_version = _PyFunction_GetVersionForCurrentState (function );
147
149
/* In order to treat globals as constants, we need to
148
150
* know that the globals dict is the one we expected, and
149
151
* that it hasn't changed
@@ -181,7 +183,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
181
183
}
182
184
else {
183
185
buffer [pc ].opcode = _CHECK_FUNCTION ;
184
- buffer [pc ].operand = ( uintptr_t ) builtins ;
186
+ buffer [pc ].operand = function_version ;
185
187
function_checked |= 1 ;
186
188
}
187
189
break ;
@@ -203,7 +205,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
203
205
}
204
206
else {
205
207
buffer [pc ].opcode = _CHECK_FUNCTION ;
206
- buffer [pc ].operand = ( uintptr_t ) globals ;
208
+ buffer [pc ].operand = function_version ;
207
209
function_checked |= 1 ;
208
210
}
209
211
break ;
@@ -227,7 +229,8 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
227
229
return 1 ;
228
230
}
229
231
assert (PyFunction_Check (func ));
230
- if (prechecked_function_version == func -> func_version ) {
232
+ function_version = func -> func_version ;
233
+ if (prechecked_function_version == function_version ) {
231
234
function_checked |= 1 ;
232
235
}
233
236
prechecked_function_version = 0 ;
@@ -245,6 +248,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
245
248
function_checked >>= 1 ;
246
249
PyFunctionObject * func = (PyFunctionObject * )buffer [pc ].operand ;
247
250
assert (PyFunction_Check (func ));
251
+ function_version = func -> func_version ;
248
252
globals = func -> func_globals ;
249
253
builtins = func -> func_builtins ;
250
254
break ;
0 commit comments