[pypy-svn] r14793 - in pypy/dist/pypy/rpython: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Jul 19 21:56:34 CEST 2005


Author: pedronis
Date: Tue Jul 19 21:56:28 2005
New Revision: 14793

Modified:
   pypy/dist/pypy/rpython/rbool.py
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/rclass.py
   pypy/dist/pypy/rpython/rdict.py
   pypy/dist/pypy/rpython/rfloat.py
   pypy/dist/pypy/rpython/rint.py
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/rmodel.py
   pypy/dist/pypy/rpython/robject.py
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/rptr.py
   pypy/dist/pypy/rpython/rslice.py
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/rtuple.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/rpython/test/test_rtyper.py
Log:
avoid obscure repr keys clashes, with basic test



Modified: pypy/dist/pypy/rpython/rbool.py
==============================================================================
--- pypy/dist/pypy/rpython/rbool.py	(original)
+++ pypy/dist/pypy/rpython/rbool.py	Tue Jul 19 21:56:28 2005
@@ -11,7 +11,7 @@
     def rtyper_makerepr(self, rtyper):
         return bool_repr
     def rtyper_makekey(self):
-        return None
+        return self.__class__,
 
 bool_repr = BoolRepr()
 

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Tue Jul 19 21:56:28 2005
@@ -26,10 +26,10 @@
     def rtyper_makekey(self):
         if self.s_self is None:
             # built-in function case
-            return getattr(self, 'const', None)
+            return self.__class__, getattr(self, 'const', None)
         else:
             # built-in method case
-            return (self.methodname, self.s_self.rtyper_makekey())
+            return (self.__class__, self.methodname, self.s_self.rtyper_makekey())
 
 
 class BuiltinFunctionRepr(Repr):

Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py	(original)
+++ pypy/dist/pypy/rpython/rclass.py	Tue Jul 19 21:56:28 2005
@@ -341,7 +341,7 @@
     def rtyper_makerepr(self, rtyper):
         return getinstancerepr(rtyper, self.classdef)
     def rtyper_makekey(self):
-        return self.classdef
+        return self.__class__, self.classdef
 
 
 class InstanceRepr(Repr):

Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py	(original)
+++ pypy/dist/pypy/rpython/rdict.py	Tue Jul 19 21:56:28 2005
@@ -50,7 +50,7 @@
             raise rmodel.TyperError("cannot make repr of %r" %(self.dictdef,))
 
     def rtyper_makekey(self):
-        return (self.dictdef.dictkey, self.dictdef.dictvalue)
+        return (self.__class__, self.dictdef.dictkey, self.dictdef.dictvalue)
 
 class StrDictRepr(rmodel.Repr):
 

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Tue Jul 19 21:56:28 2005
@@ -15,7 +15,7 @@
     def rtyper_makerepr(self, rtyper):
         return float_repr
     def rtyper_makekey(self):
-        return None
+        return self.__class__,
 
 
 float_repr = FloatRepr()

Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Tue Jul 19 21:56:28 2005
@@ -18,7 +18,7 @@
         else:
             return signed_repr
     def rtyper_makekey(self):
-        return self.unsigned
+        return self.__class__, self.unsigned
 
 signed_repr = IntegerRepr()
 unsigned_repr = IntegerRepr()

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Tue Jul 19 21:56:28 2005
@@ -40,7 +40,7 @@
                             listitem)
 
     def rtyper_makekey(self):
-        return self.listdef.listitem
+        return self.__class__, self.listdef.listitem
 
 
 class ListRepr(Repr):

Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py	(original)
+++ pypy/dist/pypy/rpython/rmodel.py	Tue Jul 19 21:56:28 2005
@@ -115,13 +115,13 @@
         r_container = rtyper.getrepr(self.s_container)
         return r_container.make_iterator_repr()
     def rtyper_makekey(self):
-        return self.s_container.rtyper_makekey()
+        return self.__class__, self.s_container.rtyper_makekey()
 
 class __extend__(annmodel.SomeImpossibleValue):
     def rtyper_makerepr(self, rtyper):
         return impossible_repr
     def rtyper_makekey(self):
-        return None
+        return self.__class__,
 
 # ____ generic binary operations _____________________________
 

