[pypy-commit] stmgc default: Add tons of debugging support, found where I forgot the save/restore.

arigo noreply at buildbot.pypy.org
Thu Jun 27 18:33:16 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r309:92111cbf8669
Date: 2013-06-27 17:51 +0200
http://bitbucket.org/pypy/stmgc/changeset/92111cbf8669/

Log:	Add tons of debugging support, found where I forgot the
	save/restore.

diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -146,22 +146,41 @@
 void Du_TransactionRun(void);
 
 
-#define _du_save1(p1)           (stm_push_root((DuObject *)(p1)))
-#define _du_save2(p1,p2)        (stm_push_root((DuObject *)(p1)),  \
-                                 stm_push_root((DuObject *)(p2)))
-#define _du_save3(p1,p2,p3)     (stm_push_root((DuObject *)(p1)),  \
-                                 stm_push_root((DuObject *)(p2)),  \
-                                 stm_push_root((DuObject *)(p3)))
+#define _du_save1(p1)           (_push_root((DuObject *)(p1)))
+#define _du_save2(p1,p2)        (_push_root((DuObject *)(p1)),  \
+                                 _push_root((DuObject *)(p2)))
+#define _du_save3(p1,p2,p3)     (_push_root((DuObject *)(p1)),  \
+                                 _push_root((DuObject *)(p2)),  \
+                                 _push_root((DuObject *)(p3)))
 
-#define _du_restore1(p1)        (p1 = (typeof(p1))stm_pop_root())
-#define _du_restore2(p1,p2)     (p2 = (typeof(p2))stm_pop_root(),  \
-                                 p1 = (typeof(p1))stm_pop_root())
-#define _du_restore3(p1,p2,p3)  (p3 = (typeof(p3))stm_pop_root(),  \
-                                 p2 = (typeof(p2))stm_pop_root(),  \
-                                 p1 = (typeof(p1))stm_pop_root())
+#define _du_restore1(p1)        (p1 = (typeof(p1))_pop_root())
+#define _du_restore2(p1,p2)     (p2 = (typeof(p2))_pop_root(),  \
+                                 p1 = (typeof(p1))_pop_root())
+#define _du_restore3(p1,p2,p3)  (p3 = (typeof(p3))_pop_root(),  \
+                                 p2 = (typeof(p2))_pop_root(),  \
+                                 p1 = (typeof(p1))_pop_root())
 
 #define _du_read1(p1)    (p1 = (typeof(p1))stm_read_barrier((DuObject *)(p1)))
 #define _du_write1(p1)   (p1 = (typeof(p1))stm_write_barrier((DuObject *)(p1)))
 
 
+#ifdef NDEBUG
+# define _push_root(ob)     stm_push_root(ob)
+# define _pop_root()        stm_pop_root()
+#else
+# define _check_not_free(ob)                                    \
+    assert(stm_get_tid((DuObject *)(ob)) > DUTYPE_INVALID &&    \
+           stm_get_tid((DuObject *)(ob)) < _DUTYPE_TOTAL)
+static inline void _push_root(gcptr ob) {
+    if (ob) _check_not_free(ob);
+    stm_push_root(ob);
+}
+static inline gcptr _pop_root(void) {
+    gcptr ob = stm_pop_root();
+    if (ob) _check_not_free(ob);
+    return ob;
+}
+#endif
+
+
 #endif  /* _DUHTON_H_ */
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -102,7 +102,9 @@
 
 DuObject *du_print(DuObject *cons, DuObject *locals)
 {
+    _du_save2(cons, locals);
     DuObject *lst = DuList_New();
+    _du_restore2(cons, locals);
 
     while (cons != Du_None) {
         _du_read1(cons);
diff --git a/duhton/test/test_gc.py b/duhton/test/test_gc.py
new file mode 100644
--- /dev/null
+++ b/duhton/test/test_gc.py
@@ -0,0 +1,15 @@
+from support import run
+
+
+def test_long1():
+    got = run("""
+        (defun g (n)
+         (if (>= n 7)
+             (print n)
+           (g (+ n 1))
+           (g (+ n 2))))
+        (g 0)
+    """)
+    pieces = got.splitlines()
+    assert len(pieces) == xxx
+    assert 0


More information about the pypy-commit mailing list