From ad8c008ebedd6855cecd508d7aba75067c5f9bf3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 12 Apr 2012 17:11:13 +2000 Subject: [PATCH] Re: [PATCH 4/4] Explicitly type void* pointers --- 03/cf9ef2e8aad5479dff57ba466956efab902442 | 127 ++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 03/cf9ef2e8aad5479dff57ba466956efab902442 diff --git a/03/cf9ef2e8aad5479dff57ba466956efab902442 b/03/cf9ef2e8aad5479dff57ba466956efab902442 new file mode 100644 index 000000000..33bc4d885 --- /dev/null +++ b/03/cf9ef2e8aad5479dff57ba466956efab902442 @@ -0,0 +1,127 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 53A9D431FAF + for ; Wed, 11 Apr 2012 14:11:17 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id rR43GqcxLqgG for ; + Wed, 11 Apr 2012 14:11:16 -0700 (PDT) +Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU + [18.9.25.15]) + by olra.theworths.org (Postfix) with ESMTP id A6D3E431FAE + for ; Wed, 11 Apr 2012 14:11:16 -0700 (PDT) +X-AuditID: 1209190f-b7f8a6d000000914-a6-4f85f37497cd +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP + id FB.12.02324.473F58F4; Wed, 11 Apr 2012 17:11:16 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q3BLBFVS012680; + Wed, 11 Apr 2012 17:11:16 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3BLBEIm021678 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Wed, 11 Apr 2012 17:11:14 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SI4or-000184-Mo; Wed, 11 Apr 2012 17:11:13 -0400 +From: Austin Clements +To: Jani Nikula , Vladimir Marek , + Notmuch Mail +Subject: Re: [PATCH 4/4] Explicitly type void* pointers +In-Reply-To: <87mx6ka8y1.fsf@nikula.org> +References: <1333966665-10469-1-git-send-email-Vladimir.Marek@oracle.com> + <1333966665-10469-5-git-send-email-Vladimir.Marek@oracle.com> + + <20120409181543.GC10554@pub.czech.sun.com> + <87mx6ka8y1.fsf@nikula.org> +User-Agent: Notmuch/0.12+107~gf2d67c3 (http://notmuchmail.org) Emacs/23.3.1 + (i486-pc-linux-gnu) +Date: Wed, 11 Apr 2012 17:11:13 -0400 +Message-ID: <87vcl6nfda.fsf@awakening.csail.mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFnrJIsWRmVeSWpSXmKPExsUixCmqrVvyudXf4NcvIYum6c4W12/OZLbo + uL2bzYHZ49b91+wez1bdYvb4+PQWSwBzFJdNSmpOZllqkb5dAldG2+yYgqM8FbMPvmJpYGzh + 6mLk5JAQMJHY+vMyC4QtJnHh3nq2LkYuDiGBfYwS9w49Z4dwNjBKfL9xmRnCOckk8ad1IRNI + i5DAEkaJzt/SIDabgIbEtv3LGUFsEYE6iZmH3rGB2MIC5hIf/09gBrE5gWomv/nMCtE7mUli + xj5VEFtUIF5iXcN7sDiLgKrE6UufwebwAp23ufckO4QtKHFy5hOwU5kFtCRu/HvJNIFRYBaS + 1CwkqQWMTKsYZVNyq3RzEzNzilOTdYuTE/PyUot0TfRyM0v0UlNKNzGCQ1SSfwfjt4NKhxgF + OBiVeHh3TWj1F2JNLCuuzD3EKMnBpCTK6/keKMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmE12V2 + i78Qb0piZVVqUT5MSpqDRUmcV03rnZ+QQHpiSWp2ampBahFMVoaDQ0mCd8knoKGCRanpqRVp + mTklCGkmDk6Q4TxAw+tBaniLCxJzizPTIfKnGBWlxHm7QBICIImM0jy4XlgKecUoDvSKMG8L + SBUPMP3Adb8CGswENPjzZJCri0sSEVJSDYzZMi8CTs3uvZzBWCX1pMU9r7tJy7L+v9nnjVyH + 2S/+3V2uuOHu28y11ytM/OSuuT64/KZSmnnxTf0KiZcHd5p/bGu4zbfCfuYGQ61Zf1s3NzNc + XDP35+bp+22SLgb+28a8q6Li41TG0C8rI/5dn/Czr9Jnx7HrIimbI3N69wp93ibx5OLT776t + SizFGYmGWsxFxYkAHgFeTfwCAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 11 Apr 2012 21:11:17 -0000 + +On Mon, 09 Apr 2012, Jani Nikula wrote: +> Vladimir Marek writes: +> I'm throwing in a third alternative below. Does it work for you? I think +> it's both prettier and uglier than the above at the same time! ;) +> +> A middle ground would be to change the callers to use +> "notmuch_talloc_steal", and just #define notmuch_talloc_steal +> talloc_steal if __GNUC__ >= 3. +> +> One could argue upstream talloc should have this, but OTOH it's a C +> library. +> +> BR, +> Jani. +> +> +> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h +> index ea836f7..83b46e8 100644 +> --- a/lib/notmuch-private.h +> +++ b/lib/notmuch-private.h +> @@ -499,4 +499,22 @@ _notmuch_filenames_create (const void *ctx, +> +> NOTMUCH_END_DECLS +> +> +#ifdef __cplusplus +> +/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in +> + * C++. In talloc_steal, an explicit cast is provided for type safety +> + * in some GCC versions. Otherwise, a cast is required. Provide a +> + * template function for this to maintain type safety, and redefine +> + * talloc_steal to use it. +> + */ +> +#if !(__GNUC__ >= 3) +> +template +> +T *notmuch_talloc_steal(const void *new_ctx, const T *ptr) +> +{ +> + return static_cast(talloc_steal(new_ctx, ptr)); +> +} +> +#undef talloc_steal +> +#define talloc_steal notmuch_talloc_steal +> +#endif +> +#endif +> + +> #endif + +This looks good to me. I was originally concerned that this depended on +talloc_steal being a macro, but I realized that's not actually the case. +Care to roll a real patch? -- 2.26.2