[pypy-svn] r79017 - in pypy/branch/rlist-jit/pypy: interpreter module/__builtin__ module/cpyext module/exceptions objspace/std

arigo at codespeak.net arigo at codespeak.net
Thu Nov 11 19:28:48 CET 2010


Author: arigo
Date: Thu Nov 11 19:28:46 2010
New Revision: 79017

Modified:
   pypy/branch/rlist-jit/pypy/interpreter/baseobjspace.py
   pypy/branch/rlist-jit/pypy/interpreter/function.py
   pypy/branch/rlist-jit/pypy/module/__builtin__/interp_classobj.py
   pypy/branch/rlist-jit/pypy/module/cpyext/typeobject.py
   pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/rlist-jit/pypy/objspace/std/objspace.py
   pypy/branch/rlist-jit/pypy/objspace/std/typeobject.py
   pypy/branch/rlist-jit/pypy/objspace/std/typetype.py
Log:
Replace the expressions 'space.fixedview(x)[:]' with yet
another method, 'space.fixedunpack(x)'.


Modified: pypy/branch/rlist-jit/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/rlist-jit/pypy/interpreter/baseobjspace.py	Thu Nov 11 19:28:46 2010
@@ -8,7 +8,7 @@
 from pypy.tool.cache import Cache
 from pypy.tool.uid import HUGEVAL_BYTES
 from pypy.rlib.objectmodel import we_are_translated
-from pypy.rlib.debug import make_sure_not_resized
+from pypy.rlib.debug import make_sure_not_resized, list_not_modified_any_more
 from pypy.rlib.timer import DummyTimer, Timer
 from pypy.rlib.rarithmetic import r_uint
 from pypy.rlib import jit
@@ -764,13 +764,21 @@
                                             'unpackiterable_unroll'))
 
     def fixedview(self, w_iterable, expected_length=-1):
-        """ A fixed list view of w_iterable. Don't modify the result
+        """ A fixed list view of w_iterable. The result is supposed to be
+        used temporarily: it is a list with the annotation flag 'do not mutate'.
         """
-        return make_sure_not_resized(self.unpackiterable(w_iterable,
+        return list_not_modified_any_more(self.unpackiterable(w_iterable,
                                                          expected_length)[:])
 
     fixedview_unroll = fixedview
 
+    def fixedunpack(self, w_iterable, expected_length=-1):
+        """ A fixed list with the content of w_iterable.
+        For most cases, use fixedview() instead.
+        """
+        return make_sure_not_resized(self.unpackiterable(w_iterable,
+                                                         expected_length)[:])
+
     def listview(self, w_iterable, expected_length=-1):
         """ A non-fixed view of w_iterable. Don't modify the result
         """

Modified: pypy/branch/rlist-jit/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/interpreter/function.py	(original)
+++ pypy/branch/rlist-jit/pypy/interpreter/function.py	Thu Nov 11 19:28:46 2010
@@ -198,7 +198,7 @@
         else:
             name = None
         if not space.is_w(w_argdefs, space.w_None):
-            defs_w = space.fixedview(w_argdefs)[:]
+            defs_w = space.fixedunpack(w_argdefs)
         else:
             defs_w = []
         nfreevars = 0
@@ -323,7 +323,7 @@
         if space.is_w(w_func_dict, space.w_None):
             w_func_dict = None
         self.w_func_dict = w_func_dict
-        self.defs_w = space.fixedview(w_defs_w)[:]
+        self.defs_w = space.fixedunpack(w_defs_w)
         self.w_module = w_module
 
     def fget_func_defaults(space, self):
@@ -338,7 +338,7 @@
             return
         if not space.is_true(space.isinstance(w_defaults, space.w_tuple)):
             raise OperationError( space.w_TypeError, space.wrap("func_defaults must be set to a tuple object or None") )
-        self.defs_w = space.fixedview(w_defaults)[:]
+        self.defs_w = space.fixedunpack(w_defaults)
 
     def fdel_func_defaults(space, self):
         self.defs_w = []

Modified: pypy/branch/rlist-jit/pypy/module/__builtin__/interp_classobj.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/module/__builtin__/interp_classobj.py	(original)
+++ pypy/branch/rlist-jit/pypy/module/__builtin__/interp_classobj.py	Thu Nov 11 19:28:46 2010
@@ -40,7 +40,7 @@
 
     # XXX missing: lengthy and obscure logic about "__module__"
         
-    bases_w = space.fixedview(w_bases)[:]
+    bases_w = space.fixedunpack(w_bases)
     for w_base in bases_w:
         if not isinstance(w_base, W_ClassObject):
             w_metaclass = space.type(w_base)
@@ -92,7 +92,7 @@
             raise OperationError(
                     space.w_TypeError,
                     space.wrap("__bases__ must be a tuple object"))
-        bases_w = space.fixedview(w_bases)[:]
+        bases_w = space.fixedunpack(w_bases)
         for w_base in bases_w:
             if not isinstance(w_base, W_ClassObject):
                 raise OperationError(space.w_TypeError,

Modified: pypy/branch/rlist-jit/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/branch/rlist-jit/pypy/module/cpyext/typeobject.py	Thu Nov 11 19:28:46 2010
@@ -262,7 +262,7 @@
 
 class W_PyCTypeObject(W_TypeObject):
     def __init__(self, space, pto):
-        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
+        bases_w = space.fixedunpack(from_ref(space, pto.c_tp_bases))
         dict_w = {}
 
         add_operators(space, dict_w, pto)

Modified: pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/branch/rlist-jit/pypy/module/exceptions/interp_exceptions.py	Thu Nov 11 19:28:46 2010
@@ -77,6 +77,7 @@
 from pypy.interpreter.gateway import interp2app, Arguments
 from pypy.interpreter.error import OperationError
 from pypy.rlib import rwin32
+from pypy.rlib.debug import list_not_modified_any_more
 
 def readwrite_attrproperty_w(name, cls):
     def fget(space, obj):
@@ -92,11 +93,15 @@
     and will be deprecated at some point. 
     """
     w_dict = None
