From: Matthieu Longo <matthieu.longo@arm.com>
To: <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>, Matthieu Longo <matthieu.longo@arm.com>
Subject: [PATCH v2 6/6] gdb: make remaining Python extension objects inherit from PyObject
Date: Tue, 27 Jan 2026 17:02:15 +0000 [thread overview]
Message-ID: <20260127170215.1803582-7-matthieu.longo@arm.com> (raw)
In-Reply-To: <20260127170215.1803582-1-matthieu.longo@arm.com>
Previous patches made some Python extension objects ipublicly inherit
directly or indirectly from PyObject.
In the interest of consistency, this patch makes all remaining Python
extension objects still not inheriting from PyObject do so.
---
gdb/python/py-arch.c | 4 ++--
gdb/python/py-block.c | 8 ++++----
gdb/python/py-disasm.c | 8 ++------
gdb/python/py-instruction.c | 5 ++---
gdb/python/py-lazy-string.c | 5 ++---
gdb/python/py-linetable.c | 12 ++++++------
gdb/python/py-param.c | 4 +---
gdb/python/py-prettyprint.c | 6 ++----
gdb/python/py-record-btrace.c | 5 ++---
gdb/python/py-record.c | 4 +---
gdb/python/py-record.h | 8 ++------
gdb/python/py-registers.c | 10 ++++------
gdb/python/py-style.c | 4 +---
gdb/python/py-type.c | 4 ++--
gdb/python/py-unwind.c | 8 ++------
gdb/python/py-value.c | 4 ++--
16 files changed, 37 insertions(+), 62 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 765a21ae0b7..f761c7ba30b 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -22,8 +22,8 @@
#include "disasm.h"
#include "python-internal.h"
-struct arch_object {
- PyObject_HEAD
+struct arch_object: public PyObject
+{
struct gdbarch *gdbarch;
};
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index 3a59d767b5c..4b02115a5f9 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -23,8 +23,8 @@
#include "python-internal.h"
#include "objfiles.h"
-struct block_object {
- PyObject_HEAD
+struct block_object: public PyObject
+{
/* The GDB block structure that represents a frame's code block. */
const struct block *block;
/* The backing object file. There is no direct relationship in GDB
@@ -33,8 +33,8 @@ struct block_object {
struct objfile *objfile;
};
-struct block_syms_iterator_object {
- PyObject_HEAD
+struct block_syms_iterator_object: public PyObject
+{
/* The block. */
const struct block *block;
/* The iterator for that block. */
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 037223f05e3..8b796628d72 100644
--- a/gdb/python/py-disasm.c
+++ b/gdb/python/py-disasm.c
@@ -57,10 +57,8 @@ extern PyTypeObject disasm_info_object_type;
that is an address that should be printed using a call to GDB's
internal print_address function. */
-struct disasm_addr_part_object
+struct disasm_addr_part_object: public PyObject
{
- PyObject_HEAD
-
/* The address to be formatted. */
bfd_vma address;
@@ -77,10 +75,8 @@ extern PyTypeObject disasm_addr_part_object_type;
this type represents a small part of a disassembled instruction; a part
that is a piece of test along with an associated style. */
-struct disasm_text_part_object
+struct disasm_text_part_object: public PyObject
{
- PyObject_HEAD
-
/* The string that is this part. */
std::string *string;
diff --git a/gdb/python/py-instruction.c b/gdb/python/py-instruction.c
index b7ab6e4668f..df64d85988f 100644
--- a/gdb/python/py-instruction.c
+++ b/gdb/python/py-instruction.c
@@ -29,9 +29,8 @@ PyTypeObject py_insn_type = {
/* Python instruction object. */
-struct py_insn_obj {
- PyObject_HEAD
-};
+struct py_insn_obj: public PyObject
+{};
/* Getter function for gdb.Instruction attributes. */
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 41f958744c1..3e95a041dcc 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -23,9 +23,8 @@
#include "valprint.h"
#include "language.h"
-struct lazy_string_object {
- PyObject_HEAD
-
+struct lazy_string_object: public PyObject
+{
/* Holds the address of the lazy string. */
CORE_ADDR address;
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 0ea2d843dd3..2db3488b1d3 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -19,8 +19,8 @@
#include "python-internal.h"
-struct linetable_entry_object {
- PyObject_HEAD
+struct linetable_entry_object: public PyObject
+{
/* The line table source line. */
int line;
/* The pc associated with the source line. */
@@ -29,8 +29,8 @@ struct linetable_entry_object {
extern PyTypeObject linetable_entry_object_type;
-struct linetable_object {
- PyObject_HEAD
+struct linetable_object: public PyObject
+{
/* The symtab python object. We store the Python object here as the
underlying symtab can become invalid, and we have to run validity
checks on it. */
@@ -39,8 +39,8 @@ struct linetable_object {
extern PyTypeObject linetable_object_type;
-struct ltpy_iterator_object {
- PyObject_HEAD
+struct ltpy_iterator_object: public PyObject
+{
/* The current entry in the line table for the iterator */
int current_index;
/* Pointer back to the original source line table object. Needed to
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index f305661fa43..4f61b8efd3c 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -124,10 +124,8 @@ union parmpy_variable
};
/* A GDB parameter. */
-struct parmpy_object
+struct parmpy_object: public PyObject
{
- PyObject_HEAD
-
/* The type of the parameter. */
enum var_types type;
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index a920e6f3cf7..8895f1c8771 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -783,10 +783,8 @@ gdbpy_get_print_options (value_print_options *opts)
/* A ValuePrinter is just a "tag", so it has no state other than that
required by Python. */
-struct printer_object
-{
- PyObject_HEAD
-};
+struct printer_object: public PyObject
+{};
/* The ValuePrinter type object. */
PyTypeObject printer_object_type =
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index d9534c02331..637488d797c 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -29,9 +29,8 @@
/* Python object for btrace record lists. */
-struct btpy_list_object {
- PyObject_HEAD
-
+struct btpy_list_object: public PyObject
+{
/* The thread this list belongs to. */
thread_info *thread;
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index 3c985c172e1..bf0551cfeac 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -55,10 +55,8 @@ PyTypeObject recpy_aux_type = {
};
/* Python RecordGap object. */
-struct recpy_gap_object
+struct recpy_gap_object: public PyObject
{
- PyObject_HEAD
-
/* Reason code. */
int reason_code;
diff --git a/gdb/python/py-record.h b/gdb/python/py-record.h
index 039a1b125e3..0722a918c68 100644
--- a/gdb/python/py-record.h
+++ b/gdb/python/py-record.h
@@ -25,10 +25,8 @@
#include "record.h"
/* Python Record object. */
-struct recpy_record_object
+struct recpy_record_object: public PyObject
{
- PyObject_HEAD
-
/* The thread this object refers to. */
thread_info *thread;
@@ -39,10 +37,8 @@ struct recpy_record_object
/* Python recorded element object. This is generic enough to represent
recorded instructions as well as recorded function call segments, hence the
generic name. */
-struct recpy_element_object
+struct recpy_element_object: public PyObject
{
- PyObject_HEAD
-
/* The thread this object refers to. */
thread_info *thread;
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index 30b333c444c..d600b67be77 100644
--- a/gdb/python/py-registers.c
+++ b/gdb/python/py-registers.c
@@ -32,9 +32,8 @@ static const registry<gdbarch>::key<gdbpy_register_type>
gdbpy_register_object_data;
/* Structure for iterator over register descriptors. */
-struct register_descriptor_iterator_object {
- PyObject_HEAD
-
+struct register_descriptor_iterator_object: public PyObject
+{
/* The register group that the user is iterating over. This will never
be NULL. */
const struct reggroup *reggroup;
@@ -61,9 +60,8 @@ struct register_descriptor_object: public PyObject
extern PyTypeObject register_descriptor_object_type;
/* Structure for iterator over register groups. */
-struct reggroup_iterator_object {
- PyObject_HEAD
-
+struct reggroup_iterator_object: public PyObject
+{
/* The index into GROUPS for the next group to return. */
std::vector<const reggroup *>::size_type index;
diff --git a/gdb/python/py-style.c b/gdb/python/py-style.c
index f404864251c..3172400fcaf 100644
--- a/gdb/python/py-style.c
+++ b/gdb/python/py-style.c
@@ -36,10 +36,8 @@ static struct {
};
/* A style. */
-struct style_object
+struct style_object: public PyObject
{
- PyObject_HEAD
-
/* Underlying style, only valid when STYLE_NAME is NULL. */
ui_file_style style;
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 1cc583b38d2..3b0525c6ec6 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -42,8 +42,8 @@ struct field_object: public gdbpy__dict__wrapper
extern PyTypeObject field_object_type;
/* A type iterator object. */
-struct typy_iterator_object {
- PyObject_HEAD
+struct typy_iterator_object: public PyObject
+{
/* The current field index. */
int field;
/* What to return. */
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index f9fd848ea0e..07effe7fa88 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -66,10 +66,8 @@ show_pyuw_debug (struct ui_file *file, int from_tty,
} \
} while (0)
-struct pending_frame_object
+struct pending_frame_object: public PyObject
{
- PyObject_HEAD
-
/* Frame we are unwinding. */
frame_info_ptr frame_info;
@@ -94,10 +92,8 @@ struct saved_reg
/* The data we keep for the PyUnwindInfo: pending_frame, saved registers
and frame ID. */
-struct unwind_info_object
+struct unwind_info_object: public PyObject
{
- PyObject_HEAD
-
/* gdb.PendingFrame for the frame we are unwinding. */
PyObject *pending_frame;
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 6c28f13a3de..4f2f9cc4b0b 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -54,8 +54,8 @@
#define builtin_type_pybool \
language_bool_type (current_language, gdbpy_enter::get_gdbarch ())
-struct value_object {
- PyObject_HEAD
+struct value_object: public PyObject
+{
struct value_object *next;
struct value_object *prev;
struct value *value;
--
2.52.0
next prev parent reply other threads:[~2026-01-27 17:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 17:02 [PATCH v2 0/6] gdb: minor fixes for Python limited C API support Matthieu Longo
2026-01-27 17:02 ` [PATCH v2 1/6] Python limited API: migrate Py_CompileStringExFlags and PyRun_SimpleString Matthieu Longo
2026-01-27 17:54 ` Tom Tromey
2026-01-27 17:02 ` [PATCH v2 2/6] Python limited API: migrate PyImport_ExtendInittab Matthieu Longo
2026-01-27 17:54 ` Tom Tromey
2026-01-27 17:02 ` [PATCH v2 3/6] gdbpy_registry: cast C extension type object to PyObject * before Py_XINCREF Matthieu Longo
2026-01-27 18:01 ` Tom Tromey
2026-01-27 18:29 ` Tom Tromey
2026-01-28 11:58 ` Matthieu Longo
2026-01-27 17:02 ` [PATCH v2 4/6] gdb: new setters and getters for __dict__, and attributes Matthieu Longo
2026-01-27 19:06 ` Tom Tromey
2026-01-28 11:57 ` Matthieu Longo
2026-01-28 17:43 ` Matthieu Longo
2026-01-28 17:51 ` Tom Tromey
2026-01-27 17:02 ` [PATCH v2 5/6] gdb: cast all Python extension objects passed to gdbpy_ref_policy to PyObject* Matthieu Longo
2026-01-27 18:28 ` Tom Tromey
2026-01-28 11:58 ` Matthieu Longo
2026-01-27 17:02 ` Matthieu Longo [this message]
2026-01-27 18:29 ` [PATCH v2 6/6] gdb: make remaining Python extension objects inherit from PyObject Tom Tromey
2026-01-28 11:58 ` Matthieu Longo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260127170215.1803582-7-matthieu.longo@arm.com \
--to=matthieu.longo@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox