[gambit-list] [PATCH-for-debugging] DEBUG: add type checks to ##continuation-capture-aux

Christian Jaeger christian at pflanze.mine.nu
Wed Nov 26 11:39:22 EST 2008


To try to find the culprit in the Termite failings.

---

 Since you got:

 Program received signal EXC_BAD_ACCESS, Could not access memory.
 Reason: KERN_INVALID_ADDRESS at address: 0x01c03ffc
 0x003058c5 in ___H_base_2d_exception_2d_handler (___ps=0x4a1880) at _thread.c:27164
 27164      ___JUMP_CONTINUATION_CAPTURE1(___JUMPNOTSAFE)
 (gdb) bt
 #0  0x003058c5 in ___H_base_2d_exception_2d_handler (___ps=0x4a1880) at _thread.c:27164
 #1  0x0000906f in ___call (nargs=0, proc=3701041, stack_marker=7340973) at setup.c:1819
 (gdb) 

 you can find out from _thread.c by scrolling up from line 27164 that
 it's the ___H__23__23_continuation_2d_capture_2d_aux procedure which
 is failing, which is the compiled version of
 ##continuation-capture-aux. Since it fails in an unsafe jump, I'd
 expect that it's been called with something different than a
 procedure (or maybe a procedure of a wrong argument count, not sure
 here). (Since it tries to access an address far off zero, I guess the
 given object is not an #f value or small fixnum but rather an
 allocated object of a wrong type.) This patch adds type checks, so
 instead of segfaulting you should now get an exception. (I realize
 that I'm not using ##not and ##pair? but it seems to work this way
 anyway. I'm hoping that the not interrupts-enabled isn't being
 disturbed by the potential error call though; and worse, *if* an
 exception happens, the code is interrupted for sure, but I don't see
 why it should be a problem here.)

 I haven't tried your program as I don't have Termite installed in my
 current Gambit, and moreover, it wouldn't be your version of Termite
 anyway. (And I don't have time either..)

 lib/_thread.scm |   41 +++++++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/lib/_thread.scm b/lib/_thread.scm
index d228dde..2caa6be 100644
--- a/lib/_thread.scm
+++ b/lib/_thread.scm
@@ -2764,24 +2764,29 @@
   (##continuation? obj))
 
 (define-prim (##continuation-capture-aux receiver lift1 lift2 lift3 others)
-  (##declare (not interrupts-enabled))
-  (cond ((##eq? lift1 (macro-absent-obj))
-         (##continuation-capture receiver))
-        ((##eq? lift2 (macro-absent-obj))
-         (##continuation-capture receiver lift1))
-        ((##eq? lift3 (macro-absent-obj))
-         (##continuation-capture receiver lift1 lift2))
-        ((##null? others)
-         (##continuation-capture receiver lift1 lift2 lift3))
-        (else
-         (let ((lifts
-                (##cons lift1
-                        (##cons lift2
-                                (##cons lift3
-                                        others)))))
-           (##continuation-capture
-            (lambda (cont)
-              (##apply receiver (##cons cont lifts))))))))
+  (if (not (##procedure? receiver))
+      (error "##continuation-capture-aux: got non-procedure receiver:" receiver))
+  (let ()
+    (##declare (not interrupts-enabled))
+    (cond ((##eq? lift1 (macro-absent-obj))
+	   (##continuation-capture receiver))
+	  ((##eq? lift2 (macro-absent-obj))
+	   (##continuation-capture receiver lift1))
+	  ((##eq? lift3 (macro-absent-obj))
+	   (##continuation-capture receiver lift1 lift2))
+	  ((##null? others)
+	   (##continuation-capture receiver lift1 lift2 lift3))
+	  (else
+	   (if (not (pair? others))
+	       (error "##continuation-capture-aux: not a list:" others))
+	   (let ((lifts
+		  (##cons lift1
+			  (##cons lift2
+				  (##cons lift3
+					  others)))))
+	     (##continuation-capture
+	      (lambda (cont)
+		(##apply receiver (##cons cont lifts)))))))))
 
 (define-prim (##continuation-capture
               receiver
-- 
1.6.0.4




More information about the Gambit-list mailing list