From patchwork Fri Dec 15 13:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1876629 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=VWxZzC9E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Ss8zk0ZQCz1ySd for ; Sat, 16 Dec 2023 00:23:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30465388267F for ; Fri, 15 Dec 2023 13:23:10 +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 95D603864878 for ; Fri, 15 Dec 2023 13:22:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95D603864878 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 95D603864878 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=1702646579; cv=none; b=B0GToYoNaPCapxPTg72fNBd7lhCJzQTDLQGCYcZzQ9r8eNehtRIf+GASKl98bOboiFHxLvuRmNYMZbgudX3lDokVSEVowUiwEraEVWt3cDmTvyyGGv/QZpS5D3TSIGZC9dY86SiTmPSzVZx0PM1ZT9tRlduPMT0vH8C0KwO2pH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702646579; c=relaxed/simple; bh=fajBU01KkrreJIUoQG7x0c1nIpxT2t4LOzN4v2fc0E4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Wk56cJIPpdkYdraDvehsugGeQ/hxhzd4SbAAKJZFIrjXh+IllTCcUT7P59eCUt55XLTv6KIHyQwdCBZBLdez/19xnISWIpJGrrRGErhwzc4KUl8E8qq6N0Fj2kAcQQp/fGXsG2BNUld0zyoXjItjid792/0sFL1cW3ul1/wuSAw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702646578; 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=tnJZ4LmuZmOPOKRDMqXbWvWk3+qY54UpjviqVrLAZJM=; b=VWxZzC9ElC8ruC2+dqlKWH/L8GvgKnNofmx5yKBC4J8xCgvnaEpcbFgRYT0Zu6MFQZzsOm SsXYI1tQ/18dEI61QIDwosq1cm/pw8I0gU97dEHKG7IJ2MbfPWAqPS9YtyHFjSyBr+/QLl GslL9ZChkfxD6xuuIfrTzGafjiEzKyk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-53-7QW1Ewb0OXG5lnaNeTBdzw-1; Fri, 15 Dec 2023 08:22:55 -0500 X-MC-Unique: 7QW1Ewb0OXG5lnaNeTBdzw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 D2918859B88; Fri, 15 Dec 2023 13:22:54 +0000 (UTC) Received: from localhost (unknown [10.42.28.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D3602026D66; Fri, 15 Dec 2023 13:22:54 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::print test case for Windows Date: Fri, 15 Dec 2023 13:22:45 +0000 Message-ID: <20231215132254.2139490-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PP_MIME_FAKE_ASCII_TEXT, 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 and x86_64-w64-mingw. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * src/c++23/print.cc (__write_to_terminal) [_WIN32]: If handle does not refer to the console then just write to it using normal file I/O. * testsuite/27_io/print/2.cc (as_printed_to_terminal): Print error message on failure. (test_utf16_transcoding): Adjust for as_printed_to_terminal modifying its argument. --- libstdc++-v3/src/c++23/print.cc | 13 ++++++++++++- libstdc++-v3/testsuite/27_io/print/2.cc | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc index 2fe7a2e3565..d72ab856017 100644 --- a/libstdc++-v3/src/c++23/print.cc +++ b/libstdc++-v3/src/c++23/print.cc @@ -35,7 +35,8 @@ #ifdef _WIN32 # include // _fileno -# include // _get_osfhandle +# include // _get_osfhandle, _open_osfhandle, _write +# include // _O_APPEND # include // GetLastError, WriteConsoleW #elifdef _GLIBCXX_HAVE_UNISTD_H # include // fileno @@ -324,6 +325,16 @@ namespace if (!to_valid_utf16(str, wstr)) ec = std::make_error_code(errc::illegal_byte_sequence); + // This allows us to test this function with a normal file, + // see testsuite/27_io/print/2.cc + if (!check_for_console(term)) + { + int fd = _open_osfhandle((intptr_t)term, _O_APPEND); + if (_write(fd, wstr.data(), wstr.size() * 2) == -1) + ec = {errno, generic_category()}; + return ec; + } + unsigned long nchars = 0; WriteConsoleW(term, wstr.data(), wstr.size(), &nchars, nullptr); if (nchars != wstr.size()) diff --git a/libstdc++-v3/testsuite/27_io/print/2.cc b/libstdc++-v3/testsuite/27_io/print/2.cc index e101201f109..8aa7888e7bd 100644 --- a/libstdc++-v3/testsuite/27_io/print/2.cc +++ b/libstdc++-v3/testsuite/27_io/print/2.cc @@ -39,7 +39,11 @@ as_printed_to_terminal(std::string& s) #else const auto ec = std::__write_to_terminal(strm, s); #endif - VERIFY( !ec || ec == std::make_error_code(std::errc::illegal_byte_sequence) ); + if (ec && ec != std::make_error_code(std::errc::illegal_byte_sequence)) + { + std::println("Failed to : {}", ec.message()); + VERIFY(!ec); + } std::fclose(strm); std::ifstream in(f.path); s.assign(std::istreambuf_iterator(in), {}); @@ -114,6 +118,7 @@ test_utf16_transcoding() VERIFY( as_printed_to_terminal(s) ); VERIFY( utf16_from_bytes(s) == s2 ); + s = (const char*)u8"£🇬🇧 €🇪🇺"; s += " \xa3 10.99 \xee\xdd"; VERIFY( ! as_printed_to_terminal(s) ); std::u16string repl = u"\uFFFD";