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: 178987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8965851dys; Thu, 14 Dec 2023 17:15:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVxJRojhn7EcAhlyAswoSCn1WhuJfDHPRiwtLlT/Do859EoCDBHixfftVS0LpJG839SVcp X-Received: by 2002:ac8:5d8d:0:b0:425:72f3:efc2 with SMTP id d13-20020ac85d8d000000b0042572f3efc2mr14190206qtx.23.1702602902545; Thu, 14 Dec 2023 17:15:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702602902; cv=pass; d=google.com; s=arc-20160816; b=ZUg8gSQZauA9Fl4EeaZWH2OQRj0dieAqYQoBQbD9brQxsTDzxNDpE9PvtmK0zVRrIP pnw3XUAzB4hN50pSu0AQRPCvyl+GfgWH5VIoF8xpcP0pILfekC1F+PKrm0dOBsMY3qV0 3Qo3sb/EkMn6PfMLslko3mClT6+7ziMN0WzO7c96ZXgmzFU6F0KwKC36uALHipyYLWkn 6bXiP5s8aBY/xbiuvSLD9wZD5tL/dxRRu+eGhiwJmtpNuUBazvp1ASPm7a0MyN56DMvS oZHbSHtC7vY+geRYipXLDSd+xHd71nHmeFEezeR69gtQtY92sS3D8mJsHZ5f7/ym0/HS D1pA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=Xik9iwCl451DWnPVvYeAK+GPobzrA1phOjbVzGXtZVw=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=asXzHBR9+Es6GMBNNLMGkNxzePDzJGoPk960MMiUVRo+A3POELN3vJVXZL1Ls3bPMX w8JMPvoFtswZzxIiKZc+/tXTyc+Ys8fPRz+EnwW5ZUQQZ5Gusl/XvpwR7E7OklBHZfEw BD27T8gmYI4/jTBJ2GDP8Jr4PR3an5JjnGLgQ4DlsfxkKr7GU6Ec1pghHY2Qk7iYToEF DmIUrRVc461NBXwnS8mQJqpc6rkfJHR0PZrfmfVZRMgP5mtwG8dm/Vo5JIZBvElQuiGZ +meAHPzDMantBI0ZmmWnoH5poGGhFmzL9EkAjjCUcfCmjlgduGdP3Iu3JtBL6PR+eyOd XcVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fau6IrGt; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e22-20020ac845d6000000b00423d2eb0b37si15468431qto.21.2023.12.14.17.15.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 17:15:02 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fau6IrGt; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4316F3875409 for ; Fri, 15 Dec 2023 00:03:30 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785308541139172686 X-GMAIL-MSGID: 1785308541139172686 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 );