Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r365:dd0aff1663a1
Date: 2013-07-06 21:38 +0200
http://bitbucket.org/pypy/stmgc/changeset/dd0aff1663a1/

Log:    Test and fix for stm_pointer_equal with null pointers

diff --git a/c4/extra.c b/c4/extra.c
--- a/c4/extra.c
+++ b/c4/extra.c
@@ -132,6 +132,10 @@
     /* fast path for two equal pointers */
     if (p1 == p2)
         return 1;
+    /* if p1 or p2 is NULL (but not both, because they are different
+       pointers), then return 0 */
+    if (p1 == NULL || p2 == NULL)
+        return 0;
     /* types must be the same */
     if ((p1->h_tid & STM_USER_TID_MASK) != (p2->h_tid & STM_USER_TID_MASK))
         return 0;
diff --git a/c4/test/test_extra.py b/c4/test/test_extra.py
--- a/c4/test/test_extra.py
+++ b/c4/test/test_extra.py
@@ -102,3 +102,15 @@
             c = lib.stm_inspect_abort_info()
             assert c
             assert ffi.string(c).endswith("ei424242ee")
+
+def test_pointer_equal():
+    p = palloc(HDR)
+    assert lib.stm_pointer_equal(p, p)
+    assert not lib.stm_pointer_equal(p, ffi.NULL)
+    assert not lib.stm_pointer_equal(ffi.NULL, p)
+    assert lib.stm_pointer_equal(ffi.NULL, ffi.NULL)
+    q = lib.stm_write_barrier(p)
+    assert q != p
+    assert lib.stm_pointer_equal(p, q)
+    assert lib.stm_pointer_equal(q, q)
+    assert lib.stm_pointer_equal(q, p)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to