Add keywords to TuiWindow.write

Message ID 20231213055315.824821-1-tom@tromey.com
State New
Headers
Series Add keywords to TuiWindow.write |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom Tromey Dec. 13, 2023, 5:53 a.m. UTC
  The gdb docs promise that methods with more than two or more arguments
will accept keywords.  However, I found that TuiWindow.write didn't
allow them.  This patch adds the missing support.
---
 gdb/python/py-tui.c                    | 9 ++++++---
 gdb/testsuite/gdb.python/tui-window.py | 3 ++-
 2 files changed, 8 insertions(+), 4 deletions(-)
  

Comments

Tom Tromey Dec. 30, 2023, 7:22 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> The gdb docs promise that methods with more than two or more arguments
Tom> will accept keywords.  However, I found that TuiWindow.write didn't
Tom> allow them.  This patch adds the missing support.

I'm checking this in.

Tom
  

Patch

diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index a84e38a0563..a28137ee78f 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -476,13 +476,16 @@  gdbpy_tui_erase (PyObject *self, PyObject *args)
 
 /* Python function that writes some text to a TUI window.  */
 static PyObject *
-gdbpy_tui_write (PyObject *self, PyObject *args)
+gdbpy_tui_write (PyObject *self, PyObject *args, PyObject *kw)
 {
+  static const char *keywords[] = { "string", "full_window", nullptr };
+
   gdbpy_tui_window *win = (gdbpy_tui_window *) self;
   const char *text;
   int full_window = 0;
 
-  if (!PyArg_ParseTuple (args, "s|i", &text, &full_window))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords,
+					&text, &full_window))
     return nullptr;
 
   REQUIRE_WINDOW (win);
@@ -562,7 +565,7 @@  static PyMethodDef tui_object_methods[] =
 Return true if this TUI window is valid, false if not." },
   { "erase", gdbpy_tui_erase, METH_NOARGS,
     "Erase the TUI window." },
-  { "write", (PyCFunction) gdbpy_tui_write, METH_VARARGS,
+  { "write", (PyCFunction) gdbpy_tui_write, METH_VARARGS | METH_KEYWORDS,
     "Append a string to the TUI window." },
   { NULL } /* Sentinel.  */
 };
diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py
index dc72cc4c0f7..47c4403bc48 100644
--- a/gdb/testsuite/gdb.python/tui-window.py
+++ b/gdb/testsuite/gdb.python/tui-window.py
@@ -32,7 +32,8 @@  class TestWindow:
         self.win.erase()
         w = self.win.width
         h = self.win.height
-        self.win.write("Test: " + str(self.count) + " " + str(w) + "x" + str(h))
+        self.win.write(string="Test: " + str(self.count) + " " + str(w) + "x" + str(h),
+                       full_window=False)
         self.count = self.count + 1
 
     # Tries to delete the title attribute.  GDB will throw an error.