From 187fdaea67b5f27f43a2c119b2a66cca7e6d7cb3 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 11 Mar 2019 16:28:11 +0000 Subject: [PATCH] PR libstdc++/89460 Fix Networking TS test failures on HP-UX Check for availability of POSIX sockatmark before using it. Rename _S_ntoh overloads that are ambiguous when passed an integral type that is neither uint16_t nor uint32_t. PR libstdc++/89460 * configure.ac: Check for sockatmark. * crossconfig.m4: Check for sockatmark. * config.h.in: Regenerate. * configure: Regenerate. * include/experimental/internet (address_v4::_S_hton): Rename overloaded functions to _S_hton_16 and _S_ntoh_16. (address_v4::_S_ntoh): Rename to _S_ntoh_16 and _S_ntoh_32. (basic_endpoint): Adjust calls to _S_hton and _S_ntoh. * include/experimental/socket (basic_socket::at_mark): Check _GLIBCXX_HAVE_SOCKATMARK. From-SVN: r269588 --- libstdc++-v3/ChangeLog | 12 ++++++ libstdc++-v3/config.h.in | 3 ++ libstdc++-v3/configure | 46 ++++++++++++++++++++++ libstdc++-v3/configure.ac | 3 ++ libstdc++-v3/crossconfig.m4 | 3 ++ libstdc++-v3/include/experimental/internet | 31 ++++++++------- libstdc++-v3/include/experimental/socket | 2 +- 7 files changed, 84 insertions(+), 16 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9c5b1bbaf7a..5c0e968d942 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,17 @@ 2019-03-11 Jonathan Wakely + PR libstdc++/89460 + * configure.ac: Check for sockatmark. + * crossconfig.m4: Check for sockatmark. + * config.h.in: Regenerate. + * configure: Regenerate. + * include/experimental/internet (address_v4::_S_hton): Rename + overloaded functions to _S_hton_16 and _S_ntoh_16. + (address_v4::_S_ntoh): Rename to _S_ntoh_16 and _S_ntoh_32. + (basic_endpoint): Adjust calls to _S_hton and _S_ntoh. + * include/experimental/socket (basic_socket::at_mark): Check + _GLIBCXX_HAVE_SOCKATMARK. + * testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc: Use const variables instead of macros. diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index 034d91b3a5f..3a6f180c06d 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -390,6 +390,9 @@ /* Defined if sleep exists. */ #undef HAVE_SLEEP +/* Define to 1 if you have the `sockatmark' function. */ +#undef HAVE_SOCKATMARK + /* Define to 1 if you have the `sqrtf' function. */ #undef HAVE_SQRTF diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 8e9f818fa3f..7d134a0034b 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -28442,6 +28442,19 @@ if test "x$ac_cv_func_timespec_get" = xyes; then : #define HAVE_TIMESPEC_GET 1 _ACEOF +fi +done + + + # For Networking TS. + for ac_func in sockatmark +do : + ac_fn_c_check_func "$LINENO" "sockatmark" "ac_cv_func_sockatmark" +if test "x$ac_cv_func_sockatmark" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKATMARK 1 +_ACEOF + fi done @@ -53638,6 +53651,17 @@ if test "x$ac_cv_func_timespec_get" = xyes; then : #define HAVE_TIMESPEC_GET 1 _ACEOF +fi +done + + for ac_func in sockatmark +do : + ac_fn_c_check_func "$LINENO" "sockatmark" "ac_cv_func_sockatmark" +if test "x$ac_cv_func_sockatmark" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKATMARK 1 +_ACEOF + fi done @@ -60268,6 +60292,17 @@ _ACEOF fi done + for ac_func in sockatmark +do : + ac_fn_c_check_func "$LINENO" "sockatmark" "ac_cv_func_sockatmark" +if test "x$ac_cv_func_sockatmark" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKATMARK 1 +_ACEOF + +fi +done + @@ -66589,6 +66624,17 @@ if test "x$ac_cv_func_timespec_get" = xyes; then : #define HAVE_TIMESPEC_GET 1 _ACEOF +fi +done + + for ac_func in sockatmark +do : + ac_fn_c_check_func "$LINENO" "sockatmark" "ac_cv_func_sockatmark" +if test "x$ac_cv_func_sockatmark" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKATMARK 1 +_ACEOF + fi done diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 39b0b90c289..dadd8827b49 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -268,6 +268,9 @@ if $GLIBCXX_IS_NATIVE; then # C11 functions for C++17 library AC_CHECK_FUNCS(timespec_get) + # For Networking TS. + AC_CHECK_FUNCS(sockatmark) + # For iconv support. AM_ICONV diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 index 4a303008053..344eec09d8e 100644 --- a/libstdc++-v3/crossconfig.m4 +++ b/libstdc++-v3/crossconfig.m4 @@ -136,6 +136,7 @@ case "${host}" in AC_CHECK_FUNCS(__cxa_thread_atexit) AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) AC_CHECK_FUNCS(timespec_get) + AC_CHECK_FUNCS(sockatmark) ;; *-fuchsia*) @@ -196,6 +197,7 @@ case "${host}" in AC_CHECK_FUNCS(__cxa_thread_atexit_impl) AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) AC_CHECK_FUNCS(timespec_get) + AC_CHECK_FUNCS(sockatmark) AM_ICONV ;; *-mingw32*) @@ -224,6 +226,7 @@ case "${host}" in fi AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) AC_CHECK_FUNCS(timespec_get) + AC_CHECK_FUNCS(sockatmark) ;; *-qnx6.1* | *-qnx6.2*) SECTION_FLAGS='-ffunction-sections -fdata-sections' diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet index 80682efed53..467bdfda3ed 100644 --- a/libstdc++-v3/include/experimental/internet +++ b/libstdc++-v3/include/experimental/internet @@ -158,7 +158,7 @@ namespace ip { } explicit constexpr - address_v4(uint_type __val) : _M_addr(_S_hton(__val)) + address_v4(uint_type __val) : _M_addr(_S_hton_32(__val)) { #if UINT_LEAST32_MAX > 0xFFFFFFFF if (__val > 0xFFFFFFFF) @@ -191,7 +191,8 @@ namespace ip }; } - constexpr uint_type to_uint() const noexcept { return _S_ntoh(_M_addr); } + constexpr uint_type + to_uint() const noexcept { return _S_ntoh_32(_M_addr); } #ifdef _GLIBCXX_HAVE_ARPA_INET_H template> @@ -224,22 +225,22 @@ namespace ip friend address_v4 make_address_v4(const char*, error_code&) noexcept; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - static constexpr uint16_t _S_hton(uint16_t __h) { return __h; } - static constexpr uint16_t _S_ntoh(uint16_t __n) { return __n; } - static constexpr uint32_t _S_hton(uint32_t __h) { return __h; } - static constexpr uint32_t _S_ntoh(uint32_t __n) { return __n; } + static constexpr uint16_t _S_hton_16(uint16_t __h) { return __h; } + static constexpr uint16_t _S_ntoh_16(uint16_t __n) { return __n; } + static constexpr uint32_t _S_hton_32(uint32_t __h) { return __h; } + static constexpr uint32_t _S_ntoh_32(uint32_t __n) { return __n; } #else static constexpr uint16_t - _S_hton(uint16_t __h) { return __builtin_bswap16(__h); } + _S_hton_16(uint16_t __h) { return __builtin_bswap16(__h); } static constexpr uint16_t - _S_ntoh(uint16_t __n) { return __builtin_bswap16(__n); } + _S_ntoh_16(uint16_t __n) { return __builtin_bswap16(__n); } static constexpr uint32_t - _S_hton(uint32_t __h) { return __builtin_bswap32(__h); } + _S_hton_32(uint32_t __h) { return __builtin_bswap32(__h); } static constexpr uint32_t - _S_ntoh(uint32_t __n) { return __builtin_bswap32(__n); } + _S_ntoh_32(uint32_t __n) { return __builtin_bswap32(__n); } #endif in_addr_t _M_addr; // network byte order @@ -1396,7 +1397,7 @@ namespace ip || __proto == protocol_type::v6()); _M_data._M_v4.sin_family = __proto.family(); - _M_data._M_v4.sin_port = address_v4::_S_hton(__port_num); + _M_data._M_v4.sin_port = address_v4::_S_hton_16(__port_num); } constexpr @@ -1407,14 +1408,14 @@ namespace ip if (__addr.is_v4()) { _M_data._M_v4.sin_family = protocol_type::v4().family(); - _M_data._M_v4.sin_port = address_v4::_S_hton(__port_num); + _M_data._M_v4.sin_port = address_v4::_S_hton_16(__port_num); _M_data._M_v4.sin_addr.s_addr = __addr._M_v4._M_addr; } else { _M_data._M_v6 = {}; _M_data._M_v6.sin6_family = protocol_type::v6().family(); - _M_data._M_v6.sin6_port = address_v4::_S_hton(__port_num); + _M_data._M_v6.sin6_port = address_v4::_S_hton_16(__port_num); __builtin_memcpy(_M_data._M_v6.sin6_addr.s6_addr, __addr._M_v6._M_bytes.data(), 16); _M_data._M_v6.sin6_scope_id = __addr._M_v6._M_scope_id; @@ -1466,11 +1467,11 @@ namespace ip constexpr port_type port() const noexcept - { return address_v4::_S_ntoh(_M_data._M_v4.sin_port); } + { return address_v4::_S_ntoh_16(_M_data._M_v4.sin_port); } void port(port_type __port_num) noexcept - { _M_data._M_v4.sin_port = address_v4::_S_hton(__port_num); } + { _M_data._M_v4.sin_port = address_v4::_S_hton_16(__port_num); } void* data() noexcept { return &_M_data; } const void* data() const noexcept { return &_M_data; } diff --git a/libstdc++-v3/include/experimental/socket b/libstdc++-v3/include/experimental/socket index a2427f93dae..e80626528ce 100644 --- a/libstdc++-v3/include/experimental/socket +++ b/libstdc++-v3/include/experimental/socket @@ -794,7 +794,7 @@ inline namespace v1 bool at_mark(error_code& __ec) const { -#ifdef _GLIBCXX_HAVE_SYS_SOCKET_H +#ifdef _GLIBCXX_HAVE_SOCKATMARK const int __result = ::sockatmark(native_handle()); if (__result == -1) { -- 2.30.2