From 2d83dd693901cb2588517d7296f1360d902c89f7 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 15 Aug 2022 12:45:43 -0600 Subject: Fix flush for sys.stderr 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 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'gdb/python/lib') diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index 5b10e3e..191915e 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 -- cgit v1.1