From patchwork Fri Oct 14 14:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 2714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp216601wrs; Fri, 14 Oct 2022 07:37:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vV5bm26Imqziep6JVaUpG/iXYZI6YbhmrcJzfFHgJXYyfY6JAPNtt4xGlJXYG9AzA94d1 X-Received: by 2002:a17:907:8688:b0:78b:eaa5:8a9d with SMTP id qa8-20020a170907868800b0078beaa58a9dmr3896321ejc.509.1665758228421; Fri, 14 Oct 2022 07:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665758228; cv=none; d=google.com; s=arc-20160816; b=DneohG23taXh+W9klEna/330sryZTseiT3sTtQvwHnl4y2sfxN1kIu2cvbynVfkzLY Dzf/o1Bwo6M8z3js5+XGYWWVMEGNpRb0hxGlBDBxC1AuhBbHuat4upEbSRfYc7l4SVUg 7doltUHs4kCC33M4pkxN/gn1ItrVJrmEimPkazqiAY7XP83BrShdiVrEerT/VwX6zVON I0o/fm/mpfjtEVLgLmTvFdRLrt1S1G3YM0KS6VG2fLX+sFF8yb1MIR7DKbfl2VwT7lcf yw5rlIJc5wWJoGFH7Vjwzgi9F7PzGg/TvXPUlTcmwRpYjcpVINQgYKLUa1CPrRZgUVQq UKyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rp2wNvQHOoCwrSTLtQb72IFG82FBs5TJVTZYI811M0A=; b=hSBgOTkUuXIebWSqrRbOmeubahoFW+NFajJSCN9hP9la29ut21cF/WRlxT7LwAr/0J 1cDcSJTkiNC2iWlVQm1gpWBK0HTFBfRTzzeBC6+0d1SMolDAw8kVplnVsl1qzRETD8hM N+u/l8tvDJwB/gEn6VUzOAEDZkvuRvtsk+xKyNIVxa4ZxkNX2IXk27UkkX1FndvS1W8k wzqpTYitNxuWSWjsRYQW1cetqv5h1DRb4QmZMXC+b+D9jU0+vxyvhRuztz5WqjSkl1RO wFCPgFwjrCDFQq4Hpv05YVF3vXSDUfFk8ZsrxbBs/DkBjjO1qoyldqQv049oDKjQc9DU buQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NUrVnugj; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id wv2-20020a170907080200b0078dc3cb8b48si2740696ejb.625.2022.10.14.07.37.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 07:37:08 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=NUrVnugj; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 93B803850208 for ; Fri, 14 Oct 2022 14:36:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93B803850208 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665758217; bh=rp2wNvQHOoCwrSTLtQb72IFG82FBs5TJVTZYI811M0A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NUrVnugjZhynXz48OYkgWVxfHGNmvb2RjDQ9l/7HnSTVtTy7b7EuP/fQ9i7qdh8fd DL1tIWT9oo4w172tqJNOFEvZbU7ZGSDsyiepBJ/tBTJB/IqCbFjcKWj9Js964Jz4Ab +0wsKnTM6Zd+dWJiHxP2+DW2XmvB3i1P6OIEr7mE= 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 EC8B038582B7 for ; Fri, 14 Oct 2022 14:36:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EC8B038582B7 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) 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 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=unavailable 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746674099692916506?= X-GMAIL-MSGID: =?utf-8?q?1746674099692916506?= 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; }