[pypy-svn] r68821 - in pypy/branch/shrink-multidict/pypy: interpreter jit/tl module/__builtin__ objspace objspace/std objspace/std/test translator/goal

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Oct 28 16:21:36 CET 2009


Author: cfbolz
Date: Wed Oct 28 16:21:35 2009
New Revision: 68821

Modified:
   pypy/branch/shrink-multidict/pypy/interpreter/baseobjspace.py
   pypy/branch/shrink-multidict/pypy/interpreter/pyopcode.py
   pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit.py
   pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit_demo.py
   pypy/branch/shrink-multidict/pypy/module/__builtin__/interp_classobj.py
   pypy/branch/shrink-multidict/pypy/objspace/descroperation.py
   pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py
   pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/objspace.py
   pypy/branch/shrink-multidict/pypy/objspace/std/proxyobject.py
   pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py
   pypy/branch/shrink-multidict/pypy/objspace/taint.py
   pypy/branch/shrink-multidict/pypy/translator/goal/gcbench.py
Log:
Change setdictvalue to also take a string. Now it's asymmetric to deldictvalue,
I might not care though.


Modified: pypy/branch/shrink-multidict/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/shrink-multidict/pypy/interpreter/baseobjspace.py	Wed Oct 28 16:21:35 2009
@@ -34,10 +34,10 @@
     def getdictvalue_attr_is_in_class(self, space, attr):
         return self.getdictvalue(space, attr)
 
-    def setdictvalue(self, space, w_attr, w_value, shadows_type=True):
+    def setdictvalue(self, space, attr, w_value, shadows_type=True):
         w_dict = self.getdict()
         if w_dict is not None:
-            space.set_str_keyed_item(w_dict, w_attr, w_value, shadows_type)
+            space.set_str_keyed_item(w_dict, attr, w_value, shadows_type)
             return True
         return False
 
@@ -563,8 +563,8 @@
         """shortcut for space.int_w(space.hash(w_obj))"""
         return self.int_w(self.hash(w_obj))
 
-    def set_str_keyed_item(self, w_obj, w_key, w_value, shadows_type=True):
-        return self.setitem(w_obj, w_key, w_value)
+    def set_str_keyed_item(self, w_obj, key, w_value, shadows_type=True):
+        return self.setitem(w_obj, self.wrap(key), w_value)
 
     def finditem_str(self, w_obj, key):
         return self.finditem(w_obj, self.wrap(key))

Modified: pypy/branch/shrink-multidict/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/shrink-multidict/pypy/interpreter/pyopcode.py	Wed Oct 28 16:21:35 2009
@@ -619,9 +619,9 @@
         f.pushvalue(w_newclass)
 
     def STORE_NAME(f, varindex, *ignored):
-        w_varname = f.getname_w(varindex)
+        varname = f.getname_u(varindex)
         w_newvalue = f.popvalue()
-        f.space.set_str_keyed_item(f.w_locals, w_varname, w_newvalue)
+        f.space.set_str_keyed_item(f.w_locals, varname, w_newvalue)
 
     def DELETE_NAME(f, varindex, *ignored):
         w_varname = f.getname_w(varindex)
@@ -656,9 +656,9 @@
         f.space.delattr(w_obj, w_attributename)
 
     def STORE_GLOBAL(f, nameindex, *ignored):
-        w_varname = f.getname_w(nameindex)
+        varname = f.getname_u(nameindex)
         w_newvalue = f.popvalue()
-        f.space.set_str_keyed_item(f.w_globals, w_varname, w_newvalue)
+        f.space.set_str_keyed_item(f.w_globals, varname, w_newvalue)
 
     def DELETE_GLOBAL(f, nameindex, *ignored):
         w_varname = f.getname_w(nameindex)

Modified: pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit.py	(original)
+++ pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit.py	Wed Oct 28 16:21:35 2009
@@ -41,6 +41,7 @@
 config.objspace.usemodules._weakref = False
 config.objspace.usemodules._sre = False
 set_pypy_opt_level(config, level='jit')
+config.objspace.std.withinlineddict = True
 
 if BACKEND == 'c':
     config.objspace.std.multimethods = 'mrd'

Modified: pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit_demo.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit_demo.py	(original)
+++ pypy/branch/shrink-multidict/pypy/jit/tl/pypyjit_demo.py	Wed Oct 28 16:21:35 2009
@@ -1,7 +1,6 @@
 base = object
 
 class Number(base):
