[pypy-commit] pypy remove-objspace-options: if we have no rweakref, make classes uncollectable as opposed to not supporting

cfbolz pypy.commits at gmail.com
Thu Apr 21 12:36:04 EDT 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: remove-objspace-options
Changeset: r83809:ab0e0f0d6bb1
Date: 2016-04-21 19:34 +0300
http://bitbucket.org/pypy/pypy/changeset/ab0e0f0d6bb1/

Log:	if we have no rweakref, make classes uncollectable as opposed to not
	supporting get_subclasses

	(this is fine since translating without rweakref is anyway only for,
	say, testing new GCs)

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -232,15 +232,12 @@
         BoolOption("withtypeversion",
                    "version type objects when changing them",
                    cmdline=None,
-                   default=False,
-                   # weakrefs needed, because of get_subclasses()
-                   requires=[("translation.rweakref", True)]),
+                   default=False),
 
         BoolOption("withmethodcache",
                    "try to cache method lookups",
                    default=False,
-                   requires=[("objspace.std.withtypeversion", True),
-                             ("translation.rweakref", True)]),
+                   requires=[("objspace.std.withtypeversion", True)]),
         BoolOption("withmethodcachecounter",
                    "try to cache methods and provide a counter in __pypy__. "
                    "for testing purposes only.",
@@ -258,14 +255,10 @@
                    default=False),
         BoolOption("getattributeshortcut",
                    "track types that override __getattribute__",
-                   default=False,
-                   # weakrefs needed, because of get_subclasses()
-                   requires=[("translation.rweakref", True)]),
+                   default=False),
         BoolOption("newshortcut",
                    "cache and shortcut calling __new__ from builtin types",
-                   default=False,
-                   # weakrefs needed, because of get_subclasses()
-                   requires=[("translation.rweakref", True)]),
+                   default=False),
 
         BoolOption("withidentitydict",
                    "track types that override __hash__, __eq__ or __cmp__ and use a special dict strategy for those which do not",
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
@@ -557,7 +557,8 @@
     def add_subclass(w_self, w_subclass):
         space = w_self.space
         if not space.config.translation.rweakref:
-            return    # no weakref support, don't keep track of subclasses
+            self.weak_subclasses.append(w_subclass) # not really weak, but well
+            return
         import weakref
         assert isinstance(w_subclass, W_TypeObject)
         newref = weakref.ref(w_subclass)
@@ -572,7 +573,12 @@
     def remove_subclass(w_self, w_subclass):
         space = w_self.space
         if not space.config.translation.rweakref:
-            return    # no weakref support, don't keep track of subclasses
+            for i in range(len(w_self.weak_subclasses)):
+                w_cls = w_self.weak_subclasses[i]
+                if w_cls is w_subclass:
+                    del w_self.weak_subclasses[i]
+                    return
+            return
         for i in range(len(w_self.weak_subclasses)):
             ref = w_self.weak_subclasses[i]
             if ref() is w_subclass:
@@ -582,9 +588,7 @@
     def get_subclasses(w_self):
         space = w_self.space
         if not space.config.translation.rweakref:
-            raise oefmt(space.w_RuntimeError,
-                        "this feature requires weakrefs, "
-                        "which are not available in this build of PyPy")
+            return self.weak_subclasses[:]
         subclasses_w = []
         for ref in w_self.weak_subclasses:
             w_ob = ref()


More information about the pypy-commit mailing list