Re: [PATCH 4/4] Explicitly type void* pointers
authorJani Nikula <jani@nikula.org>
Thu, 12 Apr 2012 08:02:12 +0000 (08:02 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:16 +0000 (09:46 -0800)
86/72da84caea499cb365bd7f23402b4bb01a63d0 [new file with mode: 0644]

diff --git a/86/72da84caea499cb365bd7f23402b4bb01a63d0 b/86/72da84caea499cb365bd7f23402b4bb01a63d0
new file mode 100644 (file)
index 0000000..3ffbd70
--- /dev/null
@@ -0,0 +1,134 @@
+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 7F44A431FAF\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 01:02:29 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 4GpkA7WFyGZ9 for <notmuch@notmuchmail.org>;\r
+       Thu, 12 Apr 2012 01:02:21 -0700 (PDT)\r
+Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com\r
+       [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 778A8431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 01:02:21 -0700 (PDT)\r
+Received: by qcsk26 with SMTP id k26so1328663qcs.26\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 01:02:20 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type:x-gm-message-state;\r
+       bh=DRB71CSZOX2WgFOFU4c+gC7k1b/2jSlhJMRtQ4ltaGE=;\r
+       b=YqFJpcR9XrrGL58AO1LsONVbna6kvdjr8IJTrosleT1SONaK8xiCHrxNCDXqXeJwZM\r
+       yHOyzJks+h2IMVKyVAr/EkOENl5YWXgnTJProH0HyMFLqDk0pQiFKjLBq16570bLf+qO\r
+       8PcGbKv+p8MiQtEgCU5Cpm7r5opfJAvACqPwLJL72gMrXHemI/ge/ygznvDXMjJudD6d\r
+       xXWesY8e6CZETLBGN1qZ+tOsbyYrAsbqtSAF528P8vyknQvcY8hmG9Go402C+H+Qykbq\r
+       tIytdsVucnU3K5LJl5ZIQIgYehkhRv2WwHY15byxIXvMy8nb+zAuReI7eaOPIPA1hoVA\r
+       UacQ==\r
+Received: by 10.224.221.75 with SMTP id ib11mr2610027qab.21.1334217739927;\r
+       Thu, 12 Apr 2012 01:02:19 -0700 (PDT)\r
+Received: from localhost ([92.243.24.172])\r
+       by mx.google.com with ESMTPS id cs10sm10466237qab.8.2012.04.12.01.02.17\r
+       (version=SSLv3 cipher=OTHER); Thu, 12 Apr 2012 01:02:18 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Austin Clements <amdragon@MIT.EDU>,\r
+       Vladimir Marek <Vladimir.Marek@Oracle.COM>,\r
+       Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: Re: [PATCH 4/4] Explicitly type void* pointers\r
+In-Reply-To: <87vcl6nfda.fsf@awakening.csail.mit.edu>\r
+References: <1333966665-10469-1-git-send-email-Vladimir.Marek@oracle.com>\r
+       <1333966665-10469-5-git-send-email-Vladimir.Marek@oracle.com>\r
+       <CAB+hUn_QyMAfC1-Dr23T63ObX=cwuBOzcyCi=61w0MtGRMyt2w@mail.gmail.com>\r
+       <20120409181543.GC10554@pub.czech.sun.com>\r
+       <87mx6ka8y1.fsf@nikula.org>\r
+       <87vcl6nfda.fsf@awakening.csail.mit.edu>\r
+User-Agent: Notmuch/0.11.1+222~ga47a98c (http://notmuchmail.org) Emacs/23.1.1\r
+       (i686-pc-linux-gnu)\r
+Date: Thu, 12 Apr 2012 08:02:12 +0000\r
+Message-ID: <87aa2hxtrv.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQl3XkMe5Epw3Hd9TfIVATcin2Ntgpcu1FQ4n7AcqDB0tcYSs+bEG23kBpsm3ON0d/DCWvvn\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: Thu, 12 Apr 2012 08:02:29 -0000\r
+\r
+On Wed, 11 Apr 2012 17:11:13 -0400, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> On Mon, 09 Apr 2012, Jani Nikula <jani@nikula.org> wrote:\r
+> > Vladimir Marek <Vladimir.Marek@Oracle.COM> writes:\r
+> > I'm throwing in a third alternative below. Does it work for you? I think\r
+> > it's both prettier and uglier than the above at the same time! ;)\r
+> >\r
+> > A middle ground would be to change the callers to use\r
+> > "notmuch_talloc_steal", and just #define notmuch_talloc_steal\r
+> > talloc_steal if __GNUC__ >= 3.\r
+> >\r
+> > One could argue upstream talloc should have this, but OTOH it's a C\r
+> > library.\r
+> >\r
+> > BR,\r
+> > Jani.\r
+> >\r
+> >\r
+> > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> > index ea836f7..83b46e8 100644\r
+> > --- a/lib/notmuch-private.h\r
+> > +++ b/lib/notmuch-private.h\r
+> > @@ -499,4 +499,22 @@ _notmuch_filenames_create (const void *ctx,\r
+> >  \r
+> >  NOTMUCH_END_DECLS\r
+> >  \r
+> > +#ifdef __cplusplus\r
+> > +/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in\r
+> > + * C++. In talloc_steal, an explicit cast is provided for type safety\r
+> > + * in some GCC versions. Otherwise, a cast is required. Provide a\r
+> > + * template function for this to maintain type safety, and redefine\r
+> > + * talloc_steal to use it.\r
+> > + */\r
+> > +#if !(__GNUC__ >= 3)\r
+> > +template <class T>\r
+> > +T *notmuch_talloc_steal(const void *new_ctx, const T *ptr)\r
+> > +{\r
+> > +    return static_cast<T*>(talloc_steal(new_ctx, ptr));\r
+> > +}\r
+> > +#undef talloc_steal\r
+> > +#define talloc_steal notmuch_talloc_steal\r
+> > +#endif\r
+> > +#endif\r
+> > +\r
+> >  #endif\r
+> \r
+> This looks good to me.  I was originally concerned that this depended on\r
+> talloc_steal being a macro, but I realized that's not actually the case.\r
+> Care to roll a real patch?\r
+\r
+Sure.\r
+\r
+One question: the template must be outside NOTMUCH_{BEGIN,END}_DECLS\r
+(which are just macros for extern "C" block) but should it be within the\r
+#pragma GCC visibility push(hidden) and pop directives? I'm not familiar\r
+with that.\r
+\r
+Thanks for the review.\r
+\r
+\r
+BR,\r
+Jani.\r