[pypy-commit] pypy identity-dict-strategy: completely remove the global identitydict version from the space, and use the space.fromcache() approach instead
antocuni
noreply at buildbot.pypy.org
Wed Jul 20 14:59:58 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: identity-dict-strategy
Changeset: r45771:0bba35bd5cfc
Date: 2011-07-20 11:48 +0200
http://bitbucket.org/pypy/pypy/changeset/0bba35bd5cfc/
Log: completely remove the global identitydict version from the space,
and use the space.fromcache() approach instead
diff --git a/pypy/objspace/std/identitydict.py b/pypy/objspace/std/identitydict.py
new file mode 100644
--- /dev/null
+++ b/pypy/objspace/std/identitydict.py
@@ -0,0 +1,27 @@
+# a global (per-space) version counter to track live instances which "compare
+# by identity" (i.e., whose __eq__, __cmp__ and __hash__ are the default
+# ones). The idea is to track only classes for which we checked the
+# compares_by_identity() status at least once: we increment the version if its
+# status might change, e.g. because we set one of those attributes. The
+# actual work is done by W_TypeObject.mutated() and objecttype:descr_setclass
+
+def bump_global_version(space):
+ if space.config.objspace.std.trackcomparebyidentity:
+ space.fromcache(ComparesByIdentityVersion).bump()
+
+def get_global_version(space):
+ if space.config.objspace.std.trackcomparebyidentity:
+ return space.fromcache(ComparesByIdentityVersion).get()
+ return None
+
+class ComparesByIdentityVersion(object):
+
+ def __init__(self, space):
+ self.bump()
+
+ def bump(self):
+ from pypy.objspace.std.typeobject import VersionTag
+ self._version = VersionTag()
+
+ def get(self):
+ return self._version
diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py
--- a/pypy/objspace/std/objecttype.py
+++ b/pypy/objspace/std/objecttype.py
@@ -6,7 +6,7 @@
from pypy.objspace.descroperation import Object
from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.register_all import register_all
-
+from pypy.objspace.std import identitydict
def descr__repr__(space, w_obj):
w = space.wrap
@@ -45,7 +45,7 @@
w_obj.setclass(space, w_newcls)
if space.config.objspace.std.trackcomparebyidentity:
if w_oldcls.compares_by_identity() and not w_newcls.compares_by_identity():
- space.compares_by_identity_version.bump()
+ identitydict.bump_global_version(space)
else:
raise operationerrfmt(space.w_TypeError,
"__class__ assignment: '%s' object layout differs from '%s'",
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
@@ -32,7 +32,7 @@
from pypy.objspace.std.smallintobject import W_SmallIntObject
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.objspace.std.typeobject import W_TypeObject, VersionTag
+from pypy.objspace.std.typeobject import W_TypeObject
# types
from pypy.objspace.std.inttype import wrapint
@@ -43,15 +43,6 @@
"""The standard object space, implementing a general-purpose object
library in Restricted Python."""
- # a global version counter to track live instances which "compare by
- # identity" (i.e., whose __eq__, __cmp__ and __hash__ are the default
- # ones). The idea is to track only classes for which we checked the
- # compares_by_identity() status at least once: we increment the version if
- # its status might change, e.g. because we set one of those attributes.
- # The actual work is done by W_TypeObject.mutated() and
- # objecttype:descr_setclass
- compares_by_identity_version = None
-
def initialize(self):
"NOT_RPYTHON: only for initializing the space."
# setup all the object types and implementations
@@ -88,9 +79,6 @@
# the type of old-style classes
self.w_classobj = self.builtin.get('__metaclass__')
- if self.config.objspace.std.trackcomparebyidentity:
- self.compares_by_identity_version = ComparesByIdentityVersion()
-
# final setup
self.setup_builtin_modules()
# Adding transparent proxy call
@@ -580,12 +568,3 @@
if isinstance(w_sub, W_TypeObject) and isinstance(w_type, W_TypeObject):
return self.wrap(w_sub.issubtype(w_type))
raise OperationError(self.w_TypeError, self.wrap("need type objects"))
-
-
-class ComparesByIdentityVersion(object):
-
- def __init__(self):
- self.bump()
-
- def bump(self):
- self._version = VersionTag()
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1204,6 +1204,7 @@
class AppTestTrackCompareByIdentity:
def setup_class(cls):
+ from pypy.objspace.std import identitydict
cls.space = gettestobjspace(
**{"objspace.std.trackcomparebyidentity": True})
@@ -1212,7 +1213,7 @@
cls.w_compares_by_identity = cls.space.wrap(interp2app(compares_by_identity))
def get_version(space):
- v = cls.versions.setdefault(space.compares_by_identity_version._version,
+ v = cls.versions.setdefault(identitydict.get_global_version(space),
len(cls.versions))
return space.wrap(v)
cls.w_get_version = cls.space.wrap(interp2app(get_version))
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
@@ -7,6 +7,7 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.objspace.std.stdtypedef import std_dict_descr, issubtypedef, Member
from pypy.objspace.std.objecttype import object_typedef
+from pypy.objspace.std import identitydict
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.objectmodel import current_object_addr_as_int, compute_hash
from pypy.rlib.jit import promote, elidable_promote, we_are_jitted
@@ -178,7 +179,7 @@
key == '__cmp__' or key == '__hash__'):
w_self.compares_by_identity_status = UNKNOWN
if did_compare_by_identity:
- w_self.space.compares_by_identity_version.bump()
+ identitydict.bump_global_version(w_self.space)
if space.config.objspace.std.newshortcut:
w_self.w_bltin_new = None
More information about the pypy-commit
mailing list