Re: [PATCH 1/1] Store and search for canonical Unicode text [WIP]
[notmuch-archives.git] / 20 / d993038e916430f62033992e4a22964f6ab363
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 20B43431FC2\r
6         for <notmuch@notmuchmail.org>; Wed, 27 Nov 2013 00:04:40 -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 InslMOSToKUO for <notmuch@notmuchmail.org>;\r
16         Wed, 27 Nov 2013 00:04:30 -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 598B7431FAE\r
19         for <notmuch@notmuchmail.org>; Wed, 27 Nov 2013 00:04:30 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 76F9810005E;\r
22         Wed, 27 Nov 2013 10:04:24 +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 v2] util: detect byte order\r
26 In-Reply-To: <1385512694-32526-1-git-send-email-david@tethera.net>\r
27 References: <m2txezqcuf.fsf@guru.guru-group.fi>\r
28         <1385512694-32526-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: Wed, 27 Nov 2013 10:04:24 +0200\r
35 Message-ID: <m2haaynud3.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\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: Wed, 27 Nov 2013 08:04:40 -0000\r
51 \r
52 On Wed, Nov 27 2013, david@tethera.net wrote:\r
53 \r
54 > From: David Bremner <david@tethera.net>\r
55 >\r
56 > Unfortunately old versions of GCC and clang do not provide byte order\r
57 > macros, so we re-invent them.\r
58 >\r
59 > If UTIL_BYTE_ORDER is not defined or defined to 0, we fall back to\r
60 > macros supported by recent versions of GCC and clang\r
61 > ---\r
62 >\r
63 > I think I got all of Tomi's comments, including the most serious one\r
64 > about the test in endian-utils.h (LITTLE twice instead of BIG,\r
65 > LITTLE).\r
66 \r
67 Agreed. LGTM.\r
68 \r
69 You may want to amend the '#' out of the line\r
70 \r
71 +#rm -f _byteorder _byteorder.c\r
72 \r
73 before pushing ?\r
74 \r
75 Tomi\r
76 \r
77 \r
78 >\r
79 >  configure          | 24 ++++++++++++++++++++++--\r
80 >  lib/libsha1.c      | 21 +++++++--------------\r
81 >  util/endian-util.h | 38 ++++++++++++++++++++++++++++++++++++++\r
82 >  3 files changed, 67 insertions(+), 16 deletions(-)\r
83 >  create mode 100644 util/endian-util.h\r
84 >\r
85 > diff --git a/configure b/configure\r
86 > index 1a8e939..a0c6771 100755\r
87 > --- a/configure\r
88 > +++ b/configure\r
89 > @@ -441,6 +441,19 @@ else\r
90 >  EOF\r
91 >  fi\r
92 >  \r
93 > +printf "Checking byte order... "\r
94 > +cat> _byteorder.c <<EOF\r
95 > +#include <stdio.h>\r
96 > +#include <stdint.h>\r
97 > +uint32_t test = 0x34333231;\r
98 > +int main() { printf("%.4s\n", (const char*)&test); return 0; }\r
99 > +EOF\r
100 > +${CC} ${CFLAGS} _byteorder.c -o _byteorder > /dev/null 2>&1\r
101 > +util_byte_order=$(./_byteorder)\r
102 > +echo $util_byte_order\r
103 > +\r
104 > +#rm -f _byteorder _byteorder.c\r
105 > +\r
106 >  if [ $errors -gt 0 ]; then\r
107 >      cat <<EOF\r
108 >  \r
109 > @@ -702,6 +715,9 @@ prefix = ${PREFIX}\r
110 >  # LIBDIR_IN_LDCONFIG value below is still set correctly.\r
111 >  libdir = ${LIBDIR:=\$(prefix)/lib}\r
112 >  \r
113 > +# byte order within a 32 bit word. 1234 = little, 4321 = big, 0 = guess\r
114 > +UTIL_BYTE_ORDER = ${util_byte_order}\r
115 > +\r
116 >  # Whether libdir is in a path configured into ldconfig\r
117 >  LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}\r
118 >  \r
119 > @@ -807,7 +823,9 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
120 >                  -DHAVE_STRSEP=\$(HAVE_STRSEP)                         \\\r
121 >                  -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\\r
122 >                  -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\\r
123 > -                -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
124 > +                -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)         \\\r
125 > +                -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
126 > +\r
127 >  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
128 >                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
129 >                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
130 > @@ -815,6 +833,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
131 >                    -DHAVE_STRSEP=\$(HAVE_STRSEP)                       \\\r
132 >                    -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\\r
133 >                    -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\\r
134 > -                  -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
135 > +                  -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
136 > +                  -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
137 > +\r
138 >  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
139 >  EOF\r
140 > diff --git a/lib/libsha1.c b/lib/libsha1.c\r
141 > index 87c7c52..aaaa4eb 100644\r
142 > --- a/lib/libsha1.c\r
143 > +++ b/lib/libsha1.c\r
144 > @@ -34,7 +34,7 @@\r
145 >  */\r
146 >  \r
147 >  #include <string.h>     /* for memcpy() etc.        */\r
148 > -\r
149 > +#include "endian-util.h"\r
150 >  #include "libsha1.h"\r
151 >  \r
152 >  #if defined(__cplusplus)\r
153 > @@ -49,20 +49,13 @@ extern "C"\r
154 >  \r
155 >  #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))\r
156 >  \r
157 > -/* The macros __BYTE_ORDER__ and __ORDER_*_ENDIAN__ are GNU C\r
158 > - * extensions. They are also supported by clang as of v3.2 */\r
159 > -\r
160 > -#ifdef __BYTE_ORDER__\r
161 > -#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
162 > -#    define bsw_32(p,n) \\r
163 > -       { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
164 > -#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
165 > -#    define bsw_32(p,n)\r
166 > -#  else\r
167 > -#    error "unknown byte order"\r
168 > -#  endif\r
169 > +#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN)\r
170 > +#  define bsw_32(p,n) \\r
171 > +     { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
172 > +#elif (UTIL_BYTE_ORDER == UTIL_ORDER_BIG_ENDIAN)\r
173 > +#  define bsw_32(p,n)\r
174 >  #else\r
175 > -#    error "macro __BYTE_ORDER__ is not defined"\r
176 > +#  error "Unsupported byte order"\r
177 >  #endif\r
178 >  \r
179 >  #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)\r
180 > diff --git a/util/endian-util.h b/util/endian-util.h\r
181 > new file mode 100644\r
182 > index 0000000..bc80c40\r
183 > --- /dev/null\r
184 > +++ b/util/endian-util.h\r
185 > @@ -0,0 +1,38 @@\r
186 > +/* this file mimics the macros present in recent GCC and CLANG */\r
187 > +\r
188 > +#ifndef _ENDIAN_UTIL_H\r
189 > +#define _ENDIAN_UTIL_H\r
190 > +\r
191 > +/* This are prefixed with UTIL to avoid collisions\r
192 > + *\r
193 > + * You can use something like the following to define UTIL_BYTE_ORDER\r
194 > + * in a configure script.\r
195 > + */\r
196 > +#if 0\r
197 > +#include <stdio.h>\r
198 > +#include <stdint.h>\r
199 > +uint32_t test = 0x34333231;\r
200 > +int main() { printf("%.4s\n", (const char*)&test); return 0; }\r
201 > +#endif\r
202 > +\r
203 > +#define UTIL_ORDER_BIG_ENDIAN          4321\r
204 > +#define UTIL_ORDER_LITTLE_ENDIAN  1234\r
205 > +\r
206 > +\r
207 > +#if !defined(UTIL_BYTE_ORDER) || ((UTIL_BYTE_ORDER != UTIL_ORDER_BIG_ENDIAN) && \\r
208 > +                               (UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN))\r
209 > +#undef UTIL_BYTE_ORDER\r
210 > +#ifdef __BYTE_ORDER__\r
211 > +#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
212 > +#    define UTIL_BYTE_ORDER UTIL_ORDER_LITTLE_ENDIAN\r
213 > +#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
214 > +#    define UTIL_BYTE_ORDER UTIL_ORDER_BIG_ENDIAN\r
215 > +#  else\r
216 > +#    error "Unsupported __BYTE_ORDER__"\r
217 > +#  endif\r
218 > +#else\r
219 > +#  error "UTIL_BYTE_ORDER not correctly defined and __BYTE_ORDER__ not defined."\r
220 > +#endif\r
221 > +#endif\r
222 > +\r
223 > +#endif\r
224 > -- \r
225 > 1.8.4.2\r
226 >\r
227 > _______________________________________________\r
228 > notmuch mailing list\r
229 > notmuch@notmuchmail.org\r
230 > http://notmuchmail.org/mailman/listinfo/notmuch\r