Add `scm_t_aligned_cell' internal type.
authorLudovic Courtès <ludo@gnu.org>
Fri, 28 May 2010 09:09:31 +0000 (11:09 +0200)
committerLudovic Courtès <ludo@gnu.org>
Fri, 28 May 2010 15:02:13 +0000 (17:02 +0200)
* libguile/_scm.h (struct scm_aligned_cell)[__GNUC__]: New type.
  (union scm_aligned_cell)[!__GNUC__]: New type.
  (scm_t_aligned_cell): New type.

* libguile/vm.c (vm_dispatch_hook): Use it.

libguile/_scm.h
libguile/vm.c

index 3bb78b4..f18b3a8 100644 (file)
@@ -63,6 +63,7 @@
 
 #include <errno.h>
 #include <verify.h>
+#include <alignof.h>
 #include "libguile/__scm.h"
 
 /* Include headers for those files central to the implementation.  The
 #define SCM_OBJCODE_COOKIE                              \
   "GOOF-" SCM_OBJCODE_MACHINE_VERSION_STRING "---"
 
+\f
+/* Cells have to be 8-byte aligned.  Use `scm_t_aligned_cell' when not
+   allocating on the heap to have this guarantee.  This is similar to the
+   `SCM_ALIGNED' macro but provides an option likely to work with compilers
+   other than GCC.  */
+
+#ifdef __GNUC__
+
+struct scm_aligned_cell
+{
+  scm_t_cell cell __attribute__ ((__aligned__ (8)));
+};
+
+typedef struct scm_aligned_cell scm_t_aligned_cell;
+
+#else /* !__GNUC__ */
+
+union scm_aligned_cell
+{
+  double alignment;
+  scm_t_cell cell;
+};
+
+typedef union scm_aligned_cell scm_t_aligned_cell;
+
+#endif /* !__GNUC__ */
+
+/* Make sure we get the right alignment.  */
+verify (alignof (scm_t_aligned_cell) >= 8);
 
 #endif  /* SCM__SCM_H */
 
index e036b63..972abf8 100644 (file)
@@ -190,11 +190,7 @@ vm_dispatch_hook (SCM vm, int hook_num)
   struct scm_vm *vp;
   SCM hook;
   struct scm_frame c_frame;
-  union
-  {
-    double alignment;
-    scm_t_cell cell;
-  } frame;
+  scm_t_aligned_cell frame;
   SCM args[1];
 
   vp = SCM_VM_DATA (vm);