Merge remote-tracking branch 'local-2.0/stable-2.0'
[bpt/guile.git] / libguile / frames.c
index 2e83cde..b90b5a2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001, 2009, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
 #include <string.h>
 #include "_scm.h"
 #include "frames.h"
+#include <verify.h>
+
+/* Make sure assumptions on the layout of `struct scm_vm_frame' hold.  */
+verify (sizeof (SCM) == sizeof (SCM *));
+verify (sizeof (struct scm_vm_frame) == 5 * sizeof (SCM));
+verify (offsetof (struct scm_vm_frame, dynamic_link) == 0);
 
 \f
-#define RELOC(frame, val) (val + SCM_VM_FRAME_OFFSET (frame))
+#define RELOC(frame, val)                              \
+  (((SCM *) (val)) + SCM_VM_FRAME_OFFSET (frame))
 
 SCM
 scm_c_make_frame (SCM stack_holder, SCM *fp, SCM *sp,
@@ -45,12 +52,12 @@ scm_c_make_frame (SCM stack_holder, SCM *fp, SCM *sp,
 void
 scm_i_frame_print (SCM frame, SCM port, scm_print_state *pstate)
 {
-  scm_puts ("#<frame ", port);
+  scm_puts_unlocked ("#<frame ", port);
   scm_uintprint (SCM_UNPACK (frame), 16, port);
-  scm_putc (' ', port);
+  scm_putc_unlocked (' ', port);
   scm_write (scm_frame_procedure (frame), port);
   /* don't write args, they can get us into trouble. */
-  scm_puts (">", port);
+  scm_puts_unlocked (">", port);
 }
 
 \f
@@ -230,11 +237,16 @@ SCM_DEFINE (scm_frame_instruction_pointer, "frame-instruction-pointer", 1, 0, 0,
            "")
 #define FUNC_NAME s_scm_frame_instruction_pointer
 {
+  SCM program;
   const struct scm_objcode *c_objcode;
 
   SCM_VALIDATE_VM_FRAME (1, frame);
+  program = scm_frame_procedure (frame);
+
+  if (!SCM_PROGRAM_P (program))
+    return SCM_INUM0;
 
-  c_objcode = SCM_PROGRAM_DATA (scm_frame_procedure (frame));
+  c_objcode = SCM_PROGRAM_DATA (program);
   return scm_from_unsigned_integer ((SCM_VM_FRAME_IP (frame)
                                      - SCM_C_OBJCODE_BASE (c_objcode)));
 }