--- /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 D77514041CF\r
+ for <notmuch@notmuchmail.org>; Mon, 9 Apr 2012 14:31:42 -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 p27yqgte60DQ for <notmuch@notmuchmail.org>;\r
+ Mon, 9 Apr 2012 14:31:42 -0700 (PDT)\r
+Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
+ [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D49B84041C4\r
+ for <notmuch@notmuchmail.org>; Mon, 9 Apr 2012 14:31:41 -0700 (PDT)\r
+Received: by lahc1 with SMTP id c1so3966278lah.26\r
+ for <notmuch@notmuchmail.org>; Mon, 09 Apr 2012 14:31:38 -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:date:message-id:mime-version\r
+ :content-type:x-gm-message-state;\r
+ bh=AY7koQTds8NWhz9uJK02k6P8bSg/aP55lxA8gPkTKe4=;\r
+ b=PfMHwIrWncbgpqnmsXZ9pzSFQevk2TuucYF6lBvbFxcjg4bijeQ6uf3ow9i8/3MBOD\r
+ iKhIGRQ97UqYrts56RqWAPSAzpaHTwSmlw8QthtwpeEiCkRKR0mrOGBL4nLeYjMKBG2S\r
+ q/vtLdVyPq0AHSqqXcQA72OcofHdclLonbOa1JtoyLsvi+qUO7f/k37lDsaJiHCdkbYm\r
+ TFazyXgxFdKqrN869Yiw+3blnH7eBHzKEEr4ORhuU0/ZaLu1JDGpSTprluFirfbT0i8T\r
+ f7de+w6qfdmoty/y0ddw34qUwj4xTQn64lRL5jIOJji3XSRq80NaXVb3eRfxJceGMlwC\r
+ Bujg==\r
+Received: by 10.152.125.41 with SMTP id mn9mr13092580lab.30.1334007098775;\r
+ Mon, 09 Apr 2012 14:31:38 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.\r
+ [80.220.80.68])\r
+ by mx.google.com with ESMTPS id u4sm17074007lad.5.2012.04.09.14.31.36\r
+ (version=SSLv3 cipher=OTHER); Mon, 09 Apr 2012 14:31:37 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: 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: <20120409181543.GC10554@pub.czech.sun.com>\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>User-Agent:\r
+ Notmuch/0.12+81~g839a805 (http://notmuchmail.org) Emacs/23.3.1\r
+ (i686-pc-linux-gnu)\r
+Date: Tue, 10 Apr 2012 00:31:34 +0300\r
+Message-ID: <87mx6ka8y1.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQnwprzR8WVSMLExIIU3AmRHsiK8Zh3/rUo+S+L15VPsqqP3Qjz2vaOOwAdsYVGbT5VgzRV7\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: Mon, 09 Apr 2012 21:31:43 -0000\r
+\r
+Vladimir Marek <Vladimir.Marek@Oracle.COM> writes:\r
+\r
+> Hi,\r
+>\r
+>> Hi, does notmuch not compile without this? IIRC talloc_steal is a macro\r
+>> that's supposed to provide type safety (at least with GCC), and I'd be\r
+>> hesitant about adding the casts. Please look in your talloc.h.\r
+>\r
+> It does not compile. It might be that I'm using Sun/Oracle CC instead of\r
+> gcc. The error looks like this:\r
+>\r
+> "lib/database.cc", line 1368: Error: Cannot assign void* to const char*.\r
+\r
+In general, that's not a difference in the C++ compilers. You can't\r
+assign 'void *' to 'T *' in C++.\r
+\r
+> When looking into talloc documentation, the definition seems to be:\r
+>\r
+> void* talloc_steal ( const void * new_ctx, const void * ptr )\r
+>\r
+> http://talloc.samba.org/talloc/doc/html/group__talloc.html#gaccc66139273e727183fb5bdda11ef82c\r
+>\r
+>\r
+> When looking into talloc.h, it says:\r
+>\r
+> /* try to make talloc_set_destructor() and talloc_steal() type safe,\r
+> if we have a recent gcc */\r
+\r
+It just so happens that the trick for type safety fixes the problem for\r
+recent GCC by having an explicit cast.\r
+\r
+> So, maybe the way to satisfy everyone would be:\r
+>\r
+> notmuch_message_t *tmp_message = message;\r
+> talloc_steal(notmuch, tmp_message);\r
+> return(tmp_message);\r
+>\r
+> Or alternatively,\r
+>\r
+> #if (__GNUC__ >= 3)\r
+> return talloc_steal (notmuch, message);\r
+> #else\r
+> return (notmuch_message_t*) talloc_steal (notmuch, message);\r
+> #fi\r
+>\r
+>\r
+> Of course I'm happy either way :)\r
+\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