From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id E3779384DEE5; Fri, 15 Dec 2023 00:02:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3779384DEE5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702598521; bh=6Y2r78f4y2CdW61g/e4hw2tdIMRbEb5d1gi1+m/kB8U=; h=From:To:Subject:Date:From; b=g58vKjx6IRhV86iEFn1USNEcn8RSPr2fdzZTe62heDH9Sxy+gRXg5EudVr0fjsVG8 doB70B1KEdvGljtOsIVmpcnWme51b3ygh6WC9oAMwHh2BTmn/93i3zmonBcUxTQqhP HCDX0ZRWuQ47mACCLCyXMXSXeb/Wgtdy3zI9w0Oo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-6568] libstdc++: Fix filebuf::native_handle() for Windows X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 3fa0f9404b1bcd5a47629d4e121390603039f951 X-Git-Newrev: 29ad35a1db645f6027acc4f2a9b15363f402ca97 Message-Id: <20231215000201.E3779384DEE5@sourceware.org> Date: Fri, 15 Dec 2023 00:02:01 +0000 (GMT) List-Id: https://gcc.gnu.org/g:29ad35a1db645f6027acc4f2a9b15363f402ca97 commit r14-6568-g29ad35a1db645f6027acc4f2a9b15363f402ca97 Author: Jonathan Wakely Date: Thu Dec 14 23:22:28 2023 +0000 libstdc++: Fix filebuf::native_handle() for Windows libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES): Add missing header to configure test. Check correct variable. * config/io/basic_file_stdio.cc (__basic_file::native_handle): Fix typo. * configure: Regenerate. * testsuite/27_io/basic_filebuf/native_handle/char/1.cc: Do not call CloseHandle on the native handle. * testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc: Likewise. Diff: --- libstdc++-v3/acinclude.m4 | 3 ++- libstdc++-v3/config/io/basic_file_stdio.cc | 2 +- libstdc++-v3/configure | 3 ++- .../testsuite/27_io/basic_filebuf/native_handle/char/1.cc | 9 +++++---- .../testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc | 9 +++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 77569d5bb59..e7cbf0fcf96 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -5803,6 +5803,7 @@ AC_LANG_SAVE AC_TRY_COMPILE([ #if defined(_WIN32) && !defined(__CYGWIN__) # include + # include # include #endif ],[ @@ -5811,7 +5812,7 @@ AC_LANG_SAVE intptr_t crt_handle = _get_osfhandle(fd); void* win32_handle = reinterpret_cast(crt_handle); ], [ac_get_osfhandle=yes], [ac_get_osfhandle=no]) - if test "$ac_objext" = yes; then + if test "$ac_get_osfhandle" = yes; then AC_DEFINE_UNQUOTED(_GLIBCXX_USE__GET_OSFHANDLE, 1, [Define if _get_osfhandle should be used for filebuf::native_handle().]) fi diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc index a33b53b3b27..f85b6e9be08 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.cc +++ b/libstdc++-v3/config/io/basic_file_stdio.cc @@ -472,7 +472,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _M_cfile; #elif _GLIBCXX_USE__GET_OSFHANDLE const intptr_t handle = _M_cfile ? _get_osfhandle(fileno(_M_cfile)) : -1; - return reinterpret_cast(handle); + return reinterpret_cast(handle); #else return fileno(_M_cfile); #endif diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 5bed1fb8110..bef2b840a59 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -54476,6 +54476,7 @@ $as_echo_n "checking whether _get_osfhandle is defined in ... " >&6; } #if defined(_WIN32) && !defined(__CYGWIN__) # include + # include # include #endif @@ -54498,7 +54499,7 @@ else ac_get_osfhandle=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - if test "$ac_objext" = yes; then + if test "$ac_get_osfhandle" = yes; then cat >>confdefs.h <<_ACEOF #define _GLIBCXX_USE__GET_OSFHANDLE 1 diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc index 0551f260ade..3ab297ed6eb 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/char/1.cc @@ -17,8 +17,9 @@ using type = std::basic_filebuf::native_handle_type; #if __has_include() # include // close(int) #endif -#if __has_include() -# include // CloseHandle(HANDLE) +#if __has_include() +# include // _open_osfhandle +# include // _O_RDONLY, _O_TEXT #endif #include @@ -38,8 +39,8 @@ test01() ::close(handle); // POSIX #endif #if __has_include() - else if constexpr (std::is_same_v) - ::CloseHandle(handle); // Windows + else if constexpr (std::is_same_v) // Windows + ::_close(::_open_osfhandle((intptr_t)handle, _O_RDONLY|_O_TEXT)); #endif else VERIFY( false ); diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc index 7ee5e4e8f53..5917c3d29c6 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc @@ -10,8 +10,9 @@ using type = std::basic_filebuf::native_handle_type; #if __has_include() # include // close(int) #endif -#if __has_include() -# include // CloseHandle(HANDLE) +#if __has_include() +# include // _open_osfhandle +# include // _O_RDONLY, _O_TEXT #endif #include @@ -31,8 +32,8 @@ test01() ::close(handle); // POSIX #endif #if __has_include() - else if constexpr (std::is_same_v) - ::CloseHandle(handle); // Windows + else if constexpr (std::is_same_v) // Windows + ::_close(::_open_osfhandle((intptr_t)handle, _O_RDONLY|_O_TEXT)); #endif else VERIFY( false );