alignment alternative

Clint Adams schizo at debian.org
Tue Oct 29 06:11:31 CET 2002


This determines the alignment boundary at configure-time, rather than
compile-time.  It uses a method that autoconf upstream calls "sadistic",
and provides no real advantage over the other method.  Nevertheless, it
seems preferable to me.

Index: configure.in
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/configure.in,v
retrieving revision 1.19
diff -u -r1.19 configure.in
--- configure.in	26 Oct 2002 01:13:00 -0000	1.19
+++ configure.in	29 Oct 2002 04:49:58 -0000
@@ -85,4 +85,31 @@
 
 AC_CHECK_FUNCS(alarm bzero ftruncate memset mkdir socket strdup strerror flock lockf fcntl)
 
+AH_TEMPLATE([BOGOFILTER_ALIGNMENT],[alignment])
+AC_MSG_CHECKING(alignment)
+AC_TRY_RUN(
+[
+ int main()
+ {
+ #include <stddef.h>
+
+ #ifndef offsetof
+ #define offsetof(type, member) ( (int) & ((type*)0) -> member )               
+ #endif
+ 
+ struct dummy { char *c; int  i; };
+
+ return offsetof(struct dummy,i);
+ }
+],
+[
+AC_MSG_ERROR([problem determining alignment])
+],
+[
+ali=$?
+AC_DEFINE_UNQUOTED(BOGOFILTER_ALIGNMENT, $ali)
+AC_MSG_RESULT($ali)
+]
+)
+
 AC_OUTPUT(Makefile tests/Makefile tests/bogoutil/Makefile bogofilter.spec)
Index: wordhash.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/wordhash.c,v
retrieving revision 1.9
diff -u -r1.9 wordhash.c
--- wordhash.c	29 Oct 2002 04:15:11 -0000	1.9
+++ wordhash.c	29 Oct 2002 04:49:58 -0000
@@ -30,6 +30,7 @@
 
 #include "xmalloc.h"
 #include "wordhash.h"
+#include "config.h"
 
 #define NHASH 29989
 #define MULT 31
@@ -46,15 +47,10 @@
 {
   int i;
 
-  /*used to determine alignment requirements */
-  struct dummy { char *c; int  i; };
-  
   wordhash_t *h = xmalloc (sizeof (wordhash_t));
 
   h->bin = xmalloc (NHASH * sizeof (hashnode_t **));
   
-  h->alignment = offsetof(struct dummy, i);
-  
   for (i = 0; i < NHASH; i++)
     h->bin[i] = NULL;
 
@@ -122,7 +118,7 @@
   char *t;
 
   /* Force alignment on architecture's natural boundary.*/
-  n += h->alignment - ( n % h->alignment);
+  n += BOGOFILTER_ALIGNMENT - ( n % BOGOFILTER_ALIGNMENT );
    
   if (x == NULL || x->avail < n)
     {
Index: wordhash.h
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/wordhash.h,v
retrieving revision 1.6
diff -u -r1.6 wordhash.h
--- wordhash.h	29 Oct 2002 03:51:17 -0000	1.6
+++ wordhash.h	29 Oct 2002 04:49:58 -0000
@@ -30,8 +30,6 @@
   wh_alloc_node *nodes; /*list of node buffers */
   wh_alloc_str  *strings; /* list of string buffers */
 
-  size_t alignment;			 /* Architecture's alignment boundary */
-
   hashnode_t *iter_ptr;
   hashnode_t *iter_head;
   hashnode_t *iter_tail;




More information about the bogofilter-dev mailing list