Skip to content

Commit

Permalink
a test that rerased works after translation to C, which it didn't, so…
Browse files Browse the repository at this point in the history
… a fix too.
  • Loading branch information
cfbolz committed Oct 21, 2011
1 parent f84909b commit 233fa47
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions pypy/translator/c/gcc/test/test_asmgcroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def make_config(cls):
config = get_pypy_config(translating=True)
config.translation.gc = cls.gcpolicy
config.translation.gcrootfinder = "asmgcc"
config.translation.taggedpointers = getattr(cls, "taggedpointers", False)
return config

@classmethod
Expand Down
7 changes: 6 additions & 1 deletion pypy/translator/c/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ def name_address(value, db):

def name_gcref(value, db):
if value:
realobj = value._obj.container
obj = value._obj
if isinstance(obj, int):
# a tagged pointer
assert obj & 1 == 1
return '((%s) %d)' % (cdecl("void*", ''), obj)
realobj = obj.container
realvalue = cast_opaque_ptr(Ptr(typeOf(realobj)), value)
return db.get(realvalue)
else:
Expand Down
37 changes: 37 additions & 0 deletions pypy/translator/c/test/test_newgc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,43 @@ def test_tagged(self):
res = self.run("tagged")
assert res == expected

def define_erased(cls):
from pypy.rlib import rerased
erase, unerase = rerased.new_erasing_pair("test")
class Unrelated(object):
pass

u = Unrelated()
u.tagged = True
u.x = rerased.erase_int(41)
class A(object):
pass
def fn():
n = 1
while n >= 0:
if u.tagged:
n = rerased.unerase_int(u.x)
a = A()
a.n = n - 1
u.x = erase(a)
u.tagged = False
else:
n = unerase(u.x).n
u.x = rerased.erase_int(n - 1)
u.tagged = True
def func():
rgc.collect() # check that a prebuilt erased integer doesn't explode
u.x = rerased.erase_int(1000)
u.tagged = True
fn()
return 1
return func

def test_erased(self):
expected = self.run_orig("erased")
res = self.run("erased")
assert res == expected

from pypy.rlib.objectmodel import UnboxedValue

class TaggedBase(object):
Expand Down

0 comments on commit 233fa47

Please sign in to comment.