1 Return-Path: <tomi.ollila@iki.fi>
\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 11620431FBF
\r
6 for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 09:42:34 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 5XqNGLVg1P+q for <notmuch@notmuchmail.org>;
\r
16 Tue, 26 Nov 2013 09:42:26 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 72D96431FC3
\r
19 for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 09:42:26 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id B161C10005E;
\r
22 Tue, 26 Nov 2013 19:42:16 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: david@tethera.net, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH] util: detect byte order
\r
26 In-Reply-To: <1385471257-31835-1-git-send-email-david@tethera.net>
\r
27 References: <1385328583-24602-2-git-send-email-david@tethera.net>
\r
28 <1385471257-31835-1-git-send-email-david@tethera.net>
\r
29 User-Agent: Notmuch/0.16+175~g19e97d6 (http://notmuchmail.org) Emacs/24.3.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Tue, 26 Nov 2013 19:42:16 +0200
\r
35 Message-ID: <m2txezqcuf.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Tue, 26 Nov 2013 17:42:34 -0000
\r
52 On Tue, Nov 26 2013, david@tethera.net wrote:
\r
54 > From: David Bremner <david@tethera.net>
\r
56 > Unfortunately old versions of GCC and clang do not provide byte order
\r
57 > macros, so we re-invent them.
\r
59 Brief comments inline :D
\r
62 > If UTIL_BYTE_ORDER is not defined, we fall back to macros supported by
\r
63 > recent versions of GCC and clang
\r
65 This is not entirely accurate as -DUTIL_BYTE_ORDER=... is given to
\r
66 compiler... maybe If UTIL_BYTE_ORDER is not defined, empty or zero (?)
\r
70 > I pushed the series
\r
71 > id:1385328583-24602-1-git-send-email-david@tethera.net; unfortunately
\r
72 > that broke compilation on old versions of GCC, in particular on our
\r
73 > buildbot. Here is a proposed fix for the fix.
\r
75 > configure | 26 ++++++++++++++++++++++++--
\r
76 > lib/libsha1.c | 19 +++++--------------
\r
77 > util/endian-util.h | 39 +++++++++++++++++++++++++++++++++++++++
\r
78 > 3 files changed, 68 insertions(+), 16 deletions(-)
\r
79 > create mode 100644 util/endian-util.h
\r
81 > diff --git a/configure b/configure
\r
82 > index 1a8e939..02d6396 100755
\r
85 > @@ -441,6 +441,21 @@ else
\r
89 > +printf "Checking byte order... "
\r
90 > +cat> _byteorder.c <<EOF
\r
91 > +#include <stdio.h>
\r
92 > +#include <stdint.h>
\r
93 > +#include <string.h>
\r
94 > +uint32_t test = 0x31323334;
\r
96 > +int main() { memcpy(buf, &test, 4); buf[4] = '\0'; printf("%s\n", buf); return 0; }
\r
98 > +${CC} ${CFLAGS} _byteorder.c -o _byteorder > /dev/null 2>&1
\r
99 > +util_byte_order=$(./_byteorder)
\r
100 > +echo $util_byte_order
\r
102 Austin version with 0x34333231
\r
105 > +#rm -f _byteorder _byteorder.c
\r
107 > if [ $errors -gt 0 ]; then
\r
110 > @@ -702,6 +717,9 @@ prefix = ${PREFIX}
\r
111 > # LIBDIR_IN_LDCONFIG value below is still set correctly.
\r
112 > libdir = ${LIBDIR:=\$(prefix)/lib}
\r
114 > +# byte order within a 32 bit word. 4321 = little, 1234 = big, 0 = guess
\r
115 > +UTIL_BYTE_ORDER = ${util_byte_order}
\r
117 > # Whether libdir is in a path configured into ldconfig
\r
118 > LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
\r
120 > @@ -807,7 +825,9 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
121 > -DHAVE_STRSEP=\$(HAVE_STRSEP) \\
\r
122 > -DSTD_GETPWUID=\$(STD_GETPWUID) \\
\r
123 > -DSTD_ASCTIME=\$(STD_ASCTIME) \\
\r
124 > - -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)
\r
125 > + -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
126 > + -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
128 > CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
129 > \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\r
130 > \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
\r
131 > @@ -815,6 +835,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
132 > -DHAVE_STRSEP=\$(HAVE_STRSEP) \\
\r
133 > -DSTD_GETPWUID=\$(STD_GETPWUID) \\
\r
134 > -DSTD_ASCTIME=\$(STD_ASCTIME) \\
\r
135 > - -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)
\r
136 > + -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
137 > + -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
139 > CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
141 > diff --git a/lib/libsha1.c b/lib/libsha1.c
\r
142 > index 87c7c52..3566ed7 100644
\r
143 > --- a/lib/libsha1.c
\r
144 > +++ b/lib/libsha1.c
\r
145 > @@ -34,7 +34,7 @@
\r
148 > #include <string.h> /* for memcpy() etc. */
\r
150 > +#include "endian-util.h"
\r
151 > #include "libsha1.h"
\r
153 > #if defined(__cplusplus)
\r
154 > @@ -49,20 +49,11 @@ extern "C"
\r
156 > #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))
\r
158 > -/* The macros __BYTE_ORDER__ and __ORDER_*_ENDIAN__ are GNU C
\r
159 > - * extensions. They are also supported by clang as of v3.2 */
\r
161 > -#ifdef __BYTE_ORDER__
\r
162 > -# if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
\r
163 > -# define bsw_32(p,n) \
\r
164 > - { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }
\r
165 > -# elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
\r
166 > -# define bsw_32(p,n)
\r
168 > -# error "unknown byte order"
\r
170 > +#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN)
\r
171 > +# define bsw_32(p,n) \
\r
172 > + { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }
\r
174 > -# error "macro __BYTE_ORDER__ is not defined"
\r
175 > +# define bsw_32(p,n)
\r
178 I'd keep the BIG_ENDIAN check too, as we don't know what would happen w/
\r
182 > #define SHA1_MASK (SHA1_BLOCK_SIZE - 1)
\r
183 > diff --git a/util/endian-util.h b/util/endian-util.h
\r
184 > new file mode 100644
\r
185 > index 0000000..cbecf66
\r
187 > +++ b/util/endian-util.h
\r
189 > +/* this file mimics the macros present in recent GCC and CLANG */
\r
191 > +#ifndef _ENDIAN_UTIL_H
\r
192 > +#define _ENDIAN_UTIL_H
\r
194 > +/* This are prefixed with UTIL to avoid collisions
\r
196 > + * You can use something like the following to define UTIL_BYTE_ORDER
\r
197 > + * in a configure script.
\r
200 > +#include <stdio.h>
\r
201 > +#include <stdint.h>
\r
202 > +#include <string.h>
\r
203 > +uint32_t test = 0x31323334;
\r
205 > +int main() { memcpy(buf, &test, 4); buf[4] = '\0'; printf("%s\n", buf); return 0; }
\r
208 The "fixed simpler version" version, or just reference configure.
\r
211 > +#define UTIL_ORDER_LITTLE_ENDIAN 4321
\r
212 > +#define UTIL_ORDER_BIG_ENDIAN 1234
\r
218 > +#if !defined(UTIL_BYTE_ORDER) || ((UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN) && \
\r
219 > + (UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN))
\r
221 for "guess" this needs to be #if !UTIL_BYTE_ORDER || ((UTIL_BYTE...
\r
222 ... as UTIL_BYTE_ORDER could be defined as 0 (or empty?) in configure.
\r
224 $ gcc -dM -DUTIL_BYTE_ORDER= -E - </dev/null | grep -i util
\r
225 #define UTIL_BYTE_ORDER
\r
230 > +#ifdef __BYTE_ORDER__
\r
231 > +# if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
\r
232 > +# define UTIL_BYTE_ORDER UTIL_ORDER_LITTLE_ENDIAN
\r
233 > +# elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
\r
234 > +# define UTIL_BYTE_ORDER UTIL_ORDER_BIG_ENDIAN
\r
236 > +# error "Unsupported __BYTE_ORDER__"
\r
239 > +# error "UTIL_BYTE_ORDER not correctly defined and __BYTE_ORDER__ not defined."
\r