classification
Title: big code objects (>64K) may be optimized incorrectly
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: cezary, rhettinger, tim.peters
Priority: normal Keywords: patch

Created on 2004-08-05 17:46 by cezary, last changed 2004-08-06 19:47 by rhettinger. This issue is now closed.

Files
File name Uploaded Description Edit
c.py cezary, 2004-08-05 17:46 A script to generate example large function.
compile.c.patch cezary, 2004-08-05 18:13 untested pach
Messages (5)
msg46558 - (view) Author: Cezary Biernacki (cezary) Date: 2004-08-05 17:46
Large functions with size of a bytecode bigger than
65535 bytes may be incorrectly optimized by
"optimize_code" in "Python/compile.c". Optimalization
happens automaticaly during loading from *.pyc and
cannot be disabled. Codes loaded directly from source
(*.py) are not optimalized and not affected by this bug.

One of task of "optimize_code" is to eliminate
"chained" jumps  (when one of jumps points directly to
unconditional jump). Problems occurs when a first jump
opcode points to JUMP_FORWARD, which target is after
64K boundary. This target adress is copied as absolute
address of the first jump modulo 2**16.

This bug can lead to different symptoms during
execution of a code. You can get an "unknown opcode"
error, but  sometimes results can be unpredicable.

This problem appears in Python 2.3 (tested) and
possibly in 2.4 (alfa). 

Attached scripts generates large functions a writes
disassebles before and after optimalization. You will
find, that some adresses after optimalization are bad. 
 
msg46559 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-08-05 17:53
Logged In: YES 
user_id=31435

Raised priority and assigned to Raymond.  I haven't verified 
the claim, but it sounds more plausible than not, and is a 
critical bug if so.
msg46560 - (view) Author: Cezary Biernacki (cezary) Date: 2004-08-05 17:59
Logged In: YES 
user_id=738

untested (sorry - no C compiler at hand) posted - see patch
"1004095"
msg46561 - (view) Author: Cezary Biernacki (cezary) Date: 2004-08-05 18:13
Logged In: YES 
user_id=738

Attached a missing patch. Untested!
msg46562 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-06 19:47
Logged In: YES 
user_id=80475

Thanks for the report and patch.
Fixed in Python/compile.c 2.314
Will backport to Py2.3
History
Date User Action Args
2004-08-05 17:46:31cezarycreate