[pypy-svn] pypy arm-backend: merge default branch

bivab commits-noreply at bitbucket.org
Thu Jan 20 16:02:04 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: arm-backend
Changeset: r41040:99c5e9ac2d92
Date: 2010-12-17 15:45 +0100
http://bitbucket.org/pypy/pypy/changeset/99c5e9ac2d92/

Log:	merge default branch

diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -55,8 +55,8 @@
         else:
             if w_type is None:
                 w_type = space.w_dict
-            w_self = space.allocate_instance(EmptyDictImplementation, w_type)
-            EmptyDictImplementation.__init__(w_self, space)
+            w_self = space.allocate_instance(W_DictMultiObject, w_type)
+            W_DictMultiObject.__init__(w_self, space)
             return w_self
 
     def __init__(self, space):
@@ -97,29 +97,39 @@
     # implementation methods
     def impl_getitem(self, w_key):
         #return w_value or None
-        raise NotImplementedError("abstract base class")
+        # in case the key is unhashable, try to hash it
+        self.space.hash(w_key)
+        # return None anyway
+        return None
 
     def impl_getitem_str(self, key):
         #return w_value or None
-        raise NotImplementedError("abstract base class")
+        return None
+
+    def impl_setitem(self, w_key, w_value):
+        self._as_rdict().impl_fallback_setitem(w_key, w_value)
 
     def impl_setitem_str(self, key, w_value):
-        raise NotImplementedError("abstract base class")
-
-    def impl_setitem(self, w_key, w_value):
-        raise NotImplementedError("abstract base class")
+        self._as_rdict().impl_fallback_setitem_str(key, w_value)
 
     def impl_delitem(self, w_key):
-        raise NotImplementedError("abstract base class")
+        # in case the key is unhashable, try to hash it
+        self.space.hash(w_key)
+        raise KeyError
 
     def impl_length(self):
-        raise NotImplementedError("abstract base class")
+        return 0
 
     def impl_iter(self):
-        raise NotImplementedError("abstract base class")
+        # XXX I guess it's not important to be fast in this case?
+        return self._as_rdict().impl_fallback_iter()
 
     def impl_clear(self):
-        raise NotImplementedError("abstract base class")
+        self.r_dict_content = None
+
+    def _as_rdict(self):
+        r_dict_content = self.initialize_as_rdict()
+        return self
 
     def impl_keys(self):
         iterator = self.impl_iter()
@@ -407,45 +417,6 @@
         return self.shadowed[i]
 
 
-class EmptyDictImplementation(W_DictMultiObject):
-    def __init__(self, space):
-        self.space = space
-
-    def impl_setitem(self, w_key, w_value):
-        self._as_rdict().impl_fallback_setitem(w_key, w_value)
-
-    def impl_setitem_str(self, key, w_value):
-        self._as_rdict().impl_fallback_setitem_str(key, w_value)
-
-    def impl_delitem(self, w_key):
-        raise KeyError
-
-    def impl_length(self):
-        return 0
-
-    def impl_getitem_str(self, key):
-        return None
-
-    def impl_getitem(self, w_key):
-        # in case the key is unhashable, try to hash it
-        self.space.hash(w_key)
-        # return None anyway
-        return None
-
-    def impl_iter(self):
-        # XXX I guess it's not important to be fast in this case?
-        return self._as_rdict().impl_fallback_iter()
-
-    def impl_clear(self):
-        self.r_dict_content = None
-
-    def _as_rdict(self):
-        r_dict_content = self.initialize_as_rdict()
-        return self
-
-    def _clear_fields(self):
-        pass
-
 class RDictIteratorImplementation(IteratorImplementation):
     def __init__(self, space, dictimplementation):
         IteratorImplementation.__init__(self, space, dictimplementation)
@@ -838,42 +809,6 @@
                              space.wrap("popitem(): dictionary is empty"))
     return space.newtuple([w_key, w_value])
 
-app = gateway.applevel('''
-    def dictrepr(currently_in_repr, d):
-        # Now we only handle one implementation of dicts, this one.
-        # The fix is to move this to dicttype.py, and do a
-        # multimethod lookup mapping str to StdObjSpace.str
-        # This cannot happen until multimethods are fixed. See dicttype.py
-            dict_id = id(d)
-            if dict_id in currently_in_repr:
-                return '{...}'
-            currently_in_repr[dict_id] = 1
-            try:
-                items = []
-                # XXX for now, we cannot use iteritems() at app-level because
-                #     we want a reasonable result instead of a RuntimeError
-                #     even if the dict is mutated by the repr() in the loop.
-                for k, v in dict.items(d):
-                    items.append(repr(k) + ": " + repr(v))
-                return "{" +  ', '.join(items) + "}"
-            finally:
-                try:
-                    del currently_in_repr[dict_id]
-                except:
-                    pass
-''', filename=__file__)
-
-dictrepr = app.interphook("dictrepr")
-
-def repr__DictMulti(space, w_dict):
-    if w_dict.length() == 0:
-        return space.wrap('{}')
-    ec = space.getexecutioncontext()
-    w_currently_in_repr = ec._py_repr
-    if w_currently_in_repr is None:
-        w_currently_in_repr = ec._py_repr = space.newdict()
-    return dictrepr(space, w_currently_in_repr, w_dict)
-
 
 # ____________________________________________________________
 # Iteration

diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -506,6 +506,7 @@
 
     def test_emptydict_unhashable(self):
         raises(TypeError, "{}[['x']]")
+        raises(TypeError, "del {}[['x']]")
 
     def test_string_subclass_via_setattr(self):
         class A(object):

diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -134,7 +134,7 @@
 
     def mutated(w_self):
         space = w_self.space
-        assert w_self.is_heaptype() or not space.config.objspace.std.immutable_builtintypes
+        assert w_self.is_heaptype() or space.config.objspace.std.mutable_builtintypes
         if (not space.config.objspace.std.withtypeversion and
             not space.config.objspace.std.getattributeshortcut and
             not space.config.objspace.std.newshortcut):
@@ -157,8 +157,8 @@
             w_subclass.mutated()
 
     def version_tag(w_self):
-        if (not we_are_jitted() or w_self.is_heaptype() or not
-            w_self.space.config.objspace.std.immutable_builtintypes):
+        if (not we_are_jitted() or w_self.is_heaptype() or
+            w_self.space.config.objspace.std.mutable_builtintypes):
             return w_self._version_tag
         # heap objects cannot get their version_tag changed
         return w_self._pure_version_tag()
@@ -784,7 +784,7 @@
             space.set(w_descr, w_type, w_value)
             return
     
-    if (space.config.objspace.std.immutable_builtintypes
+    if (not space.config.objspace.std.mutable_builtintypes
             and not w_type.is_heaptype()):
         msg = "can't set attributes on type object '%s'"
         raise operationerrfmt(space.w_TypeError, msg, w_type.name)
@@ -803,7 +803,7 @@
         if space.is_data_descr(w_descr):
             space.delete(w_descr, w_type)
             return
-    if (space.config.objspace.std.immutable_builtintypes
+    if (not space.config.objspace.std.mutable_builtintypes
             and not w_type.is_heaptype()):
         msg = "can't delete attributes on type object '%s'"
         raise operationerrfmt(space.w_TypeError, msg, w_type.name)

diff --git a/pypy/doc/config/objspace.std.immutable_builtintypes.txt b/pypy/doc/config/objspace.std.immutable_builtintypes.txt
deleted file mode 100644
--- a/pypy/doc/config/objspace.std.immutable_builtintypes.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-Disallow modification of builtin types.  Enabled by default.

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -1,6 +1,7 @@
 syntax:glob
 *.py[co]
 *.sw[po]
+*~
 
 testresult
 site-packages

diff --git a/pypy/module/cpyext/conftest.py b/pypy/module/cpyext/conftest.py
deleted file mode 100644
--- a/pypy/module/cpyext/conftest.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import py
-from pypy.conftest import option, gettestobjspace
-
-def pytest_collect_directory(parent):
-    if parent.config.option.runappdirect:
-        py.test.skip("cannot be run by py.test -A")
-
-    # ensure additional functions are registered
-    import pypy.module.cpyext.test.test_cpyext
-
-def pytest_funcarg__space(request):
-    return gettestobjspace(usemodules=['cpyext', 'thread'])
-
-def pytest_funcarg__api(request):
-    return request.cls.api
-

diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -322,6 +322,14 @@
             w_subtype = w_type.check_user_subclass(w_subtype)
             if cls.typedef.applevel_subclasses_base is not None:
                 cls = cls.typedef.applevel_subclasses_base
+            #
+            if not we_are_translated():
+                if issubclass(cls, model.W_Object):
+                    # If cls is missing from model.typeorder, then you
+                    # need to add it there (including the inheritance
+                    # relationship, if any)
+                    assert cls in self.model.typeorder, repr(cls)
+            #
             if (self.config.objspace.std.withmapdict and cls is W_ObjectObject
                     and not w_subtype.needsdel):
                 from pypy.objspace.std.mapdict import get_subclass_of_correct_size

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -301,7 +301,7 @@
                    default=False),
         BoolOption("newshortcut",
                    "cache and shortcut calling __new__ from builtin types",
-                   default=False),        
+                   default=False),
 
         BoolOption("logspaceoptypes",
                    "a instrumentation option: before exit, print the types seen by "
@@ -310,8 +310,9 @@
         ChoiceOption("multimethods", "the multimethod implementation to use",
                      ["doubledispatch", "mrd"],
                      default="mrd"),
-        BoolOption("immutable_builtintypes",
-                   "Forbid the changing of builtin types", default=True),
+        BoolOption("mutable_builtintypes",
+                   "Allow the changing of builtin types", default=False,
+                   requires=[("objspace.std.builtinshortcut", True)]),
      ]),
 ])
 


More information about the Pypy-commit mailing list