[pypy-svn] r58003 - in pypy/branch/tuple-nonresizable-395/pypy: module/marshal objspace/std

fijal at codespeak.net fijal at codespeak.net
Tue Sep 9 14:23:17 CEST 2008


Author: fijal
Date: Tue Sep  9 14:23:15 2008
New Revision: 58003

Added:
   pypy/branch/tuple-nonresizable-395/pypy/objspace/std/seqinterface.py   (contents, props changed)
Modified:
   pypy/branch/tuple-nonresizable-395/pypy/module/marshal/interp_marshal.py
   pypy/branch/tuple-nonresizable-395/pypy/objspace/std/listobject.py
   pypy/branch/tuple-nonresizable-395/pypy/objspace/std/marshal_impl.py
   pypy/branch/tuple-nonresizable-395/pypy/objspace/std/tupleobject.py
Log:
* Add common superclass for W_ListObject and W_TupleObject
* Kill shortcut for list[slice] = tuple
* Use common interface for list/tuple when marshalling

hence killing two places that share wrappeditems from listobject and tupleobject


Modified: pypy/branch/tuple-nonresizable-395/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/module/marshal/interp_marshal.py	(original)
+++ pypy/branch/tuple-nonresizable-395/pypy/module/marshal/interp_marshal.py	Tue Sep  9 14:23:15 2008
@@ -244,14 +244,29 @@
             idx += 1
         self.nesting -= 1
 
-    def put_list_w(self, list_w, lng):
+    def put_list_w(self, lst_w, lng):
         self.nesting += 1
         self.put_int(lng)
         idx = 0
         space = self.space
         if self.nesting < MAX_MARSHAL_DEPTH:
             while idx < lng:
-                w_obj = list_w[idx]
+                w_obj = lst_w[idx]
+                self.space.marshal_w(w_obj, self)
+                idx += 1
+        else:
+            self._overflow()
+        self.nesting -= 1
+
+    def put_w_seq(self, w_seq):
+        self.nesting += 1
+        lng = w_seq.getlength()
+        self.put_int(lng)
+        idx = 0
+        space = self.space
+        if self.nesting < MAX_MARSHAL_DEPTH:
+            while idx < lng:
+                w_obj = w_seq.getitem(idx)
                 self.space.marshal_w(w_obj, self)
                 idx += 1
         else:

Modified: pypy/branch/tuple-nonresizable-395/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/objspace/std/listobject.py	(original)
+++ pypy/branch/tuple-nonresizable-395/pypy/objspace/std/listobject.py	Tue Sep  9 14:23:15 2008
@@ -3,13 +3,14 @@
 from pypy.objspace.std.listtype import get_list_index
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.tupleobject import W_TupleObject
+from pypy.objspace.std.seqinterface import W_SeqObject
 
 from pypy.objspace.std import slicetype
 from pypy.interpreter import gateway, baseobjspace
 from pypy.rlib.listsort import TimSort
 
 
-class W_ListObject(W_Object):
+class W_ListObject(W_SeqObject):
     from pypy.objspace.std.listtype import list_typedef as typedef
     
     def __init__(w_self, wrappeditems):
@@ -253,10 +254,6 @@
     l = w_list2.wrappeditems
     return _setitem_slice_helper(space, w_list, w_slice, l, len(l))
 
-def setitem__List_Slice_Tuple(space, w_list, w_slice, w_tuple):
-    t = w_tuple.wrappeditems
-    return _setitem_slice_helper(space, w_list, w_slice, t, len(t))
-
 def setitem__List_Slice_ANY(space, w_list, w_slice, w_iterable):
     l = space.unpackiterable(w_iterable)
     return _setitem_slice_helper(space, w_list, w_slice, l, len(l))

Modified: pypy/branch/tuple-nonresizable-395/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/objspace/std/marshal_impl.py	(original)
+++ pypy/branch/tuple-nonresizable-395/pypy/objspace/std/marshal_impl.py	Tue Sep  9 14:23:15 2008
@@ -87,7 +87,8 @@
 put_int(int)                puts an integer
 put_pascal(s)               puts a short string
 put_w_obj(w_obj)            puts a wrapped object
-put_list_w(list_w, lng)     puts a list of lng wrapped objects
+put_list_w(lst_w, lng)      puts a list with lng of wrapped objects
+put_w_seq(w_seq)            puts a w_seqobject subclass
 
 """
 
@@ -315,8 +316,7 @@
 
 def marshal_w__Tuple(space, w_tuple, m):
     m.start(TYPE_TUPLE)
-    items = w_tuple.wrappeditems
-    m.put_list_w(items, len(items))
+    m.put_w_seq(w_tuple)
 
 def unmarshal_Tuple(space, u, tc):
     items_w = u.get_list_w()
@@ -325,8 +325,7 @@
 
 def marshal_w__List(space, w_list, m):
     m.start(TYPE_LIST)
-    items = w_list.wrappeditems
-    m.put_list_w(items, len(items))
+    m.put_w_seq(w_list)
 
 def unmarshal_List(space, u, tc):
     items_w = u.get_list_w()

Added: pypy/branch/tuple-nonresizable-395/pypy/objspace/std/seqinterface.py
==============================================================================
--- (empty file)
+++ pypy/branch/tuple-nonresizable-395/pypy/objspace/std/seqinterface.py	Tue Sep  9 14:23:15 2008
@@ -0,0 +1,15 @@
+
+from pypy.objspace.std.objspace import W_Object
+
+class W_SeqObject(W_Object):
+    """ This is a common superclass for W_ListObject and W_TupleObject.
+    it's purpose is to have some methods that present common interface
+    to accessing items from interp-level. The whole idea is to not have
+    wrappeditems of both shared
+    """
+
+    def getlength(self):
+        return len(self.wrappeditems)
+
+    def getitem(self, i):
+        return self.wrappeditems[i]

Modified: pypy/branch/tuple-nonresizable-395/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/objspace/std/tupleobject.py	(original)
+++ pypy/branch/tuple-nonresizable-395/pypy/objspace/std/tupleobject.py	Tue Sep  9 14:23:15 2008
@@ -1,4 +1,5 @@
 from pypy.objspace.std.objspace import *
+from pypy.objspace.std.seqinterface import W_SeqObject
 from pypy.objspace.std.inttype import wrapint
 from pypy.rlib.rarithmetic import intmask
 from pypy.objspace.std.sliceobject import W_SliceObject
@@ -6,7 +7,7 @@
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.annotation import model as annmodel
 
-class W_TupleObject(W_Object):
+class W_TupleObject(W_SeqObject):
     from pypy.objspace.std.tupletype import tuple_typedef as typedef
     
     def __init__(w_self, wrappeditems):



More information about the Pypy-commit mailing list