rlib/test/test_rgc.py::test_nonmoving_raw_ptr_for_resizable_list
def test_nonmoving_raw_ptr_for_resizable_list():
def f(n):
lst = ['a', 'b', 'c']
lst = rgc.resizable_list_supporting_raw_ptr(lst)
lst.append(chr(n))
assert lst[3] == chr(n)
assert lst[-1] == chr(n)
#
ptr = rgc.nonmoving_raw_ptr_for_resizable_list(lst)
assert lst[:] == ['a', 'b', 'c', chr(n)]
assert lltype.typeOf(ptr) == rffi.CCHARP
assert [ptr[i] for i in range(4)] == ['a', 'b', 'c', chr(n)]
#
lst[-3] = 'X'
assert ptr[1] == 'X'
ptr[2] = 'Y'
assert lst[-2] == 'Y'
#
addr = rffi.cast(lltype.Signed, ptr)
ptr = rffi.cast(rffi.CCHARP, addr)
rgc.collect() # should not move lst.items
lst[-4] = 'g'
assert ptr[0] == 'g'
ptr[3] = 'H'
assert lst[-1] == 'H'
return lst
#
# direct untranslated run
lst = f(35)
assert isinstance(lst, rgc._ResizableListSupportingRawPtr)
#
# llinterp run
interpret(f, [35])
#
# compilation with the GC transformer
import subprocess
from rpython.translator.interactive import Translation
#
def main(argv):
f(len(argv))
print "OK!"
return 0
#
t = Translation(main, gc="incminimark")
t.disable(['backendopt'])
t.set_backend_extra_options(c_debug_defines=True)
> exename = t.compile()
rlib/test/test_rgc.py:394:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
translator/interactive.py:117: in compile
getattr(self.driver, 'compile_' + backend)()
translator/driver.py:108: in proc
return self.proceed(backend_goal)
translator/driver.py:568: in proceed
result = self._execute(goals, task_skip = self._maybe_skip())
translator/tool/taskengine.py:114: in _execute
res = self._do(goal, taskcallable, *args, **kwds)
translator/driver.py:278: in _do
res = func()
translator/driver.py:435: in task_database_c
database = cbuilder.build_database()
translator/c/genc.py:102: in build_database
self.config.translation.reverse_debugger)
translator/c/database.py:64: in __init__
self.gctransformer = self.gcpolicy.gettransformer(translator, gchooks)
translator/c/gc.py:452: in gettransformer
return shadowstack.ShadowStackFrameworkGCTransformer(translator, gchooks)
memory/gctransform/framework.py:132: in __init__
GCClass, GC_PARAMS = choose_gc_from_config(translator.config)
memory/gc/base.py:593: in choose_gc_from_config
globals(), locals(), [classname])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# XXX Should find a way to bound the major collection threshold by the
# XXX total addressable size. Maybe by keeping some minimarkpage arenas
# XXX pre-reserved, enough for a few nursery collections? What about
# XXX raw-malloced memory?
# XXX try merging old_objects_pointing_to_pinned into
# XXX old_objects_pointing_to_young (IRC 2014-10-22, fijal and gregor_w)
import sys
import os
import time
from rpython.rtyper.lltypesystem import lltype, llmemory, llarena, llgroup
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.lltypesystem.llmemory import raw_malloc_usage
from rpython.memory.gc.base import GCBase, MovingGCBase
> from rpython.memory.gc import env
E File "/build_dir/rpython-linux-x86-64/build/rpython/memory/gc/env.py", line 423
E SyntaxError: Non-ASCII character '\xe2' in file /build_dir/rpython-linux-x86-64/build/rpython/memory/gc/env.py on line 423, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
memory/gc/incminimark.py:70: SyntaxError
---------- Captured stderr call ----------
[rtyper] specializing: 100 / 238 blocks (42%)
[rtyper] specializing: 200 / 238 blocks (84%)
[rtyper] -=- specialized 238 blocks -=-
[rtyper] -=- specialized 4 more blocks -=-
[flowgraph] (rpython.rlib.test.test_rgc:386)main
[translation:info] Annotating&simplifying...
[c58186560230f80] {translation-task
starting annotate
[translation:info] with policy: rpython.annotator.policy.AnnotatorPolicy
[flowgraph] (rpython.rlib.test.test_rgc:349)f
[flowgraph] (rpython.rlib.rgc:1473)nonmoving_raw_ptr_for_resizable_list
[flowgraph] (rpython.flowspace.specialcase:76)rpython_print_item
[flowgraph] (rpython.flowspace.specialcase:95)rpython_print_newline
[flowgraph] (rpython.flowspace.specialcase:85)rpython_print_end
[flowgraph] (rpython.rlib.rposix:500)write
[flowgraph] (rpython.rtyper.lltypesystem.rffi:1427)scoped_nonmovingbuffer.__init__
[flowgraph] (rpython.rtyper.lltypesystem.rffi:1431)scoped_nonmovingbuffer.__enter__
[flowgraph] (rpython.rtyper.lltypesystem.rffi:873)get_nonmovingbuffer_ll
[flowgraph] (rpython.rlib.objectmodel:315)we_are_translated_to_c
[flowgraph] (rpython.rtyper.lltypesystem.rstr:116)copy_string_to_raw
[flowgraph] (rpython.rtyper.lltypesystem.rstr:63)_get_raw_buf
[flowgraph] (rpython.rtyper.lltypesystem.rstr:57)_str_ofs
[flowgraph] (rpython.rtyper.lltypesystem.llmemory:411)sizeof
[flowgraph] (rpython.rtyper.lltypesystem.rffi:278)write
[flowgraph] (rpython.rtyper.lltypesystem.rffi:1433)scoped_nonmovingbuffer.__exit__
[flowgraph] (rpython.rtyper.lltypesystem.rffi:937)free_nonmovingbuffer_ll
[flowgraph] (rpython.rtyper.lltypesystem.rffi:3)ccall_write
[flowgraph] (rpython.rlib.rgil:160)release
[flowgraph] (rpython.rlib.rposix:151)_errno_before
[flowgraph] (rpython.rlib.rthread:349)getraw
[flowgraph] (rpython.rlib.rthread:349)getraw
[flowgraph] (rpython.rlib.rposix:170)_errno_after
[flowgraph] (rpython.rlib.rthread:364)setraw
[flowgraph] (rpython.rlib.rthread:364)setraw
[flowgraph] (rpython.rlib.rgil:171)acquire
[flowgraph] (rpython.rlib.rthread:282)gc_thread_run
[flowgraph] (rpython.rlib.rposix:430)handle_posix_error
[flowgraph] (rpython.rlib.rarithmetic:139)widen
[flowgraph] (rpython.rlib.rposix:113)get_saved_errno
[flowgraph] (?:1)memo_offsetof_0
[flowgraph] (?:1)memo_itemoffsetof_0
[flowgraph] (?:1)memo__sizeof_none_0
[flowgraph] (?:1)memo__isfunctype_0
[flowgraph] (?:1)memo__isfunctype_0
[flowgraph] (?:1)memo_itemoffsetof_0
[flowgraph] (?:1)memo__should_widen_type_0
[c58186563c70600] translation-task}
[translation:info] RTyping...
[c58186563c7b380] {translation-task
starting rtype_lltype
[flowgraph] (rpython.rtyper.rclass:1170)ll_runtime_type_info
[flowgraph] (rpython.rtyper.rlist:588)ll_append
[flowgraph] (rpython.rtyper.lltypesystem.rlist:365)ll_length
[flowgraph] (rpython.rtyper.lltypesystem.rlist:280)_ll_list_resize_ge
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rlib.jit:1300)conditional_call
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (?:11)_ll_list_resize_hint_really_look_inside_iff
[flowgraph] (rpython.rtyper.lltypesystem.rlist:198)<lambda>
[flowgraph] (rpython.rtyper.lltypesystem.rlist:198)_ll_list_resize_hint_really
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rtyper.lltypesystem.rlist:351)_ll_new_empty_item_array
[flowgraph] (?:2)ll_arraycopy
[flowgraph] (rpython.rlib.rgc:362)ll_arraycopy
[flowgraph] (rpython.rlib.rgc:342)copy_item
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (?:2)_ll_list_resize_hint_really_trampoline
[flowgraph] (rpython.rtyper.lltypesystem.rlist:198)_ll_list_resize_hint_really
[flowgraph] (rpython.rtyper.lltypesystem.rlist:377)ll_setitem_fast
[flowgraph] (rpython.rtyper.lltypesystem.rlist:369)ll_items
[flowgraph] (?:1)memo__ll_prebuilt_empty_array_0
[flowgraph] (?:1)memo__contains_gcptr_0
[flowgraph] (?:1)memo_itemoffsetof_0
[flowgraph] (?:11)ll_join_chars_look_inside_iff
[flowgraph] (rpython.rtyper.lltypesystem.rstr:821)<lambda>
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rtyper.lltypesystem.rstr:820)ll_join_chars
[flowgraph] (?:2)mallocstr
[flowgraph] (rpython.rtyper.lltypesystem.rstr:36)mallocstr
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (?:2)ll_join_chars_trampoline
[flowgraph] (rpython.rtyper.lltypesystem.rstr:820)ll_join_chars
[flowgraph] (?:11)ll_listdelslice_startonly_look_inside_iff
[flowgraph] (rpython.rtyper.rlist:912)<lambda>
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rtyper.rlist:912)ll_listdelslice_startonly
[flowgraph] (rpython.rtyper.rlist:539)ll_null_item
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (rpython.rtyper.lltypesystem.rlist:295)_ll_list_resize_le
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rlib.jit:1300)conditional_call
[flowgraph] (?:2)ll_listdelslice_startonly_trampoline
[flowgraph] (rpython.rtyper.rlist:912)ll_listdelslice_startonly
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rtyper.lltypesystem.rstr:350)ll_strlen
[flowgraph] (rpython.rtyper.lltypesystem.rstr:1306)ll_strnext
[flowgraph] (rpython.rtyper.rlist:697)ll_getitem
[flowgraph] (rpython.rtyper.rlist:717)ll_getitem_fast
[flowgraph] (rpython.rtyper.lltypesystem.rlist:372)ll_getitem_fast
[flowgraph] (rpython.rtyper.lltypesystem.rlist:384)ll_fixed_newlist
[flowgraph] (rpython.rtyper.rlist:726)ll_setitem_nonneg
[flowgraph] (rpython.rtyper.lltypesystem.rlist:407)ll_fixed_setitem_fast
[flowgraph] (?:11)ll_listeq_look_inside_iff
[flowgraph] (rpython.rtyper.rlist:970)listeq_unroll_case
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (rpython.rtyper.rlist:977)ll_listeq
[flowgraph] (rpython.rtyper.lltypesystem.rlist:395)ll_fixed_length
[flowgraph] (rpython.rtyper.lltypesystem.rlist:402)ll_fixed_getitem_fast
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (?:2)ll_listeq_trampoline
[flowgraph] (rpython.rtyper.rlist:977)ll_listeq
[flowgraph] (rpython.rtyper.rstr:425)ll_str
[flowgraph] (?:1)memo_ll_constant_0
[flowgraph] (?:11)ll_join_strs_look_inside_iff
[flowgraph] (rpython.rtyper.lltypesystem.rstr:783)ll_join_strs
[flowgraph] (rpython.rtyper.lltypesystem.rstr:785)<lambda>
[flowgraph] (rpython.rtyper.lltypesystem.llmemory:1037)cast_any_ptr
[flowgraph] (rpython.rlib.jit:294)loop_unrolling_heuristic
[flowgraph] (rpython.rlib.jit:269)isconstant
[flowgraph] (rpython.rtyper.lltypesystem.rstr:78)copy_string_contents
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (?:2)ll_join_strs_trampoline
[flowgraph] (rpython.rtyper.lltypesystem.rstr:783)ll_join_strs
[flowgraph] (rpython.rlib.rgc:1555)ll_nonmovable_raw_ptr_for_resizable_list
[flowgraph] (rpython.rtyper.rrange:172)ll_rangenext_up
[flowgraph] (rpython.rtyper.rlist:880)ll_listslice_startonly
[flowgraph] (rpython.rtyper.rlist:552)ll_arraycopy
[flowgraph] (rpython.rtyper.lltypesystem.rlist:399)ll_fixed_items
[flowgraph] (?:11)ll_listeq_look_inside_iff
[flowgraph] (rpython.rtyper.rlist:970)listeq_unroll_case
[flowgraph] (rpython.rtyper.rlist:977)ll_listeq
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (rpython.rlib.jit:281)isvirtual
[flowgraph] (?:2)ll_listeq_trampoline
[flowgraph] (rpython.rtyper.rlist:977)ll_listeq
[flowgraph] (rpython.rtyper.rlist:572)ll_len
[flowgraph] (rpython.rtyper.lltypesystem.rlist:365)ll_length
[rtyper] specializing: 100 / 482 blocks (20%)
[flowgraph] (rpython.rtyper.rlist:735)ll_setitem
[flowgraph] (rpython.rtyper.lltypesystem.rstr:1293)ll_striter
[flowgraph] (rpython.rtyper.lltypesystem.rlist:324)ll_newlist
[flowgraph] (rpython.rtyper.rlist:726)ll_setitem_nonneg
[flowgraph] (rpython.rtyper.rlist:688)ll_getitem_nonneg
[flowgraph] (rpython.rtyper.lltypesystem.rlist:357)ll_newemptylist
[flowgraph] (rpython.rtyper.lltypesystem.rrange:70)ll_newrange
[flowgraph] (rpython.rtyper.lltypesystem.rrange:91)ll_rangeiter
[rtyper] specializing: 200 / 504 blocks (39%)
[rtyper] specializing: 300 / 504 blocks (59%)
[rtyper] specializing: 400 / 504 blocks (79%)
[rtyper] specializing: 500 / 504 blocks (99%)
[rtyper] -=- specialized 504 blocks -=-
[flowgraph] (rpython.rtyper.rclass:1133)ll_issubclass
[flowgraph] (rpython.rtyper.rclass:1130)ll_type
[rtyper] -=- specialized 4 more blocks -=-
[c5818656fe24600] translation-task}
[translation:info] inserting stack checks...
[c5818656fe2d480] {translation-task
starting stackcheckinsertion_lltype
[flowgraph] (rpython.rlib.rstack:42)stack_check
[flowgraph] (rpython.rlib.rstack:67)stack_check_slowpath
[rtyper] -=- specialized 8 more blocks -=-
[translation:info] inserted 0 stack checks.
[c581865704de300] translation-task}
[translation:info] Creating database for generating c source...
[c581865704e6580] {translation-task
starting database_c
[flowgraph] (rpython.translator.exceptiontransform:100)rpyexc_occurred
[flowgraph] (rpython.translator.exceptiontransform:104)rpyexc_fetch_type
[flowgraph] (rpython.translator.exceptiontransform:107)rpyexc_fetch_value
[flowgraph] (rpython.translator.exceptiontransform:110)rpyexc_clear
[flowgraph] (rpython.translator.exceptiontransform:114)rpyexc_raise
[flowgraph] (rpython.translator.exceptiontransform:128)rpyexc_reraise
[flowgraph] (rpython.translator.exceptiontransform:133)rpyexc_fetch_exception
[flowgraph] (rpython.translator.exceptiontransform:138)rpyexc_restore_exception
[flowgraph] (rpython.translator.exceptiontransform:539)rpyexc_get_exception_addr
[flowgraph] (rpython.translator.exceptiontransform:543)rpyexc_get_exc_value_addr
[flowgraph] (rpython.rtyper.rclass:1173)ll_inst_type
[rtyper] -=- specialized 25 more blocks -=-
[flowgraph] (rpython.memory.gctransform.transform:447)_ll_malloc_fixedsize
[flowgraph] (rpython.memory.gctransform.transform:454)_ll_malloc_fixedsize_zero
[flowgraph] (rpython.memory.gctransform.transform:470)_ll_malloc_varsize_no_length
[flowgraph] (rpython.memory.gctransform.transform:487)ll_malloc_varsize
[flowgraph] (rpython.memory.gctransform.transform:493)_ll_malloc_varsize_no_length_zero
[c58186571496d80] translation-task}
builder: rpython-linux-x86-64 build #885
test: rlib/test/test_rgc/py/test_nonmoving_raw_ptr_for_resizable_list