[pypy-svn] r58042 - pypy/branch/tuple-nonresizable-395/pypy/interpreter
fijal at codespeak.net
fijal at codespeak.net
Wed Sep 10 18:51:41 CEST 2008
Author: fijal
Date: Wed Sep 10 18:51:39 2008
New Revision: 58042
Modified:
pypy/branch/tuple-nonresizable-395/pypy/interpreter/argument.py
pypy/branch/tuple-nonresizable-395/pypy/interpreter/pycode.py
Log:
Make sure pycode slots and arguments are never modified.
Modified: pypy/branch/tuple-nonresizable-395/pypy/interpreter/argument.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/interpreter/argument.py (original)
+++ pypy/branch/tuple-nonresizable-395/pypy/interpreter/argument.py Wed Sep 10 18:51:39 2008
@@ -271,9 +271,9 @@
if has_vararg:
if upfront > co_argcount:
assert extravarargs is not None
- stararg_w = extravarargs
+ stararg_w = extravarargs + [None] * self.nargs
for i in range(self.nargs):
- stararg_w.append(self.frame.peekvalue(self.nargs - 1 - i))
+ stararg_w[i + len(extravarargs)] = self.frame.peekvalue(self.nargs - 1 - i)
else:
args_left = co_argcount - upfront
stararg_w = [None] * (avail - co_argcount)
Modified: pypy/branch/tuple-nonresizable-395/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/interpreter/pycode.py (original)
+++ pypy/branch/tuple-nonresizable-395/pypy/interpreter/pycode.py Wed Sep 10 18:51:39 2008
@@ -11,15 +11,12 @@
from pypy.interpreter.gateway import NoneNotWrapped
from pypy.interpreter.baseobjspace import ObjSpace, W_Root
from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.debug import make_sure_not_resized
# helper
def unpack_str_tuple(space,w_str_tuple):
- els = []
- for w_el in space.unpackiterable(w_str_tuple):
- els.append(space.str_w(w_el))
- return els
-
+ return [space.str_w(w_el) for w_el in space.unpackiterable(w_str_tuple)]
# code object contants, for co_flags below
CO_OPTIMIZED = 0x0001
@@ -66,7 +63,7 @@
self.co_stacksize = stacksize
self.co_flags = flags
self.co_code = code
- self.co_consts_w = consts
+ self.co_consts_w = make_sure_not_resized(consts)
self.co_names_w = [space.new_interned_str(aname) for aname in names]
self.co_varnames = varnames
self.co_freevars = freevars
@@ -122,12 +119,13 @@
This method is called by our compile builtin function.
"""
assert isinstance(code, types.CodeType)
- newconsts_w = []
+ newconsts_w = [None] * len(code.co_consts)
+ num = 0
for const in code.co_consts:
if isinstance(const, types.CodeType): # from stable compiler
const = PyCode._from_code(space, const, hidden_applevel=hidden_applevel)
-
- newconsts_w.append(space.wrap(const))
+ newconsts_w[num] = space.wrap(const)
+ num += 1
# stick the underlying CPython magic value, if the code object
# comes from there
return PyCode(space, code.co_argcount,
@@ -213,12 +211,14 @@
def _to_code(self):
"""For debugging only."""
- consts = []
+ consts = [None] * len(self.co_consts_w)
+ num = 0
for w in self.co_consts_w:
if isinstance(w, PyCode):
- consts.append(w._to_code())
+ consts[num] = w._to_code()
else:
- consts.append(self.space.unwrap(w))
+ consts[num] = self.space.unwrap(w)
+ num += 1
return new.code( self.co_argcount,
self.co_nlocals,
self.co_stacksize,
@@ -240,10 +240,10 @@
dis.dis(co)
def fget_co_consts(space, self):
- return space.newtuple(self.co_consts_w[:])
+ return space.newtuple(self.co_consts_w)
def fget_co_names(space, self):
- return space.newtuple(self.co_names_w[:])
+ return space.newtuple(self.co_names_w)
def fget_co_varnames(space, self):
return space.newtuple([space.wrap(name) for name in self.co_varnames])
@@ -321,8 +321,11 @@
space.wrap("code: argcount must not be negative"))
if nlocals < 0:
raise OperationError(space.w_ValueError,
- space.wrap("code: nlocals must not be negative"))
- consts_w = space.unpacktuple(w_constants)
+ space.wrap("code: nlocals must not be negative"))
+ if not space.is_true(space.isinstance(w_constants, space.w_tuple)):
+ raise OperationError(space.w_TypeError,
+ space.wrap("Expected tuple for constants"))
+ consts_w = space.viewiterable(w_constants)
names = unpack_str_tuple(space, w_names)
varnames = unpack_str_tuple(space, w_varnames)
if w_freevars is not None:
@@ -351,8 +354,8 @@
w(self.co_stacksize),
w(self.co_flags),
w(self.co_code),
- space.newtuple(self.co_consts_w[:]),
- space.newtuple(self.co_names_w[:]),
+ space.newtuple(self.co_consts_w),
+ space.newtuple(self.co_names_w),
space.newtuple([w(v) for v in self.co_varnames]),
w(self.co_filename),
w(self.co_name),
More information about the Pypy-commit
mailing list