Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.6
Changeset: r98500:e89bb6f7069c
Date: 2020-01-09 14:46 +0100
http://bitbucket.org/pypy/pypy/changeset/e89bb6f7069c/
Log: mergedefault
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -448,6 +448,10 @@
def get_empty_storage(self):
raise NotImplementedError
+ def setitem_str(self, w_dict, key, w_value):
+ w_dict.setitem(self.space.newtext(key), w_value)
+
+
@jit.look_inside_iff(lambda self, w_dict:
w_dict_unrolling_heuristic(w_dict))
def w_keys(self, w_dict):
diff --git a/pypy/objspace/std/jsondict.py b/pypy/objspace/std/jsondict.py
--- a/pypy/objspace/std/jsondict.py
+++ b/pypy/objspace/std/jsondict.py
@@ -89,6 +89,10 @@
self.switch_to_unicode_strategy(w_dict)
w_dict.setitem(w_key, w_value)
+ # for setitem_str use the default implementation
+ # because the jsonmap needs a wrapped key anyway
+
+
def setdefault(self, w_dict, w_key, w_default):
if self.is_correct_type(w_key):
w_result = self.getitem_unicode(w_dict, w_key)
diff --git a/pypy/objspace/std/test/test_jsondict.py
b/pypy/objspace/std/test/test_jsondict.py
--- a/pypy/objspace/std/test/test_jsondict.py
+++ b/pypy/objspace/std/test/test_jsondict.py
@@ -103,3 +103,16 @@
str(d)
repr(d)
+ def test_objdict_bug(self):
+ import _pypyjson
+ a = """{"foo": "bar"}"""
+ d = _pypyjson.loads(a)
+ d['foo'] = 'x'
+
+ class Obj(object):
+ pass
+
+ x = Obj()
+ x.__dict__ = d
+
+ x.foo = 'baz' # used to segfault on pypy3
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -1174,7 +1174,7 @@
def lshift(self, int_other):
if int_other < 0:
raise ValueError("negative shift count")
- elif int_other == 0:
+ elif int_other == 0 or self.sign == 0:
return self
# wordshift, remshift = divmod(int_other, SHIFT)
@@ -1183,8 +1183,6 @@
if not remshift:
# So we can avoid problems with eq, AND avoid the need for
normalize.
- if self.sign == 0:
- return self
return rbigint([NULLDIGIT] * wordshift + self._digits, self.sign,
self.numdigits() + wordshift)
oldsize = self.numdigits()
diff --git a/rpython/rlib/test/test_rbigint.py
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -704,6 +704,10 @@
# Chek value accuracy.
assert rbigint.fromlong(18446744073709551615L).rshift(1).tolong() ==
18446744073709551615L >> 1
+ def test_shift_optimization(self):
+ # does not crash with memory error
+ assert rbigint.fromint(0).lshift(sys.maxint).tolong() == 0
+
def test_qshift(self):
for x in range(10):
for y in range(1, 161, 16):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit