From patchwork Fri Dec 15 00:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1876425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Fau6IrGt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SrqDk6x5hz1ySd for ; Fri, 15 Dec 2023 11:03:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC0403882656 for ; Fri, 15 Dec 2023 00:03:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 81BF3387103B for ; Fri, 15 Dec 2023 00:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81BF3387103B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 81BF3387103B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702598568; cv=none; b=URvLF3v69qSuLQzXRlqfiFsaW9/fdCAUxhuPpvIv+LthVCuGa9obBQ+/m9AHO/sAURvR7FQ4ewFWb84ApX4vpi9MvDOOYTpg5ULiTqHSL2pHl0KeLEYjZzavFMXsTlpsZecgGrxaKPTXDiCUdeDHwLefAqyKbUD2Q+81vWhFQm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702598568; c=relaxed/simple; bh=7pLn+HS0S6kEITmUai7n9vdV+DyGGTM9ctfBJz/OgDI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eHy3m/EYYC3U5QrNiOamXY4zcwVnDJMldlW8a/fXjhoTJNAQUNrTtGahajR94lUjIN9ZmCVAIdOECqSHFl9P84VpXMniCpdaAhjgL0E67sE9FW9oxNyKNe4m1k9uqCSegkDyqWEBQRZeeKLdmLc9IrjhK+30MHb+hSiKFdzIDcA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702598566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Xik9iwCl451DWnPVvYeAK+GPobzrA1phOjbVzGXtZVw=; b=Fau6IrGtg/hbkeCQbcEFWHCB81hDssao0P4ajFm/MwF5d71ehyoBcJCLxRMGOh6EeO3Q9C G865jPR1bpmEh6Z5npETZeevd2M0cUBRPW0oJdSJCsA3V9C0r8Vo8C30gMgB/7UP+djSHW bziAW5XmDOrfhQPQmm2vVMvHMnhn5Sk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-YFeXwWBaM_WrSiXRArwgtA-1; Thu, 14 Dec 2023 19:02:44 -0500 X-MC-Unique: YFeXwWBaM_WrSiXRArwgtA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D2E31C0BA5A; Fri, 15 Dec 2023 00:02:44 +0000 (UTC) Received: from localhost (unknown [10.42.28.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 286F72166B32; Fri, 15 Dec 2023 00:02:44 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix filebuf::native_handle() for Windows Date: Fri, 15 Dec 2023 00:02:25 +0000 Message-ID: <20231215000243.2069266-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- 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. --- libstdc++-v3/acinclude.m4 | 3 ++- libstdc++-v3/config/io/basic_file_stdio.cc | 2 +- libstdc++-v3/configure | 3 ++- .../27_io/basic_filebuf/native_handle/char/1.cc | 9 +++++---- .../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 );