1 Return-Path: <jani@nikula.org>
\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 1F600431FDD
\r
6 for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:40:36 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5
\r
12 tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 UnOZiGwkTIwR for <notmuch@notmuchmail.org>;
\r
16 Thu, 23 Oct 2014 21:40:28 -0700 (PDT)
\r
17 Received: from mail-la0-f48.google.com (mail-la0-f48.google.com
\r
18 [209.85.215.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 5F3DB431FDC
\r
21 for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:40:28 -0700 (PDT)
\r
22 Received: by mail-la0-f48.google.com with SMTP id gi9so1966483lab.21
\r
23 for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:40:25 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=1e100.net; s=20130820;
\r
26 h=x-gm-message-state:mime-version:in-reply-to:references:date
\r
27 :message-id:subject:from:to:cc:content-type;
\r
28 bh=BQi7AgBJzl1M8yMutnXjYAo46AeFFQdOPzxbhPuq1F0=;
\r
29 b=NmDEHvd1y52ANM/FsSu5jU3WzmNWktvPShuTUY7NSFprTwmOTLfIl8tJ2a2IqDXg5v
\r
30 kcRZ1Cpx91Frs/2oXChdYmp/EVWPzZy8Y9GuBA0oZmsV5x2rXfpNU49ygFsW3gPIEOaF
\r
31 lEYdKaXuLQ55kMHCO0oQNZ3A08la/SleSEm0TvSEmk31F7SoCO/HVRDndrUioPMatlCZ
\r
32 xuP07mUKIz61NyMtTaNpqI8o++GJnfICNVqED3CqojDuHiBCozxDS9B/N5N6/q/Igk/e
\r
33 rb4yDGYDbtN/s4zG47pDgQBw42yabM4Qo+gVuylwikEyNq0EsS9uzs0nP5QmQ2QzHOVn
\r
36 ALoCoQnJKFx4G4udFAZq9Ld8gli2h35wXO3mDfvpC9G7OOj+u+ycR9nXMc+uydlnb40MxoVtZ44m
\r
38 X-Received: by 10.152.7.7 with SMTP id f7mr1666883laa.57.1414125625506; Thu,
\r
39 23 Oct 2014 21:40:25 -0700 (PDT)
\r
40 Received: by 10.25.145.7 with HTTP; Thu, 23 Oct 2014 21:40:25 -0700 (PDT)
\r
41 Received: by 10.25.145.7 with HTTP; Thu, 23 Oct 2014 21:40:25 -0700 (PDT)
\r
42 In-Reply-To: <1414067441-29054-4-git-send-email-aclements@csail.mit.edu>
\r
43 References: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>
\r
44 <1414067441-29054-4-git-send-email-aclements@csail.mit.edu>
\r
45 Date: Fri, 24 Oct 2014 07:40:25 +0300
\r
47 <CAB+hUn_d3Wp2bie3E6n1gtb9J_NypAv5rHmr3ObAqWsOX-hzFw@mail.gmail.com>
\r
48 Subject: Re: [PATCH v3 3/9] lib: Introduce macros for bit operations
\r
49 From: Jani Nikula <jani@nikula.org>
\r
50 To: Austin Clements <aclements@csail.mit.edu>
\r
51 Content-Type: multipart/alternative; boundary=001a11c2870a939325050623c78e
\r
52 Cc: Notmuch Mail <notmuch@notmuchmail.org>
\r
53 X-BeenThere: notmuch@notmuchmail.org
\r
54 X-Mailman-Version: 2.1.13
\r
56 List-Id: "Use and development of the notmuch mail system."
\r
57 <notmuch.notmuchmail.org>
\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
61 List-Post: <mailto:notmuch@notmuchmail.org>
\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
65 X-List-Received-Date: Fri, 24 Oct 2014 04:40:36 -0000
\r
67 --001a11c2870a939325050623c78e
\r
68 Content-Type: text/plain; charset=UTF-8
\r
70 On Oct 23, 2014 3:31 PM, "Austin Clements" <aclements@csail.mit.edu> wrote:
\r
72 > These macros help clarify basic bit-twiddling code and are written to
\r
73 > be robust against C undefined behavior of shift operators.
\r
75 > lib/message.cc | 6 +++---
\r
76 > lib/notmuch-private.h | 11 +++++++++++
\r
77 > 2 files changed, 14 insertions(+), 3 deletions(-)
\r
79 > diff --git a/lib/message.cc b/lib/message.cc
\r
80 > index 38bc929..55d2ff6 100644
\r
81 > --- a/lib/message.cc
\r
82 > +++ b/lib/message.cc
\r
83 > @@ -869,7 +869,7 @@ notmuch_bool_t
\r
84 > notmuch_message_get_flag (notmuch_message_t *message,
\r
85 > notmuch_message_flag_t flag)
\r
87 > - return message->flags & (1 << flag);
\r
88 > + return NOTMUCH_TEST_BIT (message->flags, flag);
\r
92 > @@ -877,9 +877,9 @@ notmuch_message_set_flag (notmuch_message_t *message,
\r
93 > notmuch_message_flag_t flag, notmuch_bool_t
\r
97 > - message->flags |= (1 << flag);
\r
98 > + NOTMUCH_SET_BIT (&message->flags, flag);
\r
100 > - message->flags &= ~(1 << flag);
\r
101 > + NOTMUCH_CLEAR_BIT (&message->flags, flag);
\r
105 > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
106 > index 36cc12b..7250291 100644
\r
107 > --- a/lib/notmuch-private.h
\r
108 > +++ b/lib/notmuch-private.h
\r
109 > @@ -63,6 +63,17 @@ NOTMUCH_BEGIN_DECLS
\r
110 > #define STRNCMP_LITERAL(var, literal) \
\r
111 > strncmp ((var), (literal), sizeof (literal) - 1)
\r
113 > +/* Robust bit test/set/reset macros */
\r
114 > +#define NOTMUCH_TEST_BIT(val, bit) \
\r
115 > + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? 0 \
\r
116 > + : !!((val) & (1ull << bit)))
\r
117 > +#define NOTMUCH_SET_BIT(valp, bit) \
\r
118 > + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ?
\r
120 > + : (*(valp) |= (1ull << bit)))
\r
121 > +#define NOTMUCH_CLEAR_BIT(valp, bit) \
\r
122 > + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ?
\r
124 > + : (*(valp) &= ~(1ull << bit)))
\r
126 bit should be in braces in the above, like valp.
\r
131 > #define unused(x) x __attribute__ ((unused))
\r
133 > #ifdef __cplusplus
\r
137 > _______________________________________________
\r
138 > notmuch mailing list
\r
139 > notmuch@notmuchmail.org
\r
140 > http://notmuchmail.org/mailman/listinfo/notmuch
\r
142 --001a11c2870a939325050623c78e
\r
143 Content-Type: text/html; charset=UTF-8
\r
144 Content-Transfer-Encoding: quoted-printable
\r
146 <p dir=3D"ltr"><br>
\r
147 On Oct 23, 2014 3:31 PM, "Austin Clements" <<a href=3D"mailto:=
\r
148 aclements@csail.mit.edu">aclements@csail.mit.edu</a>> wrote:<br>
\r
150 > These macros help clarify basic bit-twiddling code and are written to<=
\r
152 > be robust against C undefined behavior of shift operators.<br>
\r
154 > =C2=A0lib/message.cc=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 6 +++---<br>
\r
155 > =C2=A0lib/notmuch-private.h | 11 +++++++++++<br>
\r
156 > =C2=A02 files changed, 14 insertions(+), 3 deletions(-)<br>
\r
158 > diff --git a/lib/message.cc b/lib/message.cc<br>
\r
159 > index 38bc929..55d2ff6 100644<br>
\r
160 > --- a/lib/message.cc<br>
\r
161 > +++ b/lib/message.cc<br>
\r
162 > @@ -869,7 +869,7 @@ notmuch_bool_t<br>
\r
163 > =C2=A0notmuch_message_get_flag (notmuch_message_t *message,<br>
\r
164 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
\r
165 =C2=A0 =C2=A0 =C2=A0 notmuch_message_flag_t flag)<br>
\r
167 > -=C2=A0 =C2=A0 return message->flags & (1 << flag);<br>
\r
168 > +=C2=A0 =C2=A0 return NOTMUCH_TEST_BIT (message->flags, flag);<br>
\r
171 > =C2=A0void<br>
\r
172 > @@ -877,9 +877,9 @@ notmuch_message_set_flag (notmuch_message_t *messa=
\r
174 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
\r
175 =C2=A0 =C2=A0 =C2=A0 notmuch_message_flag_t flag, notmuch_bool_t enable)<br=
\r
178 > =C2=A0 =C2=A0 =C2=A0if (enable)<br>
\r
179 > -=C2=A0 =C2=A0 =C2=A0 =C2=A0message->flags |=3D (1 << flag);<=
\r
181 > +=C2=A0 =C2=A0 =C2=A0 =C2=A0NOTMUCH_SET_BIT (&message->flags, f=
\r
183 > =C2=A0 =C2=A0 =C2=A0else<br>
\r
184 > -=C2=A0 =C2=A0 =C2=A0 =C2=A0message->flags &=3D ~(1 << fl=
\r
186 > +=C2=A0 =C2=A0 =C2=A0 =C2=A0NOTMUCH_CLEAR_BIT (&message->flags,=
\r
190 > =C2=A0time_t<br>
\r
191 > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h<br>
\r
192 > index 36cc12b..7250291 100644<br>
\r
193 > --- a/lib/notmuch-private.h<br>
\r
194 > +++ b/lib/notmuch-private.h<br>
\r
195 > @@ -63,6 +63,17 @@ NOTMUCH_BEGIN_DECLS<br>
\r
196 > =C2=A0#define STRNCMP_LITERAL(var, literal) \<br>
\r
197 > =C2=A0 =C2=A0 =C2=A0strncmp ((var), (literal), sizeof (literal) - 1)<b=
\r
200 > +/* Robust bit test/set/reset macros */<br>
\r
201 > +#define NOTMUCH_TEST_BIT(val, bit) \<br>
\r
202 > +=C2=A0 =C2=A0 ((bit < 0 || bit >=3D CHAR_BIT * sizeof (unsigned=
\r
203 long long)) ? 0=C2=A0 =C2=A0 \<br>
\r
204 > +=C2=A0 =C2=A0 =C2=A0: !!((val) & (1ull << bit)))<br>
\r
205 > +#define NOTMUCH_SET_BIT(valp, bit) \<br>
\r
206 > +=C2=A0 =C2=A0 ((bit < 0 || bit >=3D CHAR_BIT * sizeof (unsigned=
\r
207 long long)) ? *(valp) \<br>
\r
208 > +=C2=A0 =C2=A0 =C2=A0: (*(valp) |=3D (1ull << bit)))<br>
\r
209 > +#define NOTMUCH_CLEAR_BIT(valp,=C2=A0 bit) \<br>
\r
210 > +=C2=A0 =C2=A0 ((bit < 0 || bit >=3D CHAR_BIT * sizeof (unsigned=
\r
211 long long)) ? *(valp) \<br>
\r
212 > +=C2=A0 =C2=A0 =C2=A0: (*(valp) &=3D ~(1ull << bit)))</p>
\r
213 <p dir=3D"ltr">bit should be in braces in the above, like valp.</p>
\r
214 <p dir=3D"ltr">Jani.</p>
\r
215 <p dir=3D"ltr">> +<br>
\r
216 > =C2=A0#define unused(x) x __attribute__ ((unused))<br>
\r
218 > =C2=A0#ifdef __cplusplus<br>
\r
222 > _______________________________________________<br>
\r
223 > notmuch mailing list<br>
\r
224 > <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=
\r
226 > <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=
\r
227 muchmail.org/mailman/listinfo/notmuch</a><br>
\r
230 --001a11c2870a939325050623c78e--
\r