diff options
| author | Matthieu Longo <matthieu.longo@arm.com> | 2026-01-05 12:14:28 +0100 |
|---|---|---|
| committer | Matthieu Longo <matthieu.longo@arm.com> | 2026-01-29 16:46:14 +0000 |
| commit | 8b0f0d5fbf8d870c433dc62ceaaf740740af9923 (patch) | |
| tree | a9ad6aaed13d7ea73124889df16f9c2a719f7623 /gdb/python/py-objfile.c | |
| parent | c3023c9f083ea051729f00c7fa0ec6851d4d8e51 (diff) | |
| download | binutils-8b0f0d5fbf8d870c433dc62ceaaf740740af9923.tar.gz binutils-8b0f0d5fbf8d870c433dc62ceaaf740740af9923.tar.bz2 binutils-8b0f0d5fbf8d870c433dc62ceaaf740740af9923.zip | |
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>
Diffstat (limited to 'gdb/python/py-objfile.c')
0 files changed, 0 insertions, 0 deletions
