Parenthesize and type `SCM_FRAME' macros; check layout of `scm_vm_frame'.
authorLudovic Courtès <ludo@gnu.org>
Sun, 22 Jan 2012 22:20:50 +0000 (23:20 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sun, 22 Jan 2012 22:23:44 +0000 (23:23 +0100)
* libguile/frames.c: Add compile-time assertions on the layout of
  `struct scm_vm_frame'.
  (RELOC): Parenthesize and type VAL.

* libguile/frames.h (SCM_FRAME_STRUCT): Write in terms of
  `SCM_FRAME_DATA_ADDRESS'.
  (SCM_FRAME_DATA_ADDRESS): Parenthesize and type FP.
  (SCM_FRAME_SET_DYNAMIC_LINK): Write in terms of
  `SCM_FRAME_DYNAMIC_LINK'.

* libguile/vm.c (RELOC): Parenthesize and type SCM_P.

libguile/frames.c
libguile/frames.h
libguile/vm.c

index 2e83cde..c7505b2 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,
index ffb577a..eaed79d 100644 (file)
@@ -70,9 +70,10 @@ struct scm_vm_frame
   SCM stack[1]; /* Variable-length */
 };
 
-#define SCM_FRAME_STRUCT(fp)           ((struct scm_vm_frame*)(((SCM*)(fp)) - 4))
+#define SCM_FRAME_STRUCT(fp)                           \
+  ((struct scm_vm_frame *) SCM_FRAME_DATA_ADDRESS (fp))
 
-#define SCM_FRAME_DATA_ADDRESS(fp)     (fp - 4)
+#define SCM_FRAME_DATA_ADDRESS(fp)     (((SCM *) (fp)) - 4)
 #define SCM_FRAME_STACK_ADDRESS(fp)    (SCM_FRAME_STRUCT (fp)->stack)
 #define SCM_FRAME_UPPER_ADDRESS(fp)    ((SCM*)&SCM_FRAME_STRUCT (fp)->return_address)
 #define SCM_FRAME_LOWER_ADDRESS(fp)    ((SCM*)SCM_FRAME_STRUCT (fp))
@@ -91,7 +92,7 @@ struct scm_vm_frame
 #define SCM_FRAME_DYNAMIC_LINK(fp)              \
   (SCM_FRAME_STRUCT (fp)->dynamic_link)
 #define SCM_FRAME_SET_DYNAMIC_LINK(fp, dl)      \
-  SCM_FRAME_STRUCT (fp)->dynamic_link = (dl)
+  SCM_FRAME_DYNAMIC_LINK (fp) = (dl)
 #define SCM_FRAME_VARIABLE(fp,i)                \
   (SCM_FRAME_STRUCT (fp)->stack[i])
 #define SCM_FRAME_PROGRAM(fp)                   \
index 49df5cb..8fae656 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
@@ -280,7 +280,8 @@ vm_reinstate_partial_continuation (SCM vm, SCM cont, SCM intwinds,
   cp = SCM_VM_CONT_DATA (cont);
   base = SCM_FRAME_UPPER_ADDRESS (vp->fp) + 1;
 
-#define RELOC(scm_p) (scm_p + cp->reloc + (base - cp->stack_base))
+#define RELOC(scm_p)                                           \
+  (((SCM *) (scm_p)) + cp->reloc + (base - cp->stack_base))
 
   if ((base - vp->stack_base) + cp->stack_size + n + 1 > vp->stack_size)
     scm_misc_error ("vm-engine",