binutils-gdb/gdb/python
Matthieu Longo 8b0f0d5fbf gdbpy_registry: cast C extension type object to PyObject * before Py_XINCREF
When enabling the Python limited API, pointers to Python C extension
objects can no longer be implicitly converted to 'PyObject *' by the
compiler.

The lookup() method of gbdpy_registry returns a new reference to the
type object of the looked-up entry. It does so by calling Py_XINCREF()
to increment the reference counter of the returned type object. The
template parameter obj_type corresponds to the type of C extension
object type. With the Python limited API enabled, obj_type can no longer
be implicitly converted to 'PyObject *' when passed to Py_XINCREF().

This patch fixes the resulting compilation issue by adding an explicit
static_cast to 'PyObject *' before passing the value to Py_XINCREF().
As a side effect, this cast enforces, at compile time, that the template
type 'Storage::obj_type' passed to gdbpy_registry is a subclass of
PyObject. To provide a clearer diagnostic when an incorrect type is used,
a static_assert is added to gdbpy_registry, avoiding obscure errors
originating from the static_cast. Finally, the relevant C extension types
passed to gdbpy_registry are updated to inherit publicly from PyObject.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830
Approved-By: Tom Tromey <tom@tromey.com>
2026-01-29 16:46:14 +00:00
..
lib/gdb Update black to 26.1.0 2026-01-23 06:45:46 -07:00
py-all-events.def Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-arch.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-auto-load.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-block.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-bpevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-breakpoint.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-cmd.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-color.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-color.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-connection.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-continueevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-corefile.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-dap.c Small cleanup to interpreter initialization 2026-01-06 10:12:55 -07:00
py-disasm.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-event-types.def Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-event.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-event.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-events.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-evtregistry.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-evts.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-exitedevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-finishbreakpoint.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-frame.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-framefilter.c Use make_unique_xstrdup in more places 2026-01-16 07:44:32 -07:00
py-function.c Use make_unique_xstrdup in more places 2026-01-16 07:44:32 -07:00
py-gdb-readline.c Python limited API: migrate Py_CompileStringExFlags and PyRun_SimpleString 2026-01-28 09:41:25 +00:00
py-inferior.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-infevents.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-infthread.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-instruction.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-instruction.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-lazy-string.c Use make_unique_xstrdup in more places 2026-01-16 07:44:32 -07:00
py-linetable.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-membuf.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-mi.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-micmd.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-newobjfileevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-objfile.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-param.c Use make_unique_xstrdup in more places 2026-01-16 07:44:32 -07:00
py-prettyprint.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-progspace.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record-btrace.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record-btrace.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record-full.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record-full.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-ref.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-registers.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-signalevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-stopevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-stopevent.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-style.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-symbol.c gdbpy_registry: cast C extension type object to PyObject * before Py_XINCREF 2026-01-29 16:46:14 +00:00
py-symtab.c gdbpy_registry: cast C extension type object to PyObject * before Py_XINCREF 2026-01-29 16:46:14 +00:00
py-threadevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-tui.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-type.c gdbpy_registry: cast C extension type object to PyObject * before Py_XINCREF 2026-01-29 16:46:14 +00:00
py-uiout.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-unwind.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-utils.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-value.c gdb/python: use gdbpy_is_value_object in more places 2026-01-27 09:40:43 +00:00
py-varobj.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-xmethods.c gdb: remove make_cv_type typeptr parameter 2026-01-06 14:59:15 -05:00
python-config.py Run isort 2024-04-02 11:21:39 -06:00
python-internal.h gdbpy_registry: cast C extension type object to PyObject * before Py_XINCREF 2026-01-29 16:46:14 +00:00
python.c Python limited API: migrate PyImport_ExtendInittab 2026-01-28 09:41:32 +00:00
python.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00