Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Tom Tromey <tom@tromey.com>
Cc: Simon Marchi <simark@simark.ca>,  gdb-patches@sourceware.org
Subject: Re: [RFC 1/4] Add gdbpy_borrowed_ref
Date: Wed, 25 Feb 2026 18:38:17 -0700	[thread overview]
Message-ID: <87ldggqo6u.fsf@tromey.com> (raw)
In-Reply-To: <87pl5tqxww.fsf@tromey.com> (Tom Tromey's message of "Tue, 24 Feb 2026 20:55:59 -0700")

Tom> In fact all the casts I am aware are of 'self', which means we could
Tom> maybe solve this a special case: turn functions into methods on the
Tom> object, and then have the wrappers wrap a pointer-to-member-function.

Tom> This would mean that 'this' would be implicitly a borrowed reference,
Tom> but OTOH this isn't likely to be a big source of confusion and it would
Tom> make the code even simpler.

I wrote a draft of this & pushed it to my github branch.
I converted one file to this approach.  Now it looks like:

    struct arch_object : public PyObject
    {
    [...]
      const char *name ()
      {
        return gdbarch_bfd_arch_info (require ())->printable_name;
      }
    ...
    };

    static PyMethodDef arch_object_methods [] = {
      noargs_method<arch_object, &arch_object::name> ("name",
        "name () -> String.\n\
    Return the name of the architecture as a string value."),

I wish it could be a little more concise, but I'm not sure it can be
without a macro.

So maybe this is the way to go.

Tom

  parent reply	other threads:[~2026-02-26  1:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-22 19:49 [RFC 0/4] Better Python safety Tom Tromey
2026-02-22 19:49 ` [RFC 1/4] Add gdbpy_borrowed_ref Tom Tromey
2026-02-24  4:57   ` Simon Marchi
2026-02-25  3:55     ` Tom Tromey
2026-02-25 15:24       ` Simon Marchi
2026-02-26  1:38       ` Tom Tromey [this message]
2026-02-22 19:49 ` [RFC 2/4] Add wrappers for some Python APIs Tom Tromey
2026-02-22 19:49 ` [RFC 3/4] Add constexpr functions to create PyMethodDef entries Tom Tromey
2026-02-22 19:49 ` [RFC 4/4] Convert some Python code to new-style Tom Tromey
2026-02-23 20:28 ` [RFC 0/4] Better Python safety Simon Marchi
2026-02-23 21:00 ` Simon Marchi
2026-02-23 23:23   ` Tom Tromey
2026-02-23 23:56     ` Tom Tromey
2026-02-24  1:05       ` Simon Marchi
2026-02-24 16:29         ` Tom Tromey
2026-02-23 21:22 ` Tom Tromey
2026-03-04 17:39 ` Matthieu Longo
2026-03-04 21:02   ` Tom Tromey

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=87ldggqo6u.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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