def test_arena_protect(): a = arena_malloc(100, False) S = lltype.Struct('S', ('x', lltype.Signed)) arena_reserve(a, llmemory.sizeof(S)) p = llmemory.cast_adr_to_ptr(a, lltype.Ptr(S)) p.x = 123 assert p.x == 123 arena_protect(a, 100, True) py.test.raises(ArenaError, arena_reserve, a + 48, llmemory.sizeof(S)) py.test.raises(RuntimeError, "p.x") py.test.raises(RuntimeError, "p.x = 124") arena_protect(a, 100, False) assert p.x == 123 p.x = 125 assert p.x == 125
def fn(argv): testrun = int(argv[1]) a = arena_malloc(65536, False) arena_reserve(a, llmemory.sizeof(S)) p = llmemory.cast_adr_to_ptr(a + 23432, lltype.Ptr(S)) p.x = 123 assert p.x == 123 arena_protect(a, 65536, True) result = 0 if testrun == 1: print p.x # segfault if testrun == 2: p.x = 124 # segfault arena_protect(a, 65536, False) p.x += 10 print p.x return 0