-    __slots__ = ('val', )
     def __init__(self, val=0):
         self.val = val
 
@@ -28,10 +27,10 @@
     return x
 
 import time
-#t1 = time.time()
-#f(10000000, Number(), 1)
-#t2 = time.time()
-#print t2 - t1
+t1 = time.time()
+f(10000000, Number(), 1)
+t2 = time.time()
+print t2 - t1
 t1 = time.time()
 f(10000000, 0, 1)
 t2 = time.time()

Modified: pypy/branch/shrink-multidict/pypy/module/__builtin__/interp_classobj.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/module/__builtin__/interp_classobj.py	(original)
+++ pypy/branch/shrink-multidict/pypy/module/__builtin__/interp_classobj.py	Wed Oct 28 16:21:35 2009
@@ -383,7 +383,7 @@
         if w_meth is not None:
             space.call_function(w_meth, w_name, w_value)
         else:
-            self.setdictvalue(space, w_name, w_value)
+            self.setdictvalue(space, name, w_value)
 
     def descr_delattr(self, space, w_name):
         name = unwrap_attr(space, w_name)

Modified: pypy/branch/shrink-multidict/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/descroperation.py	Wed Oct 28 16:21:35 2009
@@ -54,7 +54,7 @@
                 space.set(w_descr, w_obj, w_value)
                 return
             shadows_type = True
-        if w_obj.setdictvalue(space, w_name, w_value, shadows_type):
+        if w_obj.setdictvalue(space, name, w_value, shadows_type):
             return
         raiseattrerror(space, w_obj, name, w_descr)
 

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py	Wed Oct 28 16:21:35 2009
@@ -46,12 +46,11 @@
     def impl_setitem(self, w_key, w_value):
         space = self.space
         if space.is_w(space.type(w_key), space.w_str):
-            self.impl_setitem_str(w_key, w_value)
+            self.impl_setitem_str(self.space.str_w(w_key), w_value)
         else:
             self._as_rdict().setitem(w_key, w_value)
 
-    def impl_setitem_str(self, w_key, w_value, shadows_type=True):
-        name = self.space.str_w(w_key)
+    def impl_setitem_str(self, name, w_value, shadows_type=True):
         self.getcell(name).w_value = w_value
         
         if name in self.unshadowed_builtins:
@@ -221,5 +220,5 @@
         if cell is not None:
             f.cache_for_globals[nameindex] = cell
             return cell.w_value
-    return f._load_global(f.getname_w(nameindex))
+    return f._load_global(f.getname_u(nameindex))
 load_global_fill_cache._dont_inline_ = True

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py	Wed Oct 28 16:21:35 2009
@@ -100,8 +100,8 @@
         else:
             return None
 
-    def set_str_keyed_item(w_dict, w_key, w_value, shadows_type=True):
-        w_dict.setitem_str(w_key, w_value, shadows_type)
+    def set_str_keyed_item(w_dict, key, w_value, shadows_type=True):
+        w_dict.setitem_str(key, w_value, shadows_type)
 
     # _________________________________________________________________ 
     # implementation methods
@@ -113,7 +113,7 @@
         #return w_value or None
         raise NotImplementedError("abstract base class")
 
-    def impl_setitem_str(self,  w_key, w_value, shadows_type=True):
+    def impl_setitem_str(self,  key, w_value, shadows_type=True):
         raise NotImplementedError("abstract base class")
 
     def impl_setitem(self,  w_key, w_value):
@@ -179,8 +179,8 @@
     def impl_fallback_setitem(self, w_key, w_value):
         self.r_dict_content[w_key] = w_value
 
-    def impl_fallback_setitem_str(self, w_key, w_value, shadows_type=True):
-        return self.impl_fallback_setitem(w_key, w_value)
+    def impl_fallback_setitem_str(self, key, w_value, shadows_type=True):
+        return self.impl_fallback_setitem(self.space.wrap(key), w_value)
 
     def impl_fallback_delitem(self, w_key):
         del self.r_dict_content[w_key]
@@ -309,12 +309,12 @@
     def impl_setitem(self, w_key, w_value):
         space = self.space
         if space.is_w(space.type(w_key), space.w_str):
