From e8f5d59294b77b0ffa72f1e2da04b623d6fd1ef6 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 6 Dec 2025 18:45:16 -0600 Subject: [PATCH] Small rewrite of get_unbuffered This rewrites get_unbuffered to use iteration rather than recursion. I also noticed a typo in the documentation comment, so that's fixed as well. Approved-By: Andrew Burgess --- gdb/ui-out.c | 11 +++++++---- gdb/ui-out.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 87874e22530..00c2055f492 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -907,12 +907,15 @@ buffer_group::flush_here (ui_file *stream) ui_file * get_unbuffered (ui_file *stream) { - buffering_file *buf = dynamic_cast (stream); + while (true) + { + buffering_file *buf = dynamic_cast (stream); - if (buf == nullptr) - return stream; + if (buf == nullptr) + return stream; - return get_unbuffered (buf->stream ()); + stream = buf->stream (); + } } buffered_streams::buffered_streams (buffer_group *group, ui_out *uiout) diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 9d63b4c2940..ee5e68fa233 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -529,7 +529,7 @@ private: std::unique_ptr m_buffered_streams; }; -/* If FILE is a buffering_file, return it's underlying stream. */ +/* If FILE is a buffering_file, return its underlying stream. */ extern ui_file *get_unbuffered (ui_file *file); -- 2.47.3