Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 9a / 12608fc04c03bfe3b2974eae07e2eae5f34cdd
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 27627431FBF\r
6         for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 05:08:04 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id KfU3jAf6E6Ep for <notmuch@notmuchmail.org>;\r
16         Tue, 26 Nov 2013 05:07:56 -0800 (PST)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 33642431FB6\r
21         for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 05:07:56 -0800 (PST)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1VlIMq-0008Tq-Kw; Tue, 26 Nov 2013 09:07:52 -0400\r
25 Received: (nullmailer pid 31884 invoked by uid 1000); Tue, 26 Nov 2013\r
26         13:07:48 -0000\r
27 From: david@tethera.net\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [PATCH] util: detect byte order\r
30 Date: Tue, 26 Nov 2013 09:07:37 -0400\r
31 Message-Id: <1385471257-31835-1-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.8.4.2\r
33 In-Reply-To: <1385328583-24602-2-git-send-email-david@tethera.net>\r
34 References: <1385328583-24602-2-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Tue, 26 Nov 2013 13:08:04 -0000\r
48 \r
49 From: David Bremner <david@tethera.net>\r
50 \r
51 Unfortunately old versions of GCC and clang do not provide byte order\r
52 macros, so we re-invent them.\r
53 \r
54 If UTIL_BYTE_ORDER is not defined, we fall back to macros supported by\r
55 recent versions of GCC and clang\r
56 ---\r
57 \r
58 I pushed the series\r
59 id:1385328583-24602-1-git-send-email-david@tethera.net; unfortunately\r
60 that broke compilation on old versions of GCC, in particular on our\r
61 buildbot. Here is a proposed fix for the fix.\r
62 \r
63  configure          | 26 ++++++++++++++++++++++++--\r
64  lib/libsha1.c      | 19 +++++--------------\r
65  util/endian-util.h | 39 +++++++++++++++++++++++++++++++++++++++\r
66  3 files changed, 68 insertions(+), 16 deletions(-)\r
67  create mode 100644 util/endian-util.h\r
68 \r
69 diff --git a/configure b/configure\r
70 index 1a8e939..02d6396 100755\r
71 --- a/configure\r
72 +++ b/configure\r
73 @@ -441,6 +441,21 @@ else\r
74  EOF\r
75  fi\r
76  \r
77 +printf "Checking byte order... "\r
78 +cat> _byteorder.c <<EOF\r
79 +#include <stdio.h>\r
80 +#include <stdint.h>\r
81 +#include <string.h>\r
82 +uint32_t test = 0x31323334;\r
83 +char buf[5];\r
84 +int main() { memcpy(buf, &test, 4); buf[4] = '\0'; printf("%s\n", buf); return 0; }\r
85 +EOF\r
86 +${CC} ${CFLAGS} _byteorder.c -o _byteorder > /dev/null 2>&1\r
87 +util_byte_order=$(./_byteorder)\r
88 +echo $util_byte_order\r
89 +\r
90 +#rm -f _byteorder _byteorder.c\r
91 +\r
92  if [ $errors -gt 0 ]; then\r
93      cat <<EOF\r
94  \r
95 @@ -702,6 +717,9 @@ prefix = ${PREFIX}\r
96  # LIBDIR_IN_LDCONFIG value below is still set correctly.\r
97  libdir = ${LIBDIR:=\$(prefix)/lib}\r
98  \r
99 +# byte order within a 32 bit word. 4321 = little, 1234 = big, 0 = guess\r
100 +UTIL_BYTE_ORDER = ${util_byte_order}\r
101 +\r
102  # Whether libdir is in a path configured into ldconfig\r
103  LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}\r
104  \r
105 @@ -807,7 +825,9 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
106                    -DHAVE_STRSEP=\$(HAVE_STRSEP)                         \\\r
107                    -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\\r
108                    -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\\r
109 -                  -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
110 +                  -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)         \\\r
111 +                  -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
112 +\r
113  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
114                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
115                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
116 @@ -815,6 +835,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
117                      -DHAVE_STRSEP=\$(HAVE_STRSEP)                       \\\r
118                      -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\\r
119                      -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\\r
120 -                    -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
121 +                    -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
122 +                    -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
123 +\r
124  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
125  EOF\r
126 diff --git a/lib/libsha1.c b/lib/libsha1.c\r
127 index 87c7c52..3566ed7 100644\r
128 --- a/lib/libsha1.c\r
129 +++ b/lib/libsha1.c\r
130 @@ -34,7 +34,7 @@\r
131  */\r
132  \r
133  #include <string.h>     /* for memcpy() etc.        */\r
134 -\r
135 +#include "endian-util.h"\r
136  #include "libsha1.h"\r
137  \r
138  #if defined(__cplusplus)\r
139 @@ -49,20 +49,11 @@ extern "C"\r
140  \r
141  #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))\r
142  \r
143 -/* The macros __BYTE_ORDER__ and __ORDER_*_ENDIAN__ are GNU C\r
144 - * extensions. They are also supported by clang as of v3.2 */\r
145 -\r
146 -#ifdef __BYTE_ORDER__\r
147 -#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
148 -#    define bsw_32(p,n) \\r
149 -       { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
150 -#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
151 -#    define bsw_32(p,n)\r
152 -#  else\r
153 -#    error "unknown byte order"\r
154 -#  endif\r
155 +#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN)\r
156 +#  define bsw_32(p,n) \\r
157 +     { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
158  #else\r
159 -#    error "macro __BYTE_ORDER__ is not defined"\r
160 +#  define bsw_32(p,n)\r
161  #endif\r
162  \r
163  #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)\r
164 diff --git a/util/endian-util.h b/util/endian-util.h\r
165 new file mode 100644\r
166 index 0000000..cbecf66\r
167 --- /dev/null\r
168 +++ b/util/endian-util.h\r
169 @@ -0,0 +1,39 @@\r
170 +/* this file mimics the macros present in recent GCC and CLANG */\r
171 +\r
172 +#ifndef _ENDIAN_UTIL_H\r
173 +#define _ENDIAN_UTIL_H\r
174 +\r
175 +/* This are prefixed with UTIL to avoid collisions\r
176 + *\r
177 + * You can use something like the following to define UTIL_BYTE_ORDER\r
178 + * in a configure script.\r
179 + */\r
180 +#if 0\r
181 +#include <stdio.h>\r
182 +#include <stdint.h>\r
183 +#include <string.h>\r
184 +uint32_t test = 0x31323334;\r
185 +char buf[5];\r
186 +int main() { memcpy(buf, &test, 4); buf[4] = '\0'; printf("%s\n", buf); return 0; }\r
187 +#endif\r
188 +\r
189 +#define UTIL_ORDER_LITTLE_ENDIAN 4321\r
190 +#define UTIL_ORDER_BIG_ENDIAN    1234\r
191 +\r
192 +\r
193 +#if !defined(UTIL_BYTE_ORDER) || ((UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN) && \\r
194 +                                  (UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN))\r
195 +#ifdef __BYTE_ORDER__\r
196 +#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
197 +#    define UTIL_BYTE_ORDER UTIL_ORDER_LITTLE_ENDIAN\r
198 +#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
199 +#    define UTIL_BYTE_ORDER UTIL_ORDER_BIG_ENDIAN\r
200 +#  else\r
201 +#    error "Unsupported __BYTE_ORDER__"\r
202 +#  endif\r
203 +#else\r
204 +#  error "UTIL_BYTE_ORDER not correctly defined and __BYTE_ORDER__ not defined."\r
205 +#endif\r
206 +#endif\r
207 +\r
208 +#endif\r
209 -- \r
210 1.8.4.2\r
211 \r