1 Return-Path: <aclements@csail.mit.edu>
\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 1D254429E2F
\r
6 for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 05:31:01 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 Pjfgh+gUkqfu for <notmuch@notmuchmail.org>;
\r
16 Thu, 23 Oct 2014 05:30:52 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 46CBA431FD7
\r
22 for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 05:30:52 -0700 (PDT)
\r
23 X-AuditID: 12074425-f79e46d000002583-90-5448f4fbe9df
\r
24 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
25 (using TLS with cipher AES256-SHA (256/256 bits))
\r
26 (Client did not present a certificate)
\r
27 by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP
\r
28 id 0C.F4.09603.BF4F8445; Thu, 23 Oct 2014 08:30:51 -0400 (EDT)
\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
30 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s9NCUmxd030363;
\r
31 Thu, 23 Oct 2014 08:30:48 -0400
\r
32 Received: from drake.dyndns.org
\r
33 (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
34 [216.15.114.40]) (authenticated bits=0)
\r
35 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
36 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s9NCUhFr008930
\r
37 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);
\r
38 Thu, 23 Oct 2014 08:30:46 -0400
\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.84)
\r
40 (envelope-from <aclements@csail.mit.edu>)
\r
41 id 1XhHXP-0007bk-8D; Thu, 23 Oct 2014 08:30:43 -0400
\r
42 From: Austin Clements <aclements@csail.mit.edu>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH v3 3/9] lib: Introduce macros for bit operations
\r
45 Date: Thu, 23 Oct 2014 08:30:35 -0400
\r
46 Message-Id: <1414067441-29054-4-git-send-email-aclements@csail.mit.edu>
\r
47 X-Mailer: git-send-email 2.1.0
\r
48 In-Reply-To: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>
\r
49 References: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>
\r
50 X-Brightmail-Tracker:
\r
51 H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixCmqrPv7i0eIweffyhar5/JYXL85k9mB
\r
52 yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyni56CVrwS6+ip7dF9gaGA9ydzFyckgImEis
\r
53 uNzOBGGLSVy4t54NxBYSmM0ksWRvZRcjF5C9kVHiclcvE4Rzh0ni7tvDzBBVSxglHt8MA7HZ
\r
54 BPQlVqydxApiiwhIS+y8OxvMZhbwkJjS+grMFhZwkJjd/okRxGYRUJWYO3kK2GZeAXeJzuNr
\r
55 oa6Qk9iw+z9YDSdQ754dd6AucpfY/vwg6wRG/gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0
\r
56 LfRyM0v0UlNKNzGCwojdRXUH44RDSocYBTgYlXh4L6R6hAixJpYVV+YeYpTkYFIS5Y15ABTi
\r
57 S8pPqcxILM6ILyrNSS0+xCjBwawkwht/ASjHm5JYWZValA+TkuZgURLn3fSDL0RIID2xJDU7
\r
58 NbUgtQgmK8PBoSTBywiMFyHBotT01Iq0zJwShDQTByfIcB6g4bc+gwwvLkjMLc5Mh8ifYlSU
\r
59 EudNBkkIgCQySvPgemFx/opRHOgVYV41kBU8wBQB1/0KaDATyNUbwAaXJCKkpBoY1Zh2nWh6
\r
60 NFmGRSzRakl6ySVuzz2mq5mOruz+IGUf4uHk6vL6xYbsIJslNs8PO934JHTWxHTd60cWK3Ja
\r
61 s6/Glc7TC+v9/o7z1qzrSrfMXKd5axzkkbcta5l8TizZNejGr6hYlXv/f5/fafJ6aVy/yp26
\r
62 fNVPeTF6Mk73GJT2OB5vWxdwLfWbEktxRqKhFnNRcSIAeYE5RM4CAAA=
\r
63 Cc: Austin Clements <aclements@csail.mit.edu>
\r
64 X-BeenThere: notmuch@notmuchmail.org
\r
65 X-Mailman-Version: 2.1.13
\r
67 List-Id: "Use and development of the notmuch mail system."
\r
68 <notmuch.notmuchmail.org>
\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
72 List-Post: <mailto:notmuch@notmuchmail.org>
\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
75 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
76 X-List-Received-Date: Thu, 23 Oct 2014 12:31:01 -0000
\r
78 These macros help clarify basic bit-twiddling code and are written to
\r
79 be robust against C undefined behavior of shift operators.
\r
81 lib/message.cc | 6 +++---
\r
82 lib/notmuch-private.h | 11 +++++++++++
\r
83 2 files changed, 14 insertions(+), 3 deletions(-)
\r
85 diff --git a/lib/message.cc b/lib/message.cc
\r
86 index 38bc929..55d2ff6 100644
\r
87 --- a/lib/message.cc
\r
88 +++ b/lib/message.cc
\r
89 @@ -869,7 +869,7 @@ notmuch_bool_t
\r
90 notmuch_message_get_flag (notmuch_message_t *message,
\r
91 notmuch_message_flag_t flag)
\r
93 - return message->flags & (1 << flag);
\r
94 + return NOTMUCH_TEST_BIT (message->flags, flag);
\r
98 @@ -877,9 +877,9 @@ notmuch_message_set_flag (notmuch_message_t *message,
\r
99 notmuch_message_flag_t flag, notmuch_bool_t enable)
\r
102 - message->flags |= (1 << flag);
\r
103 + NOTMUCH_SET_BIT (&message->flags, flag);
\r
105 - message->flags &= ~(1 << flag);
\r
106 + NOTMUCH_CLEAR_BIT (&message->flags, flag);
\r
110 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
111 index 36cc12b..7250291 100644
\r
112 --- a/lib/notmuch-private.h
\r
113 +++ b/lib/notmuch-private.h
\r
114 @@ -63,6 +63,17 @@ NOTMUCH_BEGIN_DECLS
\r
115 #define STRNCMP_LITERAL(var, literal) \
\r
116 strncmp ((var), (literal), sizeof (literal) - 1)
\r
118 +/* Robust bit test/set/reset macros */
\r
119 +#define NOTMUCH_TEST_BIT(val, bit) \
\r
120 + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? 0 \
\r
121 + : !!((val) & (1ull << bit)))
\r
122 +#define NOTMUCH_SET_BIT(valp, bit) \
\r
123 + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \
\r
124 + : (*(valp) |= (1ull << bit)))
\r
125 +#define NOTMUCH_CLEAR_BIT(valp, bit) \
\r
126 + ((bit < 0 || bit >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \
\r
127 + : (*(valp) &= ~(1ull << bit)))
\r
129 #define unused(x) x __attribute__ ((unused))
\r