-            self.impl_setitem_str(w_key, w_value)
+            self.impl_setitem_str(self.space.str_w(w_key), w_value)
         else:
             self._as_rdict().setitem(w_key, w_value)
 
-    def impl_setitem_str(self, w_key, w_value, shadows_type=True):
-        self.content[self.space.str_w(w_key)] = w_value
+    def impl_setitem_str(self, key, w_value, shadows_type=True):
+        self.content[key] = w_value
 
     def impl_delitem(self, w_key):
         space = self.space
@@ -396,11 +396,11 @@
         else:
             self._shadows_anything = False
 
-    def impl_setitem_str(self, w_key, w_value, shadows_type=True):
+    def impl_setitem_str(self, key, w_value, shadows_type=True):
         if shadows_type:
             self._shadows_anything = True
         StrDictImplementation.impl_setitem_str(
-            self, w_key, w_value, shadows_type)
+            self, key, w_value, shadows_type)
 
     def impl_setitem(self, w_key, w_value):
         space = self.space
@@ -410,7 +410,7 @@
                 if w_obj is not None:
                     self._shadows_anything = True
             StrDictImplementation.impl_setitem_str(
-                self, w_key, w_value, False)
+                self, self.space.str_w(w_key), w_value, False)
         else:
             self._as_rdict().setitem(w_key, w_value)
 
@@ -426,8 +426,7 @@
         StrDictImplementation.__init__(self, space)
         self.shadowed = [None] * len(BUILTIN_TO_INDEX)
 
-    def impl_setitem_str(self, w_key, w_value, shadows_type=True):
-        key = self.space.str_w(w_key)
+    def impl_setitem_str(self, key, w_value, shadows_type=True):
         i = BUILTIN_TO_INDEX.get(key, -1)
         if i != -1:
             self.shadowed[i] = w_value
@@ -557,9 +556,9 @@
         self.info.writes += 1
         self.content[w_key] = w_value
         self.info.maxcontents = max(self.info.maxcontents, len(self.content))
-    def impl_setitem_str(self, w_key, w_value, shadows_type=True):
+    def impl_setitem_str(self, key, w_value, shadows_type=True):
         self.info.setitem_strs += 1
-        self.impl_setitem(w_key, w_value)
+        self.impl_setitem(self.space.wrap(key), w_value)
     def impl_delitem(self, w_key):
         if not self.info.seen_non_string_in_write \
                and not self.info.seen_non_string_in_read_first \

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py	Wed Oct 28 16:21:35 2009
@@ -92,10 +92,10 @@
         def getdictvalue_attr_is_in_class(self, space, attr):
             return self.getdictvalue(space, attr)
 
-        def setdictvalue(self, space, w_attr, w_value, shadows_type=True):
+        def setdictvalue(self, space, attr, w_value, shadows_type=True):
             if self._inlined_dict_valid():
                 # XXX don't ignore shadows_type
-                self.impl_setitem(w_attr, w_value)
+                self.impl_setitem_str(attr, w_value)
                 return True
             w_dict = self.getdict()
             w_dict.setitem(w_attr, w_value)

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/objspace.py	Wed Oct 28 16:21:35 2009
@@ -743,13 +743,13 @@
             return w_obj.getitem(w_key)
         return ObjSpace.finditem(self, w_obj, w_key)
 
-    def set_str_keyed_item(self, w_obj, w_key, w_value, shadows_type=True):
+    def set_str_keyed_item(self, w_obj, key, w_value, shadows_type=True):
         # performance shortcut to avoid creating the OperationError(KeyError)
         if (isinstance(w_obj, self.DictObjectCls) and
                 not w_obj.user_overridden_class):
-            w_obj.set_str_keyed_item(w_key, w_value, shadows_type)
+            w_obj.set_str_keyed_item(key, w_value, shadows_type)
         else:
-            self.setitem(w_obj, w_key, w_value)
+            self.setitem(w_obj, self.wrap(key), w_value)
 
     def getindex_w(self, w_obj, w_exception, objdescr=None):
         # Performance shortcut for the common case of w_obj being an int.

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/proxyobject.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/proxyobject.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/proxyobject.py	Wed Oct 28 16:21:35 2009
@@ -43,10 +43,10 @@
                     raise
                 return None
         
