Author: Armin Rigo <[email protected]>
Branch: copy-over-original2
Changeset: r445:7cf82d665852
Date: 2013-07-25 23:19 +0200
http://bitbucket.org/pypy/stmgc/changeset/7cf82d665852/

Log:    Fix (argh), by adding a reasonable assert, and fix all tests to pass
        this condition.

diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -569,6 +569,12 @@
 gcptr stm_WriteBarrier(gcptr P)
 {
   assert(!(P->h_tid & GCFLAG_IMMUTABLE));
+  assert(stmgc_size(P) > sizeof(struct stm_stub_s) - WORD);
+  /* If stmgc_size(P) gives a number <= sizeof(stub)-WORD, then there is a
+     risk of overrunning the object later in gcpage.c when copying a stub
+     over it.  However such objects are so small that they contain no field
+     at all, and so no write barrier should occur on them. */
+
   if (is_private(P))
     {
       /* If we have GCFLAG_WRITE_BARRIER in P, then list it into
diff --git a/c4/test/support.py b/c4/test/support.py
--- a/c4/test/support.py
+++ b/c4/test/support.py
@@ -586,6 +586,7 @@
 def delegate(p1, p2):
     assert classify(p1) == "public"
     assert classify(p2) == "public"
+    assert lib.gettid(p1) != 42 and lib.gettid(p2) == lib.gettid(p1)
     p1.h_revision = ffi.cast("revision_t", p2)
     p1.h_tid |= GCFLAG_PUBLIC_TO_PRIVATE
     if p1.h_tid & GCFLAG_PREBUILT_ORIGINAL:
diff --git a/c4/test/test_gcpage.py b/c4/test/test_gcpage.py
--- a/c4/test/test_gcpage.py
+++ b/c4/test/test_gcpage.py
@@ -159,7 +159,7 @@
     lib.stm_pop_root()
 
 def test_local_copy_from_global_obj():
-    p1 = oalloc(HDR); make_public(p1)
+    p1 = oalloc(HDR + WORD); make_public(p1)
     p2n = lib.stm_write_barrier(p1)
     assert p2n != p1
     assert lib.stm_write_barrier(p1) == p2n
@@ -184,8 +184,8 @@
     assert p3 == p2
 
 def test_new_version():
-    p1 = oalloc(HDR); make_public(p1)
-    p2 = oalloc(HDR); make_public(p2)
+    p1 = oalloc(HDR + WORD); make_public(p1)
+    p2 = oalloc(HDR + WORD); make_public(p2)
     delegate(p1, p2)
     check_not_free(p1)
     check_not_free(p2)
@@ -214,10 +214,10 @@
 
     
 def test_new_version_kill_intermediate():
-    p1 = oalloc(HDR); make_public(p1)
-    p2 = oalloc(HDR); make_public(p2)
-    p3 = oalloc(HDR); make_public(p3)
-    p4 = oalloc(HDR); make_public(p4)
+    p1 = oalloc(HDR + WORD); make_public(p1)
+    p2 = oalloc(HDR + WORD); make_public(p2)
+    p3 = oalloc(HDR + WORD); make_public(p3)
+    p4 = oalloc(HDR + WORD); make_public(p4)
     delegate(p1, p2)
     delegate(p2, p3)
     delegate(p3, p4)
@@ -318,7 +318,7 @@
     check_free_old(p3)
 
 def test_prebuilt_version_to_protected():
-    p1 = lib.pseudoprebuilt(HDR, 42 + HDR)
+    p1 = lib.pseudoprebuilt(HDR + WORD, 42 + HDR + WORD)
     p2 = lib.stm_write_barrier(p1)
     lib.stm_commit_transaction()
     lib.stm_begin_inevitable_transaction()
@@ -366,7 +366,7 @@
     check_not_free(p1)
 
 def test_private_from_protected_young():
-    p1 = nalloc(HDR)
+    p1 = nalloc(HDR + WORD)
     lib.stm_commit_transaction()
     lib.stm_begin_inevitable_transaction()
     p1b = lib.stm_write_barrier(p1)
@@ -384,7 +384,7 @@
     assert follow_revision(p1).h_tid & GCFLAG_BACKUP_COPY
 
 def test_backup_stolen():
-    p = palloc(HDR)
+    p = palloc(HDR + WORD)
     def f1(r):
         p1 = lib.stm_write_barrier(p)   # private copy
         lib.stm_push_root(p1)
@@ -429,7 +429,7 @@
     run_parallel(f1, f2)
 
 def test_private_from_protected_inevitable():
-    p1 = nalloc(HDR)
+    p1 = nalloc(HDR + WORD)
     lib.stm_commit_transaction()
     lib.stm_begin_inevitable_transaction()
     p1b = lib.stm_write_barrier(p1)
@@ -452,7 +452,7 @@
     check_not_free(lib.getptr(p1, 0))
 
 def test_prebuilt_modified_during_transaction():
-    p1 = palloc(HDR)
+    p1 = palloc(HDR + WORD)
     p2 = nalloc_refs(1)
     lib.setptr(p2, 0, p1)
     lib.stm_push_root(p2)
@@ -466,7 +466,7 @@
     check_not_free(p1b)
 
 def test_prebuilt_modified_later():
-    p1 = palloc(HDR)
+    p1 = palloc(HDR + WORD)
     p2 = nalloc_refs(1)
     lib.setptr(p2, 0, p1)
     lib.stm_push_root(p2)
@@ -490,7 +490,7 @@
     # assert did not crash
 
 def test_big_old_object_free():
-    for words in range(80):
+    for words in range(1, 80):
         p1 = oalloc(HDR + words * WORD)
         p1b = lib.stm_write_barrier(p1)
         assert p1b == p1
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to