Modified: pypy/dist/pypy/rpython/robject.py
==============================================================================
--- pypy/dist/pypy/rpython/robject.py	(original)
+++ pypy/dist/pypy/rpython/robject.py	Tue Jul 19 21:56:28 2005
@@ -16,11 +16,11 @@
             return pyobj_repr
     def rtyper_makekey(self):
         if self.is_constant():
-            return "const"
+            return self.__class__, "const"
         if self.knowntype is type:
-            return "type"
+            return self.__class__, "type"
         else:
-            return "pyobj"
+            return self.__class__, "pyobj"
 
 
 class PyObjRepr(Repr):

Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Tue Jul 19 21:56:28 2005
@@ -88,7 +88,7 @@
     def rtyper_makekey(self):
         lst = self.prebuiltinstances.items()
         lst.sort()
-        return tuple(lst)
+        return tuple([self.__class__]+lst)
 
 builtin_descriptor_type = (
     type(len),                             # type 'builtin_function_or_method'

Modified: pypy/dist/pypy/rpython/rptr.py
==============================================================================
--- pypy/dist/pypy/rpython/rptr.py	(original)
+++ pypy/dist/pypy/rpython/rptr.py	Tue Jul 19 21:56:28 2005
@@ -15,7 +15,7 @@
 ##        if self.is_constant() and not self.const:
 ##            return None
 ##        else:
-        return self.ll_ptrtype
+        return self.__class__, self.ll_ptrtype
 
 
 class PtrRepr(Repr):

Modified: pypy/dist/pypy/rpython/rslice.py
==============================================================================
--- pypy/dist/pypy/rpython/rslice.py	(original)
+++ pypy/dist/pypy/rpython/rslice.py	Tue Jul 19 21:56:28 2005
@@ -39,7 +39,8 @@
         else:
             return startstop_slice_repr
     def rtyper_makekey(self):
-        return (self.start.rtyper_makekey(),
+        return (self.__class__,
+                self.start.rtyper_makekey(),
                 self.stop.rtyper_makekey(),
                 self.step.rtyper_makekey())
 

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Tue Jul 19 21:56:28 2005
@@ -34,19 +34,19 @@
     def rtyper_makerepr(self, rtyper):
         return string_repr
     def rtyper_makekey(self):
-        return None
+        return self.__class__,
 
 class __extend__(annmodel.SomeChar):
     def rtyper_makerepr(self, rtyper):
         return char_repr
     def rtyper_makekey(self):
-        return None
+        return self.__class__,
 
 class __extend__(annmodel.SomeUnicodeCodePoint):
     def rtyper_makerepr(self, rtyper):
         return unichar_repr
     def rtyper_makekey(self):
-        return None
+        return self.__class__,
 
 CONST_STR_CACHE = WeakValueDictionary()
 string_repr = StringRepr()

Modified: pypy/dist/pypy/rpython/rtuple.py
==============================================================================
--- pypy/dist/pypy/rpython/rtuple.py	(original)
+++ pypy/dist/pypy/rpython/rtuple.py	Tue Jul 19 21:56:28 2005
@@ -23,7 +23,7 @@
     
     def rtyper_makekey(self):
         keys = [s_item.rtyper_makekey() for s_item in self.items]
-        return tuple(keys)
+        return tuple([self.__class__]+keys)
 
 
 class TupleRepr(Repr):

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Tue Jul 19 21:56:28 2005
@@ -78,7 +78,8 @@
 
     def getrepr(self, s_obj):
         # s_objs are not hashable... try hard to find a unique key anyway
-        key = s_obj.__class__, s_obj.rtyper_makekey()
+        key = s_obj.rtyper_makekey()
+        assert key[0] == s_obj.__class__
         try:
             result = self.reprs[key]
         except KeyError:

Modified: pypy/dist/pypy/rpython/test/test_rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rtyper.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rtyper.py	Tue Jul 19 21:56:28 2005
@@ -13,6 +13,15 @@
 def teardown_module(mod): 
     py.log._setstate(mod.logstate) 
 
+def test_reprkey_dont_clash():
+    stup1 = annmodel.SomeTuple((annmodel.SomeFloat(), 
+                                annmodel.SomeInteger()))
+    stup2 = annmodel.SomeTuple((annmodel.SomeString(), 
+                                annmodel.SomeInteger()))
+    key1 = stup1.rtyper_makekey()
+    key2 = stup2.rtyper_makekey()
+    assert key1 != key2
+
 def test_simple():
     def dummyfn(x):
         return x+1



More information about the Pypy-commit mailing list