From patchwork Thu Mar 19 20:50:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 452266 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4735D1400EA for ; Fri, 20 Mar 2015 07:50:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=oagyIq71; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=K4K/IiHt2Y6z6IK8x 0r5zTWfTqN5Cn+b0jd8pUP/iWNJ5FojzpyZl+6sYyz2thEt0wt6RyOygZO08a/EZ ftyb5a9UJW5vQQXvixWIfb9PTUIMNaxsvyqIuEOOQ0QjSfq0MqWWs3kJzCxkqgqP gEQnSgeXYH2g/Q/+PzvnAyrXIs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=Rke/BgbGihx5QDeVN9XFxZZ zFTY=; b=oagyIq71dgGtlQ61EpyuY1pRml0pMLo8P7EulHj0hBdRb1bbolwaf14 O6bP9f75m6H2Zkt9X23MIJNjEZtndkmeiL9CZ4SQPTP3o9cw6tQ7sHO/IbDP6IFw gxQW69BXzIbXlUttPz5sjdoJCvmRLyBXpz8vvOCmLlxOAulsZxIE= Received: (qmail 54186 invoked by alias); 19 Mar 2015 20:50:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 54168 invoked by uid 89); 19 Mar 2015 20:50:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-we0-f172.google.com Received: from mail-we0-f172.google.com (HELO mail-we0-f172.google.com) (74.125.82.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 19 Mar 2015 20:50:30 +0000 Received: by weop45 with SMTP id p45so67145493weo.0; Thu, 19 Mar 2015 13:50:27 -0700 (PDT) X-Received: by 10.181.8.99 with SMTP id dj3mr19521678wid.83.1426798227799; Thu, 19 Mar 2015 13:50:27 -0700 (PDT) Received: from [192.168.0.22] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by mx.google.com with ESMTPSA id m4sm3473018wjb.25.2015.03.19.13.50.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 13:50:27 -0700 (PDT) Message-ID: <550B3692.2050305@gmail.com> Date: Thu, 19 Mar 2015 21:50:26 +0100 From: =?windows-1252?Q?Fran=E7ois_Dumont?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: libstdc++@gcc.gnu.org, gcc-patches Subject: Make messages_members.cc Catalog_info and Catalogs ABI agnostic References: <20150318181647.GV9755@redhat.com> In-Reply-To: <20150318181647.GV9755@redhat.com> On 18/03/2015 19:16, Jonathan Wakely wrote: > > Preparing this patch reminded me that we currently have two copies of > the Catalog_info and Catalogs code in the unnamed namespace in > config/locale/gnu/messages_members.cc, one using the old string and > one using the new. We should really alter the code to not use > std::string so that the catalogs can be shared by both versions of the > messages facets. > Hello Do you mean like the attached patch ? Or do I need to isolate get_catalogs function in a dedicated source file that won't be built twice ? Tested under Linux x86_64 but uniqueness of catalogs have not been checked. François diff --git a/libstdc++-v3/config/locale/gnu/messages_members.cc b/libstdc++-v3/config/locale/gnu/messages_members.cc index c90499e..c34d846 100644 --- a/libstdc++-v3/config/locale/gnu/messages_members.cc +++ b/libstdc++-v3/config/locale/gnu/messages_members.cc @@ -46,18 +46,21 @@ namespace typedef messages_base::catalog catalog; - struct _GLIBCXX_DEFAULT_ABI_TAG Catalog_info + struct Catalog_info { - Catalog_info(catalog __id, const string& __domain, locale __loc) - : _M_id(__id), _M_domain(__domain), _M_locale(__loc) + Catalog_info(catalog __id, const char* __domain, locale __loc) + : _M_id(__id), _M_domain(strdup(__domain)), _M_locale(__loc) { } + ~Catalog_info() + { free(_M_domain); } + catalog _M_id; - string _M_domain; + char* _M_domain; locale _M_locale; }; - class _GLIBCXX_DEFAULT_ABI_TAG Catalogs + class Catalogs { public: Catalogs() : _M_catalog_counter(0) { } @@ -70,7 +73,7 @@ namespace } catalog - _M_add(const string& __domain, locale __l) + _M_add(const char* __domain, locale __l) { __gnu_cxx::__scoped_lock lock(_M_mutex); @@ -82,6 +85,10 @@ namespace std::auto_ptr info(new Catalog_info(_M_catalog_counter++, __domain, __l)); + + if (!info->_M_domain) + return -1; + _M_infos.push_back(info.get()); return info.release()->_M_id; } @@ -133,7 +140,6 @@ namespace std::vector _M_infos; }; - _GLIBCXX_DEFAULT_ABI_TAG Catalogs& get_catalogs() { @@ -181,7 +187,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bind_textdomain_codeset(__s.c_str(), __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); - return get_catalogs()._M_add(__s, __l); + return get_catalogs()._M_add(__s.c_str(), __l); } template<> @@ -203,7 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __dfault; return get_glibc_msg(_M_c_locale_messages, _M_name_messages, - __cat_info->_M_domain.c_str(), + __cat_info->_M_domain, __dfault.c_str()); } @@ -219,7 +225,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bind_textdomain_codeset(__s.c_str(), __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); - return get_catalogs()._M_add(__s, __l); + return get_catalogs()._M_add(__s.c_str(), __l); } template<> @@ -261,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Make sure string passed to dgettext is \0 terminated. *__dfault_next = '\0'; __translation = get_glibc_msg(_M_c_locale_messages, _M_name_messages, - __cat_info->_M_domain.c_str(), __dfault); + __cat_info->_M_domain, __dfault); // If we end up getting default value back we can simply return original // default value.