From 3b0f487165a33b52bc30c0a67797522b1c604a9a Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Thu, 12 Apr 2012 23:57:39 +0300 Subject: [PATCH] [PATCH] lib: work around talloc_steal usage from C++ code --- 4e/cdff70db3ac927af54a4d2f3524b8825f916f8 | 121 ++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 4e/cdff70db3ac927af54a4d2f3524b8825f916f8 diff --git a/4e/cdff70db3ac927af54a4d2f3524b8825f916f8 b/4e/cdff70db3ac927af54a4d2f3524b8825f916f8 new file mode 100644 index 000000000..ef584e232 --- /dev/null +++ b/4e/cdff70db3ac927af54a4d2f3524b8825f916f8 @@ -0,0 +1,121 @@ +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 84511431FAF + for ; Thu, 12 Apr 2012 13:57:47 -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 EgmJRd8cC-IW for ; + Thu, 12 Apr 2012 13:57:47 -0700 (PDT) +Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com + [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AA8AB431FAE + for ; Thu, 12 Apr 2012 13:57:46 -0700 (PDT) +Received: by lahc1 with SMTP id c1so1939174lah.26 + for ; Thu, 12 Apr 2012 13:57:43 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; + bh=o/2zKP+UOcE6THnHoJHxtPJf/VI5kIe9FPDmzRHdkpQ=; + b=bNkmI+p57BRwBnvZNsr4upWafK6KPhrYzy++nSiMEiB94RbwmRzJ2nhRlFX297Mvpe + ckLRH59JNBsdLj2lpI5/8G7ytmYyO/0EoHgXaGacT7afdOC4UlsZmEvWNFPAo8m0EEYi + OfIeR8deYgQLTLS+N9+DdkshVysHQ/TRZX3jyiDSjqW9M88mqxdbDWoTYDdU4QShZZtr + hOcOre8Wc/MfhfGzd5B8+44IMUB4fTSlRRzCRa9qA6iBQXOwC5y6h/pv2KrgvPMff5Nh + c+YBz9Fti2nTjgiUd60YHdxKctplvMDRRjtYQfwKPkO17M3uQ83SuqM0/Z0BsIs6yTrR + CMBA== +Received: by 10.112.29.166 with SMTP id l6mr1699501lbh.78.1334264263574; + Thu, 12 Apr 2012 13:57:43 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi. + [80.220.80.68]) + by mx.google.com with ESMTPS id u4sm7291312lad.5.2012.04.12.13.57.41 + (version=SSLv3 cipher=OTHER); Thu, 12 Apr 2012 13:57:42 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH] lib: work around talloc_steal usage from C++ code +Date: Thu, 12 Apr 2012 23:57:39 +0300 +Message-Id: <1334264259-17632-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 1.7.5.4 +X-Gm-Message-State: + ALoCoQl5NB2XQPkT53ya621KRRQDH/VE8iYbiR1gs9nYh0/5b1DzOmnXcZqMLSozxingnK4yOeLK +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: Thu, 12 Apr 2012 20:57:47 -0000 + +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. + +The template must be outside the extern "C" block (NOTMUCH_BEGIN_DECLS +and NOTMUCH_END_DECLS), but keep it within the GCC visibility #pragma. + +No functional changes, apart from making the library build with +compilers other than recent GCC. + +Signed-off-by: Jani Nikula + +--- + +For background, see discussion starting at +id:"1333966665-10469-5-git-send-email-Vladimir.Marek@oracle.com" + +Vladimir, please test this. Thanks. +--- + lib/notmuch-private.h | 22 ++++++++++++++++++++-- + 1 files changed, 20 insertions(+), 2 deletions(-) + +diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h +index ea836f7..3886e0c 100644 +--- a/lib/notmuch-private.h ++++ b/lib/notmuch-private.h +@@ -495,8 +495,26 @@ notmuch_filenames_t * + _notmuch_filenames_create (const void *ctx, + notmuch_string_list_t *list); + +-#pragma GCC visibility pop +- + 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 ++ ++#pragma GCC visibility pop ++ + #endif +-- +1.7.5.4 + -- 2.26.2