[PATCH] lib: work around talloc_steal usage from C++ code
authorJani Nikula <jani@nikula.org>
Thu, 12 Apr 2012 20:57:39 +0000 (23:57 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:19 +0000 (09:46 -0800)
4e/cdff70db3ac927af54a4d2f3524b8825f916f8 [new file with mode: 0644]

diff --git a/4e/cdff70db3ac927af54a4d2f3524b8825f916f8 b/4e/cdff70db3ac927af54a4d2f3524b8825f916f8
new file mode 100644 (file)
index 0000000..ef584e2
--- /dev/null
@@ -0,0 +1,121 @@
+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 84511431FAF\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 13:57:47 -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 EgmJRd8cC-IW for <notmuch@notmuchmail.org>;\r
+       Thu, 12 Apr 2012 13:57:47 -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 AA8AB431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 13:57:46 -0700 (PDT)\r
+Received: by lahc1 with SMTP id c1so1939174lah.26\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Apr 2012 13:57:43 -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:cc:subject:date:message-id:x-mailer:x-gm-message-state;\r
+       bh=o/2zKP+UOcE6THnHoJHxtPJf/VI5kIe9FPDmzRHdkpQ=;\r
+       b=bNkmI+p57BRwBnvZNsr4upWafK6KPhrYzy++nSiMEiB94RbwmRzJ2nhRlFX297Mvpe\r
+       ckLRH59JNBsdLj2lpI5/8G7ytmYyO/0EoHgXaGacT7afdOC4UlsZmEvWNFPAo8m0EEYi\r
+       OfIeR8deYgQLTLS+N9+DdkshVysHQ/TRZX3jyiDSjqW9M88mqxdbDWoTYDdU4QShZZtr\r
+       hOcOre8Wc/MfhfGzd5B8+44IMUB4fTSlRRzCRa9qA6iBQXOwC5y6h/pv2KrgvPMff5Nh\r
+       c+YBz9Fti2nTjgiUd60YHdxKctplvMDRRjtYQfwKPkO17M3uQ83SuqM0/Z0BsIs6yTrR\r
+       CMBA==\r
+Received: by 10.112.29.166 with SMTP id l6mr1699501lbh.78.1334264263574;\r
+       Thu, 12 Apr 2012 13:57:43 -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 u4sm7291312lad.5.2012.04.12.13.57.41\r
+       (version=SSLv3 cipher=OTHER); Thu, 12 Apr 2012 13:57:42 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] lib: work around talloc_steal usage from C++ code\r
+Date: Thu, 12 Apr 2012 23:57:39 +0300\r
+Message-Id: <1334264259-17632-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+X-Gm-Message-State:\r
+ ALoCoQl5NB2XQPkT53ya621KRRQDH/VE8iYbiR1gs9nYh0/5b1DzOmnXcZqMLSozxingnK4yOeLK\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 20:57:47 -0000\r
+\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 in\r
+some GCC versions. Otherwise, a cast is required. Provide a template\r
+function for this to maintain type safety, and redefine talloc_steal\r
+to use it.\r
+\r
+The template must be outside the extern "C" block (NOTMUCH_BEGIN_DECLS\r
+and NOTMUCH_END_DECLS), but keep it within the GCC visibility #pragma.\r
+\r
+No functional changes, apart from making the library build with\r
+compilers other than recent GCC.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+\r
+---\r
+\r
+For background, see discussion starting at\r
+id:"1333966665-10469-5-git-send-email-Vladimir.Marek@oracle.com"\r
+\r
+Vladimir, please test this. Thanks.\r
+---\r
+ lib/notmuch-private.h |   22 ++++++++++++++++++++--\r
+ 1 files changed, 20 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index ea836f7..3886e0c 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -495,8 +495,26 @@ notmuch_filenames_t *\r
+ _notmuch_filenames_create (const void *ctx,\r
+                          notmuch_string_list_t *list);\r
\r
+-#pragma GCC visibility pop\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> T *\r
++_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
++#pragma GCC visibility pop\r
++\r
+ #endif\r
+-- \r
+1.7.5.4\r
+\r