Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47420:5476d5e4a096
Date: 2011-02-16 12:26 +0100
http://bitbucket.org/pypy/pypy/changeset/5476d5e4a096/

Log:    Implemented deleteitem

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -90,6 +90,9 @@
     def inplace_mul(self, times):
         self.strategy.inplace_mul(self, times)
 
+    def deleteitem(self, index):
+        self.strategy.deleteitem(self, index)
+
 registerimplementation(W_ListObject)
 
 
@@ -115,6 +118,9 @@
     def inplace_mul(self, w_list, times):
         raise NotImplementedError
 
+    def deleteitem(self, w_list, index):
+        raise NotImplementedError
+
 class EmptyListStrategy(ListStrategy):
     def init_from_list_w(self, w_list, list_w):
         assert len(list_w) == 0
@@ -148,6 +154,9 @@
     def inplace_mul(self, w_list, times):
         return
 
+    def deleteitem(self, w_list, index):
+        raise IndexError
+
 class ObjectListStrategy(ListStrategy):
     def init_from_list_w(self, w_list, list_w):
         w_list.storage = cast_to_void_star(list_w, "object")
@@ -178,6 +187,10 @@
         list_w = cast_from_void_star(w_list.storage, "object")
         list_w *= times
 
+    def deleteitem(self, w_list, index):
+        list_w = cast_from_void_star(w_list.storage, "object")
+        del list_w[index]
+
 class IntegerListStrategy(ListStrategy):
 
     def init_from_list_w(self, w_list, list_w):
@@ -217,6 +230,10 @@
         list_w = cast_from_void_star(w_list.storage, "integer")
         list_w *= times
 
+    def deleteitem(self, w_list, index):
+        list_w = cast_from_void_star(w_list.storage, "integer")
+        del list_w[index]
+
 class StringListStrategy(ListStrategy):
 
     def init_from_list_w(self, w_list, list_w):
@@ -256,6 +273,10 @@
         list_w = cast_from_void_star(w_list.storage, "string")
         list_w *= times
 
+    def deleteitem(self, w_list, index):
+        list_w = cast_from_void_star(w_list.storage, "string")
+        del list_w[index]
+
 # _______________________________________________________
 
 init_signature = Signature(['sequence'], None, None)
@@ -423,7 +444,7 @@
 def delitem__List_ANY(space, w_list, w_idx):
     idx = get_list_index(space, w_idx)
     try:
-        del w_list.wrappeditems[idx]
+        w_list.deleteitem(idx)
     except IndexError:
         raise OperationError(space.w_IndexError,
                              space.wrap("list deletion index out of range"))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to