Author: l.diekmann
Branch: type-specialized-instances
Changeset: r52013:ed1dbd45c349
Date: 2012-02-01 12:48 +0000
http://bitbucket.org/pypy/pypy/changeset/ed1dbd45c349/
Log: fixed OverflowError for type-specialized instances
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -29,26 +29,29 @@
self.terminator = terminator
def read(self, obj, selector):
- attr = self.findmap(selector) # index = self.index(selector)
+ attr = self.findmap(selector)
if attr is None:
return self.terminator._read_terminator(obj, selector)
- return attr.read_attr(obj) #obj._mapdict_read_storage(index)
+ return attr.read_attr(obj)
def write(self, obj, selector, w_value):
from pypy.interpreter.error import OperationError
- attr = self.findmap(selector) # index = self.index(selector)
+ attr = self.findmap(selector)
if attr is None:
return self.terminator._write_terminator(obj, selector, w_value)
try:
- attr.write_attr(obj, w_value) #obj._mapdict_write_storage(index,
w_value)
+ attr.write_attr(obj, w_value)
except OperationError, e:
if not e.match(self.space, self.space.w_TypeError):
raise
- firstattr = obj._get_mapdict_map()
- firstattr.delete(obj, selector)
- firstattr.add_attr(obj, selector, w_value)
+ self._replace(obj, selector, w_value)
return True
+ def _replace(self, obj, selector, w_value):
+ firstattr = obj._get_mapdict_map()
+ firstattr.delete(obj, selector)
+ firstattr.add_attr(obj, selector, w_value)
+
def delete(self, obj, selector):
return None
@@ -362,6 +365,9 @@
return self.space.wrap(value)
def write_attr(self, obj, w_value):
+ if not is_taggable_int(self.space, w_value):
+ self._replace(obj, self.selector, w_value)
+ return
erased = self.erase_item(self.space.int_w(w_value))
obj._mapdict_write_storage(self.position, erased)
diff --git a/pypy/objspace/std/test/test_mapdict.py
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -776,6 +776,16 @@
assert a.x == 5
+ def test_too_large_int(self):
+ class A(object):
+ def __init__(self):
+ self.x = 1
+
+ a = A()
+ a.x = 1234567890L
+
+ assert a.x == 1234567890L
+
class AppTestWithMapDictAndCounters(object):
def setup_class(cls):
from pypy.interpreter import gateway
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit