[pypy-issue] Issue #2000: bytecode changed but pyc version didn't in pypy 2.5.x (pypy/pypy)
Antonio Cuni
issues-reply at bitbucket.org
Tue Mar 17 15:29:32 CET 2015
New issue 2000: bytecode changed but pyc version didn't in pypy 2.5.x
https://bitbucket.org/pypy/pypy/issue/2000/bytecode-changed-but-pyc-version-didnt-in
Antonio Cuni:
PyPy 2.5.x compiles the statement ```exec(src, d)``` (i.e., when passing a tuple) differently than PyPy 2.5.0 and CPython. However, the pyc version is the same, which results in an exception when trying to import a pyc which was compiled with a previous version of PyPy.
To reproduce, create a file named ```execbug.py```
```
#!python
import sys
import dis
def foo(src, d):
exec(src, d)
print sys.version
dis.dis(foo)
foo('None', {})
print 'ALL OK'
```
Then, make sure that exebug.pyc does NOT exist, and execute the following with PyPy 2.5.0:
```
$ /tmp/pypy-2.5.0-linux64/bin/pypy -c 'import execbug'
2.7.8 (10f1b29a2bd2, Feb 02 2015, 21:22:43)
[PyPy 2.5.0 with GCC 4.6.3]
5 0 LOAD_FAST 0 (src)
3 LOAD_FAST 1 (d)
6 BUILD_TUPLE 2
9 LOAD_CONST 0 (None)
12 DUP_TOP
13 EXEC_STMT
14 LOAD_CONST 0 (None)
17 RETURN_VALUE
ALL OK
```
Now, if you try with pypy 2.5.1 (as well as the current trunk):
```
2.7.9 (5aed0a41060e, Mar 17 2015, 05:46:24)
[PyPy 2.5.1 with GCC 4.6.3]
5 0 LOAD_FAST 0 (src)
3 LOAD_FAST 1 (d)
6 BUILD_TUPLE 2
9 LOAD_CONST 0 (None)
12 DUP_TOP
13 EXEC_STMT
14 LOAD_CONST 0 (None)
17 RETURN_VALUE
Traceback (most recent call last):
File "<builtin>//app_main.py", line 75, in run_toplevel
File "<builtin>//app_main.py", line 588, in run_it
File "<string>", line 1, in <module>
File "execbug.py", line 9, in <module>
foo('None', {})
File "execbug.py", line 5, in foo
exec(src, d)
TypeError: exec: arg 1 must be a string, file, or code object
```
If you remove the .pyc, pypy 2.5.1 works well (note that the bytecode is different, not sure why)
```
$ /tmp/pypy-c-jit-76420-5aed0a41060e-linux64/bin/pypy -c 'import execbug'
2.7.9 (5aed0a41060e, Mar 17 2015, 05:46:24)
[PyPy 2.5.1 with GCC 4.6.3]
5 0 LOAD_FAST 0 (src)
3 LOAD_FAST 1 (d)
6 DUP_TOP
7 EXEC_STMT
8 LOAD_CONST 0 (None)
11 RETURN_VALUE
ALL OK
```
This is a serious bug, because it triggers random errors if someone upgrades from PyPy 2.5.0 to 2.5.1.
Note that this also breaks code like ```x=('None', {}); exec x```, which works fine on CPython and PyPy up to 2.5.0
More information about the pypy-issue
mailing list