-        def setdictvalue(self, space, w_attr, w_value, shadows_type=True):
+        def setdictvalue(self, space, attr, w_value, shadows_type=True):
             try:
                 space.call_function(self.w_controller, space.wrap('__setattr__'),
-                   w_attr, w_value)
+                   space.wrap(attr), w_value)
                 return True
             except OperationError, e:
                 if not e.match(space, space.w_AttributeError):
@@ -67,7 +67,7 @@
             return self.getdictvalue(self.space, '__dict__')
         
         def setdict(self, space, w_dict):
-            if not self.setdictvalue(space, space.wrap('__dict__'), w_dict):
+            if not self.setdictvalue(space, '__dict__', w_dict):
                 baseobjspace.W_Root.setdict(self, space, w_dict)
         
     W_Transparent.__name__ = name

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py	Wed Oct 28 16:21:35 2009
@@ -100,13 +100,12 @@
     def impl_setitem(self, w_key, w_value):
         space = self.space
         if space.is_w(space.type(w_key), space.w_str):
-            self.impl_setitem_str(w_key, w_value)
+            self.impl_setitem_str(self.space.str_w(w_key), w_value)
         else:
             self._as_rdict().setitem(w_key, w_value)
 
     @unroll_safe
-    def impl_setitem_str(self, w_key, w_value, shadows_type=True):
-        key = self.space.str_w(w_key)
+    def impl_setitem_str(self, key, w_value, shadows_type=True):
         i = self.structure.lookup_position(key)
         if i != -1:
             self.entries[i] = w_value

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py	Wed Oct 28 16:21:35 2009
@@ -50,22 +50,6 @@
         assert obj.getdictvalue(self.fakespace, "hello") == 4
         assert obj.getdictvalue(self.fakespace, "world") == 5
 
-    def test_dict_devolves_via_object(self):
-        obj = self.make_obj()
-        obj.setdictvalue(self.fakespace, 4, 1)
-        obj.setdictvalue(self.fakespace, 5, 2)
-        w_dict = obj.w__dict__
-        assert w_dict is not None
-        assert dict(w_dict.r_dict_content) == {4: 1, 5: 2, "hello": 1, "world": 2}
-        assert obj.getdictvalue(self.fakespace, "hello") == 1
-        assert obj.getdictvalue(self.fakespace, "world") == 2
-        assert obj.getdictvalue(self.fakespace, 4) == 1
-        assert obj.getdictvalue(self.fakespace, 5) == 2
-        obj.deldictvalue(self.fakespace, "world")
-        assert obj.getdictvalue(self.fakespace, "world") is None
-        obj.deldictvalue(self.fakespace, "hello")
-        assert obj.getdictvalue(self.fakespace, "hello") is None
-
     def test_dict_devolves_via_dict(self):
         obj = self.make_obj()
         w_dict = obj.getdict()

Modified: pypy/branch/shrink-multidict/pypy/objspace/taint.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/taint.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/taint.py	Wed Oct 28 16:21:35 2009
@@ -23,8 +23,8 @@
 ##    def getdictvalue(self, space, attr):
 ##        return taint(self.w_obj.getdictvalue(space, attr))
 
-##    def setdictvalue(self, space, w_attr, w_value):
-##        return self.w_obj.setdictvalue(space, w_attr, w_value)
+##    def setdictvalue(self, space, attr, w_value):
+##        return self.w_obj.setdictvalue(space, attr, w_value)
 
 ##    ...
 

Modified: pypy/branch/shrink-multidict/pypy/translator/goal/gcbench.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/translator/goal/gcbench.py	(original)
+++ pypy/branch/shrink-multidict/pypy/translator/goal/gcbench.py	Wed Oct 28 16:21:35 2009
@@ -87,9 +87,21 @@
     else:
         return Node(make_tree(depth-1), make_tree(depth-1))
 
+def get_memory_usage():
+    import os
+    pid = os.getpid()
+    f = file("/proc/%s/status" % (pid, ))
+    lines = f.readlines()
+    f.close()
+    for l in lines:
+        if l.startswith("VmData:\t"):
+            return int(l[len("VmData:\t"):-len(" kB")])
+    print "\n".join(lines)
+    assert 0
+
 def print_diagnostics():
     "ought to print free/total memory"
-    pass
+    print "total memory:", get_memory_usage()
 
 def time_construction(depth):
     niters = num_iters(depth)



More information about the Pypy-commit mailing list