Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Koning <paulkoning@comcast.net>
To: Tom Tromey <tom@tromey.com>
Cc: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Use the "O!" format more in the Python code
Date: Fri, 27 Feb 2026 15:24:08 -0500	[thread overview]
Message-ID: <78A812F6-2C9A-4E41-84BB-BA036D377BFD@comcast.net> (raw)
In-Reply-To: <871pi6t0uw.fsf@tromey.com>



> On Feb 27, 2026, at 2:58 PM, Tom Tromey <tom@tromey.com> wrote:
> 
>>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes:
> 
> Paul> Also, any type can be subclassed.  That
> Paul> last point is not true for types defined in C code, unless the code
> Paul> allows it to happen.  In general it should do so; it's very rare
> Paul> indeed for it to be "the right thing" for a type not to allow
> Paul> subclasses.
> 
> In gdb we've been fairly selective with this.
> 
> I looked it up and you have to set Py_TPFLAGS_BASETYPE, which we do in
> 13 of the classes that gdb implements.
> 
> Maybe we should do this everywhere?  But if we did that then wouldn't we
> also want to implement the 'dict' feature everywhere as well?

You mean in the sense that an object acts as if it has a dictionary inside, holding its attributes?  I'm not sure if that is needed for the GDB (base) classes.  Consider "slotted" objects, which don't have one, but can be subclassed and the subclass objects may have a dictionary, or not, at the discretion of the subclass author.

> I'm not sure there's a big advantage to it or need for it though.
> So maybe it's just busy-work.
> 
> I've been hoping to transition the internal types to be real C++ types,
> like give them constructors and destructors, initializers, etc.  But
> maybe it's not really possible with the Python lifetime model, at least
> when subclassing is available.

Python classes have construtors and destructors, but they work differently than C++.  Especially destructors because it isn't necessarily obvious when they will be called, at least for some scenarios where things aren't freed until the garbage collector gets there.

It's indeed possible that for some classes subclassing is unlikely to be wanted.  But I do remember, some years ago, wanting to subclass a GDB type and finding I could not.  I no longer remember which class it was, unfortunately.

	paul

      reply	other threads:[~2026-02-27 20:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 16:48 Tom Tromey
2026-02-27 18:23 ` Tom de Vries
2026-02-27 18:31   ` Tom Tromey
2026-02-27 19:01     ` Tom Tromey
2026-02-27 19:06       ` Tom de Vries
2026-02-27 19:35     ` Paul Koning
2026-02-27 19:58       ` Tom Tromey
2026-02-27 20:24         ` Paul Koning [this message]

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=78A812F6-2C9A-4E41-84BB-BA036D377BFD@comcast.net \
    --to=paulkoning@comcast.net \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    --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