* [PATCH 0/2] Fix two small Python flush problems @ 2022-08-15 18:50 Tom Tromey via Gdb-patches 2022-08-15 18:50 ` [PATCH 1/2] Fix gdb.flush documentation Tom Tromey via Gdb-patches ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Tom Tromey via Gdb-patches @ 2022-08-15 18:50 UTC (permalink / raw) To: gdb-patches This short series fixes a couple of small problems with the 'flush' function in Python. First, I noticed that the documentation is missing a part of the description. Then, I noticed that the stdout/stderr 'flush' method was incorrectly implemented. Tom ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] Fix gdb.flush documentation 2022-08-15 18:50 [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches @ 2022-08-15 18:50 ` Tom Tromey via Gdb-patches 2022-08-15 19:00 ` Eli Zaretskii via Gdb-patches 2022-08-15 18:50 ` [PATCH 2/2] Fix flush for sys.stderr Tom Tromey via Gdb-patches 2022-08-30 17:49 ` [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches 2 siblings, 1 reply; 5+ messages in thread From: Tom Tromey via Gdb-patches @ 2022-08-15 18:50 UTC (permalink / raw) To: gdb-patches; +Cc: Tom Tromey The gdb.flush documentation does not mention the 'stream' argument in the function signature, only in the description. This patch fixes the oversight. --- gdb/doc/python.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 9a823409854..7aa9e853d85 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -511,7 +511,7 @@ relevant stream. @end defun @findex gdb.flush -@defun gdb.flush () +@defun gdb.flush (@r{[}, stream@r{]}) Flush the buffer of a @value{GDBN} paginated stream so that the contents are displayed immediately. @value{GDBN} will flush the contents of a stream automatically when it encounters a newline in the -- 2.34.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Fix gdb.flush documentation 2022-08-15 18:50 ` [PATCH 1/2] Fix gdb.flush documentation Tom Tromey via Gdb-patches @ 2022-08-15 19:00 ` Eli Zaretskii via Gdb-patches 0 siblings, 0 replies; 5+ messages in thread From: Eli Zaretskii via Gdb-patches @ 2022-08-15 19:00 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches > Date: Mon, 15 Aug 2022 12:50:08 -0600 > From: Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> > Cc: Tom Tromey <tromey@adacore.com> > > The gdb.flush documentation does not mention the 'stream' argument in > the function signature, only in the description. This patch fixes the > oversight. Thanks, this falls under the "obvious fix" category, I think. It's fine in any case. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] Fix flush for sys.stderr 2022-08-15 18:50 [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches 2022-08-15 18:50 ` [PATCH 1/2] Fix gdb.flush documentation Tom Tromey via Gdb-patches @ 2022-08-15 18:50 ` Tom Tromey via Gdb-patches 2022-08-30 17:49 ` [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches 2 siblings, 0 replies; 5+ messages in thread From: Tom Tromey via Gdb-patches @ 2022-08-15 18:50 UTC (permalink / raw) To: gdb-patches; +Cc: Tom Tromey GDB overwrites Python's sys.stdout and sys.stderr, but does not properly implement the 'flush' method -- it only ever will flush stdout. This patch fixes the bug. I couldn't find a straightforward way to write a test for this. --- gdb/python/lib/gdb/__init__.py | 19 +++++++------------ gdb/testsuite/gdb.python/python.exp | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index 5b10e3e2381..191915e4f3b 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -39,6 +39,9 @@ class _GdbFile(object): encoding = "UTF-8" errors = "strict" + def __init__(self, stream): + self.stream = stream + def close(self): # Do nothing. return None @@ -51,23 +54,15 @@ class _GdbFile(object): self.write(line) def flush(self): - flush() - + flush(stream=self.stream) -class _GdbOutputFile(_GdbFile): def write(self, s): - write(s, stream=STDOUT) - + write(s, stream=self.stream) -sys.stdout = _GdbOutputFile() - - -class _GdbOutputErrorFile(_GdbFile): - def write(self, s): - write(s, stream=STDERR) +sys.stdout = _GdbFile(STDOUT) -sys.stderr = _GdbOutputErrorFile() +sys.stderr = _GdbFile(STDERR) # Default prompt hook does nothing. prompt_hook = None diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index 8c0da6daa26..48ff07e91e5 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -297,8 +297,8 @@ with_test_prefix "test decode_line" { } # gdb.write -gdb_test "python print (sys.stderr)" ".*gdb._GdbOutputErrorFile (instance|object) at.*" "test stderr location" -gdb_test "python print (sys.stdout)" ".*gdb._GdbOutputFile (instance|object) at.*" "test stdout location" +gdb_test "python print (sys.stderr)" ".*gdb._GdbFile (instance|object) at.*" "test stderr location" +gdb_test "python print (sys.stdout)" ".*gdb._GdbFile (instance|object) at.*" "test stdout location" gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "test default write" gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "test stderr write" gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "test stdout write" -- 2.34.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Fix two small Python flush problems 2022-08-15 18:50 [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches 2022-08-15 18:50 ` [PATCH 1/2] Fix gdb.flush documentation Tom Tromey via Gdb-patches 2022-08-15 18:50 ` [PATCH 2/2] Fix flush for sys.stderr Tom Tromey via Gdb-patches @ 2022-08-30 17:49 ` Tom Tromey via Gdb-patches 2 siblings, 0 replies; 5+ messages in thread From: Tom Tromey via Gdb-patches @ 2022-08-30 17:49 UTC (permalink / raw) To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey >>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes: Tom> This short series fixes a couple of small problems with the 'flush' Tom> function in Python. Tom> First, I noticed that the documentation is missing a part of the Tom> description. Then, I noticed that the stdout/stderr 'flush' method Tom> was incorrectly implemented. I'm checking these in now. Tom ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-30 17:49 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-08-15 18:50 [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches 2022-08-15 18:50 ` [PATCH 1/2] Fix gdb.flush documentation Tom Tromey via Gdb-patches 2022-08-15 19:00 ` Eli Zaretskii via Gdb-patches 2022-08-15 18:50 ` [PATCH 2/2] Fix flush for sys.stderr Tom Tromey via Gdb-patches 2022-08-30 17:49 ` [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox