From: Jonathan Wakely <jwakely@redhat.com>
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 [thread overview]
Message-ID: <20221014143602.2512815-1-jwakely@redhat.com> (raw)
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 <cstdlib> // for std::abort
#include <cctype> // for std::isspace.
#include <cstring> // for std::strstr.
+#include <climits> // for INT_MAX
#include <algorithm> // 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
next reply other threads:[~2022-10-14 14:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-14 14:36 Jonathan Wakely [this message]
2022-10-15 10:51 ` libstdc++: Address '-Wunused-function' for 'print_raw' (was: [committed] libstdc++: Simplify print_raw function for debug assertions) Thomas Schwinge
2022-10-15 13:30 ` Jonathan Wakely
2022-10-15 20:26 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221014143602.2512815-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).