Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r86178:cd39a869a312 Date: 2016-08-12 20:59 +0200 http://bitbucket.org/pypy/pypy/changeset/cd39a869a312/
Log: Test and probable fix (thanks sbauman) diff --git a/rpython/rlib/rweakref.py b/rpython/rlib/rweakref.py --- a/rpython/rlib/rweakref.py +++ b/rpython/rlib/rweakref.py @@ -142,7 +142,7 @@ def compute_result_annotation(self, s_keyclass, s_valueclass): assert s_keyclass.is_constant() - s_key = self.bookkeeper.immutablevalue(s_keyclass.const()) + s_key = self.bookkeeper.valueoftype(s_keyclass.const) return SomeWeakValueDict( s_key, _getclassdef(s_valueclass)) @@ -158,7 +158,7 @@ bk = self.bookkeeper x = self.instance return SomeWeakValueDict( - bk.immutablevalue(x._keyclass()), + bk.valueoftype(x._keyclass), bk.getuniqueclassdef(x._valueclass)) def _getclassdef(s_instance): diff --git a/rpython/rlib/test/test_rweakvaldict.py b/rpython/rlib/test/test_rweakvaldict.py --- a/rpython/rlib/test/test_rweakvaldict.py +++ b/rpython/rlib/test/test_rweakvaldict.py @@ -180,3 +180,36 @@ RWeakValueDictionary(str, X).get("foobar") RWeakValueDictionary(int, Y).get(42) interpret(g, []) + +def test_key_instance(): + class K(object): + pass + keys = [K(), K(), K()] + + def g(d): + assert d.get(keys[3]) is None + x1 = X(); x2 = X(); x3 = X() + d.set(keys[0], x1) + d.set(keys[1], x2) + d.set(keys[2], x3) + assert d.get(keys[0]) is x1 + assert d.get(keys[1]) is x2 + assert d.get(keys[2]) is x3 + assert d.get(keys[3]) is None + return x1, x3 # x2 dies + def f(): + keys.append(K()) + d = RWeakValueDictionary(K, X) + x1, x3 = g(d) + rgc.collect(); rgc.collect() + assert d.get(keys[0]) is x1 + assert d.get(keys[1]) is None + assert d.get(keys[2]) is x3 + assert d.get(keys[3]) is None + d.set(keys[0], None) + assert d.get(keys[0]) is None + assert d.get(keys[1]) is None + assert d.get(keys[2]) is x3 + assert d.get(keys[3]) is None + f() + interpret(f, []) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit