[pypy-commit] pypy default: Fix for rgc.move_out_of_nursery() in very old GCs like "semispace"
arigo
pypy.commits at gmail.com
Fri Jan 13 06:55:49 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r89538:df8618e832de
Date: 2017-01-13 12:55 +0100
http://bitbucket.org/pypy/pypy/changeset/df8618e832de/
Log: Fix for rgc.move_out_of_nursery() in very old GCs like "semispace"
diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -1601,6 +1601,8 @@
resulttype=llmemory.Address)
hop.genop("cast_adr_to_ptr", [v_ret],
resultvar = hop.spaceop.result)
+ else:
+ hop.rename("same_as")
diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py
--- a/rpython/rlib/buffer.py
+++ b/rpython/rlib/buffer.py
@@ -112,6 +112,7 @@
def get_raw_address(self):
from rpython.rtyper.lltypesystem import rffi
+ # may still raise ValueError on some GCs
return rffi.get_raw_address_of_string(self.value)
class SubBuffer(Buffer):
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -542,8 +542,13 @@
become identical to the one returned.
NOTE: Only use for immutable objects!
+
+ NOTE: Might fail on some GCs! You have to check again
+ can_move() afterwards. It should always work with the default
+ GC. With Boehm, can_move() is always False so
+ move_out_of_nursery() should never be called in the first place.
"""
- pass
+ return obj
class MoveOutOfNurseryEntry(ExtRegistryEntry):
_about_ = move_out_of_nursery
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -1336,6 +1336,8 @@
as key is alive. If key goes out of scope, the buffer will eventually
be freed. `string` cannot go out of scope until the RawBytes object
referencing it goes out of scope.
+
+ NOTE: may raise ValueError on some GCs, but not the default one.
"""
assert isinstance(string, str)
from rpython.rtyper.annlowlevel import llstr
@@ -1346,6 +1348,8 @@
if we_are_translated():
if rgc.can_move(string):
string = rgc.move_out_of_nursery(string)
+ if rgc.can_move(string):
+ raise ValueError("cannot make string immovable")
# string cannot move now! return the address
lldata = llstr(string)
diff --git a/rpython/rtyper/lltypesystem/test/test_ztranslated.py b/rpython/rtyper/lltypesystem/test/test_ztranslated.py
--- a/rpython/rtyper/lltypesystem/test/test_ztranslated.py
+++ b/rpython/rtyper/lltypesystem/test/test_ztranslated.py
@@ -37,7 +37,10 @@
return ptr
def main(argv=[]):
- use_str()
+ try:
+ use_str()
+ except ValueError:
+ return 42
gc.collect()
mystr = b"12341234aa"*4096*10
#debug_assert(not rgc.can_move(mystr), "long string can move... why?")
@@ -56,4 +59,15 @@
def test_compiled_incminimark():
fn = compile(main, [], gcpolicy="incminimark")
- fn()
+ res = fn()
+ assert res == 0
+
+def test_compiled_semispace():
+ fn = compile(main, [], gcpolicy="semispace")
+ res = fn()
+ assert res == 42 # get_raw_address_of_string() raises ValueError
+
+def test_compiled_boehm():
+ fn = compile(main, [], gcpolicy="boehm")
+ res = fn()
+ assert res == 0
More information about the pypy-commit
mailing list