File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -2341,7 +2341,7 @@ def long_loop():
2341
2341
long_loop ()
2342
2342
self .assertEqual (opt .get_count (), 10 )
2343
2343
2344
- def test_code_richcompare (self ):
2344
+ def test_code_restore_for_ENTER_EXECUTOR (self ):
2345
2345
def testfunc (x ):
2346
2346
i = 0
2347
2347
while i < x :
@@ -2350,7 +2350,9 @@ def testfunc(x):
2350
2350
opt = _testinternalcapi .get_counter_optimizer ()
2351
2351
with temporary_optimizer (opt ):
2352
2352
testfunc (1000 )
2353
- self .assertEqual (testfunc .__code__ , testfunc .__code__ .replace ())
2353
+ code , replace_code = testfunc .__code__ , testfunc .__code__ .replace ()
2354
+ self .assertEqual (code , replace_code )
2355
+ self .assertEqual (hash (code ), hash (replace_code ))
2354
2356
2355
2357
2356
2358
def get_first_executor (func ):
Original file line number Diff line number Diff line change @@ -1884,9 +1884,20 @@ code_hash(PyCodeObject *co)
1884
1884
SCRAMBLE_IN (Py_SIZE (co ));
1885
1885
for (int i = 0 ; i < Py_SIZE (co ); i ++ ) {
1886
1886
int deop = _Py_GetBaseOpcode (co , i );
1887
- SCRAMBLE_IN (deop );
1888
- SCRAMBLE_IN (_PyCode_CODE (co )[i ].op .arg );
1889
- i += _PyOpcode_Caches [deop ];
1887
+ if (deop == ENTER_EXECUTOR ) {
1888
+ // Assume that deopt of ENTER_EXECUTOR will be ENTER_EXECUTOR.
1889
+ const int exec_index = _PyCode_CODE (co )[i ].op .arg ;
1890
+ _PyExecutorObject * exec = co -> co_executors -> executors [exec_index ];
1891
+ assert (exec != NULL );
1892
+ SCRAMBLE_IN (exec -> vm_data .opcode );
1893
+ SCRAMBLE_IN (exec -> vm_data .oparg );
1894
+ i += _PyOpcode_Caches [exec -> vm_data .opcode ];
1895
+ }
1896
+ else {
1897
+ SCRAMBLE_IN (deop );
1898
+ SCRAMBLE_IN (_PyCode_CODE (co )[i ].op .arg );
1899
+ i += _PyOpcode_Caches [deop ];
1900
+ }
1890
1901
}
1891
1902
if ((Py_hash_t )uhash == -1 ) {
1892
1903
return -2 ;
You can’t perform that action at this time.
0 commit comments