diff mbox

Make messages_members.cc Catalog_info and Catalogs ABI agnostic

Message ID 550B3692.2050305@gmail.com
State New
Headers show

Commit Message

François Dumont March 19, 2015, 8:50 p.m. UTC
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

Comments

Jonathan Wakely March 20, 2015, 11:38 a.m. UTC | #1
On 19/03/15 21:50 +0100, François Dumont wrote:
>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 ?

That's a partial fix, but the types and functions are still in an
anonymous namespace, so will still be duplicated.

To do it correctly they can't be in an anon namespace and the names
must be uglified.
diff mbox

Patch

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<Catalog_info> 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<Catalog_info*> _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.