-    args_w = []
+    _empty_args_w = []
 
     def __init__(self, space):
         self.space = space
         self.w_message = space.w_None
+        self.args_w = list_not_modified_any_more(W_BaseException._empty_args_w)
+        # Note that 'self.args_w' is annotated as a list-that-is-not-modified,
+        # which cannot easily be mixed together with a general list annotation.
+        # That's why we use 'list_not_modified_any_more()'.
 
     def descr_init(self, space, args_w):
         self.args_w = args_w
@@ -327,7 +332,7 @@
             self.w_strerror = args_w[1]
         if len(args_w) == 3:
             self.w_filename = args_w[2]
-            self.args_w = [args_w[0], args_w[1]]
+            self.args_w = list_not_modified_any_more([args_w[0], args_w[1]])
     descr_init.unwrap_spec = ['self', ObjSpace, 'args_w']
 
     # since we rebind args_w, we need special reduce, grump

Modified: pypy/branch/rlist-jit/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/rlist-jit/pypy/objspace/std/objspace.py	Thu Nov 11 19:28:46 2010
@@ -362,14 +362,15 @@
         if isinstance(w_obj, W_TupleObject):
             t = w_obj.wrappeditems
         elif isinstance(w_obj, W_ListObject):
-            t = w_obj.wrappeditems[:]
+            t = list_not_modified_any_more(w_obj.wrappeditems[:])
         else:
             if unroll:
-                return make_sure_not_resized(ObjSpace.unpackiterable_unroll(
-                    self, w_obj, expected_length)[:])
+                r = ObjSpace.unpackiterable_unroll(
+                        self, w_obj, expected_length)
             else:
-                return make_sure_not_resized(ObjSpace.unpackiterable(
-                    self, w_obj, expected_length)[:])
+                r = ObjSpace.unpackiterable(
+                        self, w_obj, expected_length)
+            return list_not_modified_any_more(r[:])
         if expected_length != -1 and len(t) != expected_length:
             raise self._wrap_expected_length(expected_length, len(t))
         return t
@@ -377,6 +378,17 @@
     def fixedview_unroll(self, w_obj, expected_length=-1):
         return self.fixedview(w_obj, expected_length, unroll=True)
 
+    def fixedunpack(self, w_obj, expected_length=-1):
+        if isinstance(w_obj, W_TupleObject):
+            t = w_obj.wrappeditems[:]
+        elif isinstance(w_obj, W_ListObject):
+            t = w_obj.wrappeditems[:]
+        else:
+            return ObjSpace.fixedunpack(self, w_obj, expected_length)
+        if expected_length != -1 and len(t) != expected_length:
+            raise self._wrap_expected_length(expected_length, len(t))
+        return t
+
     def listview(self, w_obj, expected_length=-1):
         if isinstance(w_obj, W_ListObject):
             t = w_obj.wrappeditems

Modified: pypy/branch/rlist-jit/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/objspace/std/typeobject.py	(original)
+++ pypy/branch/rlist-jit/pypy/objspace/std/typeobject.py	Thu Nov 11 19:28:46 2010
@@ -652,7 +652,7 @@
         if w_mro_func is not None and not space.is_w(w_where, space.w_type):
             w_mro_meth = space.get(w_mro_func, w_self)
             w_mro = space.call_function(w_mro_meth)
-            mro_w = space.fixedview(w_mro)[:]
+            mro_w = space.fixedunpack(w_mro)
             w_self.mro_w = validate_custom_mro(space, mro_w)
             return    # done
     w_self.mro_w = w_self.compute_default_mro()[:]

Modified: pypy/branch/rlist-jit/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/objspace/std/typetype.py	(original)
+++ pypy/branch/rlist-jit/pypy/objspace/std/typetype.py	Thu Nov 11 19:28:46 2010
@@ -12,7 +12,7 @@
 
     w_typetype = _precheck_for_new(space, w_typetype)
 
-    bases_w = space.fixedview(w_bases)[:]
+    bases_w = space.fixedunpack(w_bases)
 
     w_winner = w_typetype
     for base in bases_w:
@@ -115,7 +115,7 @@
                               "can only assign tuple to %s.__bases__, not %s",
                               w_type.name,
                               space.type(w_value).getname(space, '?'))
-    newbases_w = space.fixedview(w_value)[:]
+    newbases_w = space.fixedunpack(w_value)
     if len(newbases_w) == 0:
         raise operationerrfmt(space.w_TypeError,
                     "can only assign non-empty tuple to %s.__bases__, not ()",



More information about the Pypy-commit mailing list