From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 22ABB385841A; Tue, 30 Aug 2022 17:55:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22ABB385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661882102; bh=9WbE9YT6/7Fwc2mqJXko15JbmxA351kdR5VAyLTxZqs=; h=From:To:Subject:Date:From; b=Ld/5WU+Q+alWrpddnnxDTuzsxg6bfYO2+Ahaw40JlAEhRyZqXM9LrxCCS6kQ3KICC m9PiQGOS88+oTizm4t9f4QModd3+W1o1HKq3NcxvPgYyXERz9iSdSbZ58vCdJDpZ6z 3Z4+8E6WirGM++OS+3t0q3GlNAhlJNAyPHuJYbjE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix flush for sys.stderr X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: dd083c6524f1e90dae19ed895b3f5eaf6228de68 X-Git-Newrev: 2d83dd693901cb2588517d7296f1360d902c89f7 Message-Id: <20220830175502.22ABB385841A@sourceware.org> Date: Tue, 30 Aug 2022 17:55:02 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2d83dd693901= cb2588517d7296f1360d902c89f7 commit 2d83dd693901cb2588517d7296f1360d902c89f7 Author: Tom Tromey Date: Mon Aug 15 12:45:43 2022 -0600 Fix flush for sys.stderr =20 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. Diff: --- 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 =3D "UTF-8" errors =3D "strict" =20 + def __init__(self, stream): + self.stream =3D stream + def close(self): # Do nothing. return None @@ -51,23 +54,15 @@ class _GdbFile(object): self.write(line) =20 def flush(self): - flush() - + flush(stream=3Dself.stream) =20 -class _GdbOutputFile(_GdbFile): def write(self, s): - write(s, stream=3DSTDOUT) - + write(s, stream=3Dself.stream) =20 -sys.stdout =3D _GdbOutputFile() - - -class _GdbOutputErrorFile(_GdbFile): - def write(self, s): - write(s, stream=3DSTDERR) =20 +sys.stdout =3D _GdbFile(STDOUT) =20 -sys.stderr =3D _GdbOutputErrorFile() +sys.stderr =3D _GdbFile(STDERR) =20 # Default prompt hook does nothing. prompt_hook =3D 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" { } =20 # 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|objec= t) 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=3Dgdb.STDERR)" "Err= or stream" "test stderr write" gdb_test "python gdb.write(\"Normal stream\\n\", stream=3Dgdb.STDOUT)" "No= rmal stream" "test stdout write"