From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 268223858C83 for ; Fri, 14 Oct 2022 14:36:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 268223858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665758164; 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=rp2wNvQHOoCwrSTLtQb72IFG82FBs5TJVTZYI811M0A=; b=P0OZ2LHOF61SLj6nczQLI2Qp0aAXsmpqU3KAv3fxJeWfKKAOCK/4G03Ce1RpzH6qbDDWLU Ouf+92J0tyAIPaRsscD85CLxhdTYu5T3Z3sqG///sJfzNymfqMu83QBwBNFbF/NboDX8gU /Ypsr4q67eDvKUZRxYt8h6Rd/WwlDrE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-IIeC7QgBMWmmw0sg8SU8Rg-1; Fri, 14 Oct 2022 10:36:03 -0400 X-MC-Unique: IIeC7QgBMWmmw0sg8SU8Rg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27DC5811E75; Fri, 14 Oct 2022 14:36:03 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id E47F9140215B; Fri, 14 Oct 2022 14:36:02 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify print_raw function for debug assertions Date: Fri, 14 Oct 2022 15:36:02 +0100 Message-Id: <20221014143602.2512815-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 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,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested powerpc64le-linux. Pushed to trunk. -- >8 -- Replace two uses of print_raw where it's clearer to just use fprintf directly. Then the only remaining use of print_raw is as the print_func argument of pretty_print. When called by pretty_print the count is either a positive integer or -1, so we can simplify print_raw itself. Remove the default argument, because it's never used. Remove the check for nbc == 0, which never happens (but would be harmless if it did). Replace the conditional expression with a single call to fprintf, using INT_MAX as the maximum length. libstdc++-v3/ChangeLog: * src/c++11/debug.cc (print_raw): Simplify. (print_word): Print indentation by calling fprintf directly. (_Error_formatter::_M_error): Print unindented string by calling fprintf directly. --- libstdc++-v3/src/c++11/debug.cc | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index abc4124c01e..f2b25fbefce 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -37,6 +37,7 @@ #include // for std::abort #include // for std::isspace. #include // for std::strstr. +#include // for INT_MAX #include // for std::min. @@ -609,14 +610,11 @@ namespace { print_word(ctx, word, Length - 1); } void - print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc = -1) + print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc) { - if (nbc != 0) - { - ctx._M_column += (nbc > 0) - ? fprintf(stderr, "%.*s", (int)nbc, str) - : fprintf(stderr, "%s", str); - } + if (nbc == -1) + nbc = INT_MAX; + ctx._M_column += fprintf(stderr, "%.*s", (int)nbc, str); } void @@ -645,12 +643,9 @@ namespace || (ctx._M_column + visual_length < ctx._M_max_length) || (visual_length >= ctx._M_max_length && ctx._M_column == 1)) { - // If this isn't the first line, indent + // If this isn't the first line, indent. if (ctx._M_column == 1 && !ctx._M_first_line) - { - const char spacing[PrintContext::_S_indent + 1] = " "; - print_raw(ctx, spacing, PrintContext::_S_indent); - } + ctx._M_column += fprintf(stderr, "%*c", PrintContext::_S_indent, ' '); int written = fprintf(stderr, "%.*s", (int)length, word); @@ -1166,7 +1161,7 @@ namespace __gnu_debug PrintContext ctx; if (_M_file) { - print_raw(ctx, _M_file); + ctx._M_column += fprintf(stderr, "%s", _M_file); print_literal(ctx, ":"); go_to_next_line = true; } -- 2.37.3