File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -2341,7 +2341,7 @@ def long_loop():
23412341 long_loop ()
23422342 self .assertEqual (opt .get_count (), 10 )
23432343
2344- def test_code_richcompare (self ):
2344+ def test_code_restore_for_ENTER_EXECUTOR (self ):
23452345 def testfunc (x ):
23462346 i = 0
23472347 while i < x :
@@ -2350,7 +2350,9 @@ def testfunc(x):
23502350 opt = _testinternalcapi .get_counter_optimizer ()
23512351 with temporary_optimizer (opt ):
23522352 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 ))
23542356
23552357
23562358def get_first_executor (func ):
Original file line number Diff line number Diff line change @@ -1884,9 +1884,20 @@ code_hash(PyCodeObject *co)
18841884 SCRAMBLE_IN (Py_SIZE (co ));
18851885 for (int i = 0 ; i < Py_SIZE (co ); i ++ ) {
18861886 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+ }
18901901 }
18911902 if ((Py_hash_t )uhash == -1 ) {
18921903 return -2 ;
You can’t perform that action at this time.
0 commit comments