Re: [PATCH 4/4] Explicitly type void* pointers
[notmuch-archives.git] / e9 / 5d98dd2b915f39bcb5253ce3f40761942ace59
1 Return-Path: <amdragon@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 0D1C3431FAF\r
6         for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 10:57:34 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[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 NNtKva1dsRw4 for <notmuch@notmuchmail.org>;\r
16         Thu, 12 Apr 2012 10:57:33 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 4FE23431FAE\r
20         for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 10:57:33 -0700 (PDT)\r
21 X-AuditID: 1209190f-b7f8a6d000000914-b8-4f87178ca6c5\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 38.BF.02324.C87178F4; Thu, 12 Apr 2012 13:57:32 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q3CHvVtR014123; \r
27         Thu, 12 Apr 2012 13:57:32 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3CHvUJm010169\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 12 Apr 2012 13:57:31 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1SIOGv-0004T4-V9; Thu, 12 Apr 2012 13:57:30 -0400\r
37 Date: Thu, 12 Apr 2012 13:57:29 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Jani Nikula <jani@nikula.org>\r
40 Subject: Re: [PATCH 4/4] Explicitly type void* pointers\r
41 Message-ID: <20120412175729.GH13549@mit.edu>\r
42 References: <1333966665-10469-1-git-send-email-Vladimir.Marek@oracle.com>\r
43         <1333966665-10469-5-git-send-email-Vladimir.Marek@oracle.com>\r
44         <CAB+hUn_QyMAfC1-Dr23T63ObX=cwuBOzcyCi=61w0MtGRMyt2w@mail.gmail.com>\r
45         <20120409181543.GC10554@pub.czech.sun.com>\r
46         <87mx6ka8y1.fsf@nikula.org>\r
47         <87vcl6nfda.fsf@awakening.csail.mit.edu>\r
48         <87aa2hxtrv.fsf@nikula.org>\r
49 MIME-Version: 1.0\r
50 Content-Type: text/plain; charset=us-ascii\r
51 Content-Disposition: inline\r
52 In-Reply-To: <87aa2hxtrv.fsf@nikula.org>\r
53 User-Agent: Mutt/1.5.21 (2010-09-15)\r
54 X-Brightmail-Tracker:\r
55  H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42IRYrdT1+0Rb/c3OL3BwqJpurPF9ZszmS06\r
56         bu9mc2D2uHX/NbvHs1W3mD0+Pr3FEsAcxWWTkpqTWZZapG+XwJWxpvMZU8Fv4YqZezvZGhh3\r
57         8XcxcnBICJhI3Pir0MXICWSKSVy4t56ti5GLQ0hgH6PE9tsbmSGcDYwSW+ZeZ4dwTjJJ3P90\r
58         F6psCaPE739dbCD9LAKqEm0Hn7KD2GwCGhLb9i9nBLFFBBQlNp/cD2YzC8RLPLr8hRXEFhYw\r
59         l/j4fwIziM0roCPxbM8yqHVPmCTeNPazQyQEJU7OfMIC0awlcePfSyaQu5kFpCWW/+MACXMC\r
60         7WrY/4YJxBYVUJGYcnIb2wRGoVlIumch6Z6F0L2AkXkVo2xKbpVubmJmTnFqsm5xcmJeXmqR\r
61         rolebmaJXmpK6SZGUKhzSvLvYPx2UOkQowAHoxIP74tnbf5CrIllxZW5hxglOZiURHk/C7X7\r
62         C/El5adUZiQWZ8QXleakFh9ilOBgVhLh/fMYqJw3JbGyKrUoHyYlzcGiJM6rpvXOT0ggPbEk\r
63         NTs1tSC1CCYrw8GhJMH7HWSoYFFqempFWmZOCUKaiYMTZDgP0PDVIDW8xQWJucWZ6RD5U4yK\r
64         UuK8/MJACQGQREZpHlwvLBW9YhQHekWY9z1IOw8wjcF1vwIazAQ0mE8B5OrikkSElFQDo+hJ\r
65         lomBsqpXDGvmhEycfn7zrxBVe7+Eu0YTludN05/NPPnihmAJl7JbR8MnTj5ZuXJ1ZZ2i9cR9\r
66         997UT3mWmCP1886TWf8XdIvNY5vjvXGl6+VvqWVJcdxa+ddX5X307lr37PraqU+uTL38hUVT\r
67         6KHNfkb/aTMD8mYWVaQU9dY2qCbmTA0IXq/EUpyRaKjFXFScCAABk71WIAMAAA==\r
68 Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
69 X-BeenThere: notmuch@notmuchmail.org\r
70 X-Mailman-Version: 2.1.13\r
71 Precedence: list\r
72 List-Id: "Use and development of the notmuch mail system."\r
73         <notmuch.notmuchmail.org>\r
74 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
76 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
77 List-Post: <mailto:notmuch@notmuchmail.org>\r
78 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
79 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
80         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
81 X-List-Received-Date: Thu, 12 Apr 2012 17:57:34 -0000\r
82 \r
83 Quoth Jani Nikula on Apr 12 at  8:02 am:\r
84 > On Wed, 11 Apr 2012 17:11:13 -0400, Austin Clements <amdragon@MIT.EDU> wrote:\r
85 > > On Mon, 09 Apr 2012, Jani Nikula <jani@nikula.org> wrote:\r
86 > > > Vladimir Marek <Vladimir.Marek@Oracle.COM> writes:\r
87 > > > I'm throwing in a third alternative below. Does it work for you? I think\r
88 > > > it's both prettier and uglier than the above at the same time! ;)\r
89 > > >\r
90 > > > A middle ground would be to change the callers to use\r
91 > > > "notmuch_talloc_steal", and just #define notmuch_talloc_steal\r
92 > > > talloc_steal if __GNUC__ >= 3.\r
93 > > >\r
94 > > > One could argue upstream talloc should have this, but OTOH it's a C\r
95 > > > library.\r
96 > > >\r
97 > > > BR,\r
98 > > > Jani.\r
99 > > >\r
100 > > >\r
101 > > > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
102 > > > index ea836f7..83b46e8 100644\r
103 > > > --- a/lib/notmuch-private.h\r
104 > > > +++ b/lib/notmuch-private.h\r
105 > > > @@ -499,4 +499,22 @@ _notmuch_filenames_create (const void *ctx,\r
106 > > >  \r
107 > > >  NOTMUCH_END_DECLS\r
108 > > >  \r
109 > > > +#ifdef __cplusplus\r
110 > > > +/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in\r
111 > > > + * C++. In talloc_steal, an explicit cast is provided for type safety\r
112 > > > + * in some GCC versions. Otherwise, a cast is required. Provide a\r
113 > > > + * template function for this to maintain type safety, and redefine\r
114 > > > + * talloc_steal to use it.\r
115 > > > + */\r
116 > > > +#if !(__GNUC__ >= 3)\r
117 > > > +template <class T>\r
118 > > > +T *notmuch_talloc_steal(const void *new_ctx, const T *ptr)\r
119 > > > +{\r
120 > > > +    return static_cast<T*>(talloc_steal(new_ctx, ptr));\r
121 > > > +}\r
122 > > > +#undef talloc_steal\r
123 > > > +#define talloc_steal notmuch_talloc_steal\r
124 > > > +#endif\r
125 > > > +#endif\r
126 > > > +\r
127 > > >  #endif\r
128 > > \r
129 > > This looks good to me.  I was originally concerned that this depended on\r
130 > > talloc_steal being a macro, but I realized that's not actually the case.\r
131 > > Care to roll a real patch?\r
132\r
133 > Sure.\r
134\r
135 > One question: the template must be outside NOTMUCH_{BEGIN,END}_DECLS\r
136 > (which are just macros for extern "C" block) but should it be within the\r
137 > #pragma GCC visibility push(hidden) and pop directives? I'm not familiar\r
138 > with that.\r
139 \r
140 Hmm.  I'm not sure, but it can't hurt to have it inside the visibility\r
141 directives.  My guess would be that it will affect the visibility of\r
142 the symbols produced when the template is instantiated, which we don't\r
143 want to be visible outside the library.  (As long as that doesn't mess\r
144 up the linker's handling of weak symbols.)\r
145 \r
146 > Thanks for the review.\r
147\r
148\r
149 > BR,\r
150 > Jani.\r