[pypy-commit] pypy null_byte_after_str: Test with the framework GCs, passing because gctypelayout already uses

arigo pypy.commits at gmail.com
Fri Jul 29 12:12:06 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: null_byte_after_str
Changeset: r85912:8314165f314f
Date: 2016-07-29 18:11 +0200
http://bitbucket.org/pypy/pypy/changeset/8314165f314f/

Log:	Test with the framework GCs, passing because gctypelayout already
	uses the modified llmemory.sizeof()

diff --git a/rpython/translator/c/test/test_lltyped.py b/rpython/translator/c/test/test_lltyped.py
--- a/rpython/translator/c/test/test_lltyped.py
+++ b/rpython/translator/c/test/test_lltyped.py
@@ -1004,7 +1004,6 @@
 
     def test_extra_item_after_alloc(self):
         from rpython.rlib import rgc
-        from rpython.rlib.objectmodel import compute_hash
         from rpython.rtyper.lltypesystem import lltype
         from rpython.rtyper.lltypesystem import rstr
         # all STR objects should be allocated with enough space for one
diff --git a/rpython/translator/c/test/test_newgc.py b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -3,6 +3,7 @@
 import os
 import sys
 import subprocess
+import random
 
 import py
 
@@ -1468,6 +1469,52 @@
         res = self.run('nursery_hash_base')
         assert res >= 195
 
+    def define_extra_item_after_alloc(cls):
+        from rpython.rtyper.lltypesystem import rstr
+        # all STR objects should be allocated with enough space for
+        # one extra char.  Check this with our GCs.  Use strings of 8,
+        # 16 and 24 chars because if the extra char is missing,
+        # writing to it is likely to cause corruption in nearby
+        # structures.
+        sizes = [random.choice([8, 16, 24]) for i in range(100)]
+        A = lltype.Struct('A', ('x', lltype.Signed))
+        prebuilt = [(rstr.mallocstr(sz),
+                     lltype.malloc(A, flavor='raw', immortal=True))
+                        for sz in sizes]
+        k = 0
+        for i, (s, a) in enumerate(prebuilt):
+            a.x = i
+            for i in range(len(s.chars)):
+                k += 1
+                if k == 256:
+                    k = 1
+                s.chars[i] = chr(k)
+
+        def check(lst):
+            hashes = []
+            for i, (s, a) in enumerate(lst):
+                assert a.x == i
+                rgc.ll_write_final_null_char(s)
+            for i, (s, a) in enumerate(lst):
+                assert a.x == i     # check it was not overwritten
+        def fn():
+            check(prebuilt)
+            lst1 = []
+            for i, sz in enumerate(sizes):
+                s = rstr.mallocstr(sz)
+                a = lltype.malloc(A, flavor='raw')
+                a.x = i
+                lst1.append((s, a))
+            check(lst1)
+            for _, a in lst1:
+                lltype.free(a, flavor='raw')
+            return 42
+        return fn
+
+    def test_extra_item_after_alloc(self):
+        res = self.run('extra_item_after_alloc')
+        assert res == 42
+
 
 class TestGenerationalGC(TestSemiSpaceGC):
     gcpolicy = "generation"


More information about the pypy-commit mailing list