--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1F600431FDD\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:40:36 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+ tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id UnOZiGwkTIwR for <notmuch@notmuchmail.org>;\r
+ Thu, 23 Oct 2014 21:40:28 -0700 (PDT)\r
+Received: from mail-la0-f48.google.com (mail-la0-f48.google.com\r
+ [209.85.215.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 5F3DB431FDC\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:40:28 -0700 (PDT)\r
+Received: by mail-la0-f48.google.com with SMTP id gi9so1966483lab.21\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:40:25 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:mime-version:in-reply-to:references:date\r
+ :message-id:subject:from:to:cc:content-type;\r
+ bh=BQi7AgBJzl1M8yMutnXjYAo46AeFFQdOPzxbhPuq1F0=;\r
+ b=NmDEHvd1y52ANM/FsSu5jU3WzmNWktvPShuTUY7NSFprTwmOTLfIl8tJ2a2IqDXg5v\r
+ kcRZ1Cpx91Frs/2oXChdYmp/EVWPzZy8Y9GuBA0oZmsV5x2rXfpNU49ygFsW3gPIEOaF\r
+ lEYdKaXuLQ55kMHCO0oQNZ3A08la/SleSEm0TvSEmk31F7SoCO/HVRDndrUioPMatlCZ\r
+ xuP07mUKIz61NyMtTaNpqI8o++GJnfICNVqED3CqojDuHiBCozxDS9B/N5N6/q/Igk/e\r
+ rb4yDGYDbtN/s4zG47pDgQBw42yabM4Qo+gVuylwikEyNq0EsS9uzs0nP5QmQ2QzHOVn\r
+ jCHg==\r
+X-Gm-Message-State:\r
+ ALoCoQnJKFx4G4udFAZq9Ld8gli2h35wXO3mDfvpC9G7OOj+u+ycR9nXMc+uydlnb40MxoVtZ44m\r
+MIME-Version: 1.0\r
+X-Received: by 10.152.7.7 with SMTP id f7mr1666883laa.57.1414125625506; Thu,\r
+ 23 Oct 2014 21:40:25 -0700 (PDT)\r
+Received: by 10.25.145.7 with HTTP; Thu, 23 Oct 2014 21:40:25 -0700 (PDT)\r
+Received: by 10.25.145.7 with HTTP; Thu, 23 Oct 2014 21:40:25 -0700 (PDT)\r
+In-Reply-To: <1414067441-29054-4-git-send-email-aclements@csail.mit.edu>\r
+References: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>\r
+ <1414067441-29054-4-git-send-email-aclements@csail.mit.edu>\r
+Date: Fri, 24 Oct 2014 07:40:25 +0300\r
+Message-ID:\r
+ <CAB+hUn_d3Wp2bie3E6n1gtb9J_NypAv5rHmr3ObAqWsOX-hzFw@mail.gmail.com>\r
+Subject: Re: [PATCH v3 3/9] lib: Introduce macros for bit operations\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Austin Clements <aclements@csail.mit.edu>\r
+Content-Type: multipart/alternative; boundary=001a11c2870a939325050623c78e\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 24 Oct 2014 04:40:36 -0000\r
+\r
+--001a11c2870a939325050623c78e\r
+Content-Type: text/plain; charset=UTF-8\r
+\r
+On Oct 23, 2014 3:31 PM, "Austin Clements" <aclements@csail.mit.edu> wrote:\r
+>\r
+> These macros help clarify basic bit-twiddling code and are written to\r
+> be robust against C undefined behavior of shift operators.\r
+> ---\r
+> lib/message.cc | 6 +++---\r
+> lib/notmuch-private.h | 11 +++++++++++\r
+> 2 files changed, 14 insertions(+), 3 deletions(-)\r
+>\r
+> diff --git a/lib/message.cc b/lib/message.cc\r
+> index 38bc929..55d2ff6 100644\r
+> --- a/lib/message.cc\r
+> +++ b/lib/message.cc\r
+> @@ -869,7 +869,7 @@ notmuch_bool_t\r
+> notmuch_message_get_flag (notmuch_message_t *message,\r
+> notmuch_message_flag_t flag)\r
+> {\r
+> - return message->flags & (1 << flag);\r
+> + return NOTMUCH_TEST_BIT (message->flags, flag);\r
+> }\r
+>\r
+> void\r
+> @@ -877,9 +877,9 @@ notmuch_message_set_flag (notmuch_message_t *message,\r
+> notmuch_message_flag_t flag, notmuch_bool_t\r
+enable)\r
+> {\r
+> if (enable)\r
+> - message->flags |= (1 << flag);\r
+> + NOTMUCH_SET_BIT (&message->flags, flag);\r
+> else\r
+> - message->flags &= ~(1 << flag);\r
+> + NOTMUCH_CLEAR_BIT (&message->flags, flag);\r
+> }\r
+>\r
+> time_t\r
+> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> index 36cc12b..7250291 100644\r
+> --- a/lib/notmuch-private.h\r
+> +++ b/lib/notmuch-private.h\r
+> @@ -63,6 +63,17 @@ NOTMUCH_BEGIN_DECLS\r
+> #define STRNCMP_LITERAL(var, literal) \\r
+> strncmp ((var), (literal), sizeof (literal) - 1)\r
+>\r
+> +/* Robust bit test/set/reset macros */\r
+> +#define NOTMUCH_TEST_BIT(val, bit) \\r
+> + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? 0 \\r
+> + : !!((val) & (1ull << bit)))\r
+> +#define NOTMUCH_SET_BIT(valp, bit) \\r
+> + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ?\r
+*(valp) \\r
+> + : (*(valp) |= (1ull << bit)))\r
+> +#define NOTMUCH_CLEAR_BIT(valp, bit) \\r
+> + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ?\r
+*(valp) \\r
+> + : (*(valp) &= ~(1ull << bit)))\r
+\r
+bit should be in braces in the above, like valp.\r
+\r
+Jani.\r
+\r
+> +\r
+> #define unused(x) x __attribute__ ((unused))\r
+>\r
+> #ifdef __cplusplus\r
+> --\r
+> 2.1.0\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--001a11c2870a939325050623c78e\r
+Content-Type: text/html; charset=UTF-8\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+<p dir=3D"ltr"><br>\r
+On Oct 23, 2014 3:31 PM, "Austin Clements" <<a href=3D"mailto:=\r
+aclements@csail.mit.edu">aclements@csail.mit.edu</a>> wrote:<br>\r
+><br>\r
+> These macros help clarify basic bit-twiddling code and are written to<=\r
+br>\r
+> be robust against C undefined behavior of shift operators.<br>\r
+> ---<br>\r
+> =C2=A0lib/message.cc=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 6 +++---<br>\r
+> =C2=A0lib/notmuch-private.h | 11 +++++++++++<br>\r
+> =C2=A02 files changed, 14 insertions(+), 3 deletions(-)<br>\r
+><br>\r
+> diff --git a/lib/message.cc b/lib/message.cc<br>\r
+> index 38bc929..55d2ff6 100644<br>\r
+> --- a/lib/message.cc<br>\r
+> +++ b/lib/message.cc<br>\r
+> @@ -869,7 +869,7 @@ notmuch_bool_t<br>\r
+> =C2=A0notmuch_message_get_flag (notmuch_message_t *message,<br>\r
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0 =C2=A0 notmuch_message_flag_t flag)<br>\r
+> =C2=A0{<br>\r
+> -=C2=A0 =C2=A0 return message->flags & (1 << flag);<br>\r
+> +=C2=A0 =C2=A0 return NOTMUCH_TEST_BIT (message->flags, flag);<br>\r
+> =C2=A0}<br>\r
+><br>\r
+> =C2=A0void<br>\r
+> @@ -877,9 +877,9 @@ notmuch_message_set_flag (notmuch_message_t *messa=\r
+ge,<br>\r
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0 =C2=A0 notmuch_message_flag_t flag, notmuch_bool_t enable)<br=\r
+>\r
+> =C2=A0{<br>\r
+> =C2=A0 =C2=A0 =C2=A0if (enable)<br>\r
+> -=C2=A0 =C2=A0 =C2=A0 =C2=A0message->flags |=3D (1 << flag);<=\r
+br>\r
+> +=C2=A0 =C2=A0 =C2=A0 =C2=A0NOTMUCH_SET_BIT (&message->flags, f=\r
+lag);<br>\r
+> =C2=A0 =C2=A0 =C2=A0else<br>\r
+> -=C2=A0 =C2=A0 =C2=A0 =C2=A0message->flags &=3D ~(1 << fl=\r
+ag);<br>\r
+> +=C2=A0 =C2=A0 =C2=A0 =C2=A0NOTMUCH_CLEAR_BIT (&message->flags,=\r
+ flag);<br>\r
+> =C2=A0}<br>\r
+><br>\r
+> =C2=A0time_t<br>\r
+> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h<br>\r
+> index 36cc12b..7250291 100644<br>\r
+> --- a/lib/notmuch-private.h<br>\r
+> +++ b/lib/notmuch-private.h<br>\r
+> @@ -63,6 +63,17 @@ NOTMUCH_BEGIN_DECLS<br>\r
+> =C2=A0#define STRNCMP_LITERAL(var, literal) \<br>\r
+> =C2=A0 =C2=A0 =C2=A0strncmp ((var), (literal), sizeof (literal) - 1)<b=\r
+r>\r
+><br>\r
+> +/* Robust bit test/set/reset macros */<br>\r
+> +#define NOTMUCH_TEST_BIT(val, bit) \<br>\r
+> +=C2=A0 =C2=A0 ((bit < 0 || bit >=3D CHAR_BIT * sizeof (unsigned=\r
+ long long)) ? 0=C2=A0 =C2=A0 \<br>\r
+> +=C2=A0 =C2=A0 =C2=A0: !!((val) & (1ull << bit)))<br>\r
+> +#define NOTMUCH_SET_BIT(valp, bit) \<br>\r
+> +=C2=A0 =C2=A0 ((bit < 0 || bit >=3D CHAR_BIT * sizeof (unsigned=\r
+ long long)) ? *(valp) \<br>\r
+> +=C2=A0 =C2=A0 =C2=A0: (*(valp) |=3D (1ull << bit)))<br>\r
+> +#define NOTMUCH_CLEAR_BIT(valp,=C2=A0 bit) \<br>\r
+> +=C2=A0 =C2=A0 ((bit < 0 || bit >=3D CHAR_BIT * sizeof (unsigned=\r
+ long long)) ? *(valp) \<br>\r
+> +=C2=A0 =C2=A0 =C2=A0: (*(valp) &=3D ~(1ull << bit)))</p>\r
+<p dir=3D"ltr">bit should be in braces in the above, like valp.</p>\r
+<p dir=3D"ltr">Jani.</p>\r
+<p dir=3D"ltr">> +<br>\r
+> =C2=A0#define unused(x) x __attribute__ ((unused))<br>\r
+><br>\r
+> =C2=A0#ifdef __cplusplus<br>\r
+> --<br>\r
+> 2.1.0<br>\r
+><br>\r
+> _______________________________________________<br>\r
+> notmuch mailing list<br>\r
+> <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=\r
+<br>\r
+> <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=\r
+muchmail.org/mailman/listinfo/notmuch</a><br>\r
+</p>\r
+\r
+--001a11c2870a939325050623c78e--\r