[pypy-commit] pypy default: Give up and return a regular int from compute_unique_id(), with an explanation.
arigo
noreply at buildbot.pypy.org
Mon Mar 10 08:06:54 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r69834:3a69dad4faf9
Date: 2014-03-10 08:06 +0100
http://bitbucket.org/pypy/pypy/changeset/3a69dad4faf9/
Log: Give up and return a regular int from compute_unique_id(), with an
explanation.
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -432,7 +432,11 @@
costly depending on the garbage collector. To remind you of this
fact, we don't support id(x) directly.
"""
- return id(x) # XXX need to return r_longlong on some platforms
+ # The assumption with RPython is that a regular integer is wide enough
+ # to store a pointer. The following intmask() should not loose any
+ # information.
+ from rpython.rlib.rarithmetic import intmask
+ return intmask(id(x))
def current_object_addr_as_int(x):
"""A cheap version of id(x).
diff --git a/rpython/rlib/test/test_objectmodel.py b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -177,10 +177,13 @@
assert h == getattr(foo, '__precomputed_identity_hash')
def test_compute_unique_id():
+ from rpython.rlib.rarithmetic import intmask
class Foo(object):
pass
foo = Foo()
- assert compute_unique_id(foo) == id(foo)
+ x = compute_unique_id(foo)
+ assert type(x) is int
+ assert x == intmask(id(foo))
def test_current_object_addr_as_int():
from rpython.rlib.rarithmetic import intmask
More information about the pypy-commit
mailing list