[Python-checkins] r54085 - in python/branches/release25-maint: Lib/test/test_peepholer.py Misc/NEWS Python/compile.c
raymond.hettinger
python-checkins at python.org
Fri Mar 2 20:19:06 CET 2007
Author: raymond.hettinger
Date: Fri Mar 2 20:19:05 2007
New Revision: 54085
Modified:
python/branches/release25-maint/Lib/test/test_peepholer.py
python/branches/release25-maint/Misc/NEWS
python/branches/release25-maint/Python/compile.c
Log:
Fix constantification of None.
Modified: python/branches/release25-maint/Lib/test/test_peepholer.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_peepholer.py (original)
+++ python/branches/release25-maint/Lib/test/test_peepholer.py Fri Mar 2 20:19:05 2007
@@ -49,6 +49,11 @@
self.assert_(elem not in asm)
for elem in ('LOAD_CONST', '(None)'):
self.assert_(elem in asm)
+ def f():
+ 'Adding a docstring made this test fail in Py2.5.0'
+ return None
+ self.assert_('LOAD_CONST' in disassemble(f))
+ self.assert_('LOAD_GLOBAL' not in disassemble(f))
def test_while_one(self):
# Skip over: LOAD_CONST trueconst JUMP_IF_FALSE xx POP_TOP
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS (original)
+++ python/branches/release25-maint/Misc/NEWS Fri Mar 2 20:19:05 2007
@@ -15,6 +15,9 @@
- Bug #1669182: prevent crash when trying to print an unraisable error
from a string exception.
+- The peephole optimizer left None as a global in functions with a docstring
+ and an explicit return value.
+
- Bug #1653736: Properly discard third argument to slot_nb_inplace_power.
- SF #151204: enumerate() now raises an Overflow error at sys.maxint items.
Modified: python/branches/release25-maint/Python/compile.c
==============================================================================
--- python/branches/release25-maint/Python/compile.c (original)
+++ python/branches/release25-maint/Python/compile.c Fri Mar 2 20:19:05 2007
@@ -773,13 +773,17 @@
if (name == NULL || strcmp(name, "None") != 0)
continue;
for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) {
- if (PyList_GET_ITEM(consts, j) == Py_None) {
- codestr[i] = LOAD_CONST;
- SETARG(codestr, i, j);
- cumlc = lastlc + 1;
+ if (PyList_GET_ITEM(consts, j) == Py_None)
break;
- }
}
+ if (j == PyList_GET_SIZE(consts)) {
+ if (PyList_Append(consts, Py_None) == -1)
+ goto exitUnchanged;
+ }
+ assert(PyList_GET_ITEM(consts, j) == Py_None);
+ codestr[i] = LOAD_CONST;
+ SETARG(codestr, i, j);
+ cumlc = lastlc + 1;
break;
/* Skip over LOAD_CONST trueconst
More information about the Python-checkins
mailing list