libstdc++: Enable std::text_encoding for darwin and FreeBSD

Message ID 20240130150216.1790473-1-jwakely@redhat.com
State Committed
Headers
Series libstdc++: Enable std::text_encoding for darwin and FreeBSD |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed

Commit Message

Jonathan Wakely Jan. 30, 2024, 3:02 p.m. UTC
  This should fix the std/text_encoding/* FAILs that Iain sees on darwin.
I assume it will make it work for FreeBSD too.
 
I won't push this until I hear it works for at least one of those.

Tested x86_64-linux.

-- >8 --

The <xlocale.h> header is needed for newlocale and locale_t on these
targets.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_CHECK_TEXT_ENCODING): Use <xlocale.h> if
	needed for newlocale.
	* configure: Regenerate.
	* src/c++26/text_encoding.cc: Use <xlocale.h>.
---
 libstdc++-v3/acinclude.m4               | 3 +++
 libstdc++-v3/configure                  | 3 +++
 libstdc++-v3/src/c++26/text_encoding.cc | 3 +++
 3 files changed, 9 insertions(+)
  

Comments

Iain Sandoe Jan. 31, 2024, 9:38 a.m. UTC | #1
Hi Jonathan,

> On 30 Jan 2024, at 15:02, Jonathan Wakely <jwakely@redhat.com> wrote:
> 
> This should fix the std/text_encoding/* FAILs that Iain sees on darwin.
> I assume it will make it work for FreeBSD too.
> 
> I won't push this until I hear it works for at least one of those.

It works on x86_64-darwin{19,21,23} and on a cross to powerpc-darwin9.
The header is present on all versions we currently support (although I did not yet
test more widely than noted above).

As discussed on IRC, Darwin is qualified to Posix 2003 (and does not, generally,
have all the optional parts), so we do not expect the symbols to be present in
locale.h (even with some _XOPEN_SOURCE= value).

thanks for taking care of this,
Iain
> 
> Tested x86_64-linux.
> 
> -- >8 --
> 
> The <xlocale.h> header is needed for newlocale and locale_t on these
> targets.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* acinclude.m4 (GLIBCXX_CHECK_TEXT_ENCODING): Use <xlocale.h> if
> 	needed for newlocale.
> 	* configure: Regenerate.
> 	* src/c++26/text_encoding.cc: Use <xlocale.h>.
> ---
> libstdc++-v3/acinclude.m4               | 3 +++
> libstdc++-v3/configure                  | 3 +++
> libstdc++-v3/src/c++26/text_encoding.cc | 3 +++
> 3 files changed, 9 insertions(+)
> 
> diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
> index f9ba7ef744b..f72bd0f45b8 100644
> --- a/libstdc++-v3/acinclude.m4
> +++ b/libstdc++-v3/acinclude.m4
> @@ -5834,6 +5834,9 @@ AC_LANG_SAVE
>   AC_MSG_CHECKING([whether nl_langinfo_l is defined in <langinfo.h>])
>   AC_TRY_COMPILE([
>   #include <locale.h>
> +  #if __has_include(<xlocale.h>)
> +  # include <xlocale.h>
> +  #endif
>   #include <langinfo.h>
>   ],[
>     locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0);
> diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
> index 65ce679f1bd..f4bc0486768 100755
> --- a/libstdc++-v3/configure
> +++ b/libstdc++-v3/configure
> @@ -54533,6 +54533,9 @@ $as_echo_n "checking whether nl_langinfo_l is defined in <langinfo.h>... " >&6;
> /* end confdefs.h.  */
> 
>   #include <locale.h>
> +  #if __has_include(<xlocale.h>)
> +  # include <xlocale.h>
> +  #endif
>   #include <langinfo.h>
> 
> int
> diff --git a/libstdc++-v3/src/c++26/text_encoding.cc b/libstdc++-v3/src/c++26/text_encoding.cc
> index 33c6c07820c..b9a50ef1a00 100644
> --- a/libstdc++-v3/src/c++26/text_encoding.cc
> +++ b/libstdc++-v3/src/c++26/text_encoding.cc
> @@ -27,6 +27,9 @@
> 
> #ifdef _GLIBCXX_USE_NL_LANGINFO_L
> #include <locale.h>
> +#if __has_include(<xlocale.h>)
> +# include <xlocale.h>
> +#endif
> #include <langinfo.h>
> 
> #if __CHAR_BIT__ == 8
> -- 
> 2.43.0
>
  
Jonathan Wakely Jan. 31, 2024, 9:55 a.m. UTC | #2
On Wed, 31 Jan 2024 at 09:38, Iain Sandoe wrote:
>
> Hi Jonathan,
>
> > On 30 Jan 2024, at 15:02, Jonathan Wakely <jwakely@redhat.com> wrote:
> >
> > This should fix the std/text_encoding/* FAILs that Iain sees on darwin.
> > I assume it will make it work for FreeBSD too.
> >
> > I won't push this until I hear it works for at least one of those.
>
> It works on x86_64-darwin{19,21,23} and on a cross to powerpc-darwin9.
> The header is present on all versions we currently support (although I did not yet
> test more widely than noted above).
>
> As discussed on IRC, Darwin is qualified to Posix 2003 (and does not, generally,
> have all the optional parts), so we do not expect the symbols to be present in
> locale.h (even with some _XOPEN_SOURCE= value).


OK, thanks for the checks. I've pushed it now.
  

Patch

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index f9ba7ef744b..f72bd0f45b8 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -5834,6 +5834,9 @@  AC_LANG_SAVE
   AC_MSG_CHECKING([whether nl_langinfo_l is defined in <langinfo.h>])
   AC_TRY_COMPILE([
   #include <locale.h>
+  #if __has_include(<xlocale.h>)
+  # include <xlocale.h>
+  #endif
   #include <langinfo.h>
   ],[
     locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0);
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 65ce679f1bd..f4bc0486768 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -54533,6 +54533,9 @@  $as_echo_n "checking whether nl_langinfo_l is defined in <langinfo.h>... " >&6;
 /* end confdefs.h.  */
 
   #include <locale.h>
+  #if __has_include(<xlocale.h>)
+  # include <xlocale.h>
+  #endif
   #include <langinfo.h>
 
 int
diff --git a/libstdc++-v3/src/c++26/text_encoding.cc b/libstdc++-v3/src/c++26/text_encoding.cc
index 33c6c07820c..b9a50ef1a00 100644
--- a/libstdc++-v3/src/c++26/text_encoding.cc
+++ b/libstdc++-v3/src/c++26/text_encoding.cc
@@ -27,6 +27,9 @@ 
 
 #ifdef _GLIBCXX_USE_NL_LANGINFO_L
 #include <locale.h>
+#if __has_include(<xlocale.h>)
+# include <xlocale.h>
+#endif
 #include <langinfo.h>
 
 #if __CHAR_BIT__ == 8