Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Python safety initial work
@ 2026-05-21 23:27 Tom Tromey
  2026-05-21 23:27 ` [PATCH v3 1/4] Add gdbpy_borrowed_ref Tom Tromey
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Tom Tromey @ 2026-05-21 23:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I rewrote my earlier Python safety series to use methods a while back.
And while I like the result, I got bogged down converting things, so I
thought I'd send some initial work, with the idea that if this looks
good, other code can be transformed in pieces.

Since this is extracted from a larger series, there is some code in
here that isn't currently used in-tree.  This is mainly true for the
gdb functions that wrap Python APIs, see patch 2.

Patch 4 shows what the end effect is, but the patch is somewhat hard
to read IMO.  So for instance now the 'title' getter for a TUI window
is just an ordinary method:

    const std::string &
    gdbpy_tui_window::title ()
    {
      require_valid ();
      return window->title ();
    }

Since it wants to only operate on a valid window, require_valid will
throw if that isn't the case.

Note there's no explicit error checking, no casts, no messing with
reference counts, and the return type is just a string.  All these
boilerplate details are handled by a template wrapper function.

Signed-off-by: Tom Tromey <tom@tromey.com>
---
Changes in v3:
- Updated per review
- Changed gdbpy_opt_borrowed_ref and gdbpy_borrowed_ref to templates
- Link to v2: https://inbox.sourceware.org/gdb-patches/20260515-python-safety-initial-v2-0-6129cadf258a@tromey.com

Changes in v2:
- Avoids Py_RETURN_* macros
- Link to v1: https://inbox.sourceware.org/gdb-patches/20260515-python-safety-initial-v1-0-8f155338df57@tromey.com

---
Tom Tromey (4):
      Add gdbpy_borrowed_ref
      Add wrappers for some Python APIs
      Add wrappers for Python implementation functions and methods
      Convert py-tui.c to the "python safety" approach

 gdb/python/py-ref.h          |  86 +++++++++++
 gdb/python/py-safety.h       | 346 +++++++++++++++++++++++++++++++++++++++++
 gdb/python/py-tui.c          | 209 +++++++++++--------------
 gdb/python/py-wrappers.h     | 361 +++++++++++++++++++++++++++++++++++++++++++
 gdb/python/python-internal.h |   8 +-
 gdb/python/python.c          |   5 +-
 6 files changed, 890 insertions(+), 125 deletions(-)
---
base-commit: 1500a5d93a2ae02ee227d6b227acfeda9f6d4f6a
change-id: 20260515-python-safety-initial-422bf34a8ce3

Best regards,
-- 
Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-07-24 12:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-21 23:27 [PATCH v3 0/4] Python safety initial work Tom Tromey
2026-05-21 23:27 ` [PATCH v3 1/4] Add gdbpy_borrowed_ref Tom Tromey
2026-06-01 10:00   ` Matthieu Longo
2026-06-03 18:19     ` Tom Tromey
2026-07-24 12:02       ` Yury Khrustalev
2026-06-29 13:51   ` Matthieu Longo
2026-05-21 23:27 ` [PATCH v3 2/4] Add wrappers for some Python APIs Tom Tromey
2026-05-21 23:27 ` [PATCH v3 3/4] Add wrappers for Python implementation functions and methods Tom Tromey
2026-05-21 23:27 ` [PATCH v3 4/4] Convert py-tui.c to the "python safety" approach Tom Tromey
2026-06-12 15:34 ` [PATCH v3 0/4] Python safety initial work Tom Tromey
2026-07-19 17:16   ` Tom Tromey
2026-07-21 11:45     ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox