Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Tom de Vries <tdevries@suse.de>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions
Date: Fri, 15 May 2026 11:36:03 -0600	[thread overview]
Message-ID: <87h5o8h8xo.fsf@tromey.com> (raw)
In-Reply-To: <20260515135834.2502165-1-tdevries@suse.de> (Tom de Vries's message of "Fri, 15 May 2026 15:58:30 +0200")

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> +/* The following four functions are refcount-safe wrappers around
Tom> +   Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED}.
Tom> +
Tom> +   Starting with python 3.12, None, True, False and Py_NotImplemented are
Tom> +   immortal, and increasing and decreasing refcount for such objects is a
Tom> +   no-op, and consequently for the limited C API 3.12 and newer,
Tom> +   Py_RETURN_NONE is simply "return Py_None".
Tom> +
Tom> +   So for the limited C API 3.12 and newer, we could just return a
Tom> +   "PyObject *" instead.

I don't think this sentence is correct.  I mean, it might work in some
places, but using this universally would severely uglify gdb because
then spots operating generically would have to check specifically for
such objects.  IMO object immortality is really best thought of as an
implementation detail of CPython and not an exposed feature.

Tom> +   For the limited C API 3.12 and newer, while returning gdbpy_ref<> there's
Tom> +   an imbalance (we do a Py_DECREF in gdbpy_ref_policy::decref, without
Tom> +   corresponding Py_INCREF in Py_RETURN_NONE), but this is not harmful because
Tom> +   Py_DECREF is no-op for immortal objects.  */

Tom> +static inline gdbpy_ref<>
Tom> +py_notimplemented ()
Tom> +{
Tom> +  auto f = [] { Py_RETURN_NOTIMPLEMENTED; };
Tom> +  return gdbpy_ref<> (f ());
Tom> +}

I don't think we use this and I think we shouldn't add it until it is needed.

Tom

  parent reply	other threads:[~2026-05-15 17:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 13:58 Tom de Vries
2026-05-15 13:58 ` [PATCH v3 2/5] [gdb/python] Remove Py_RETURN_{NONE, TRUE, FALSE, NOTIMPLEMENTED} Tom de Vries
2026-05-15 13:58 ` [PATCH v3 3/5] [gdb/python] Undefine " Tom de Vries
2026-05-15 14:05   ` Tom de Vries
2026-05-15 17:40   ` Tom Tromey
2026-05-15 13:58 ` [PATCH v3 4/5] [gdb/python] Use py_{none,false} more often Tom de Vries
2026-05-15 17:39   ` Tom Tromey
2026-05-15 13:58 ` [PATCH v3 5/5] [gdb/python] Use py_{none,notimplemented} " Tom de Vries
2026-05-15 17:38   ` Tom Tromey
2026-05-15 17:36 ` Tom Tromey [this message]
2026-05-15 17:44   ` [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom de Vries
2026-05-15 18:36     ` Tom Tromey
2026-05-15 19:08       ` Tom de Vries

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=87h5o8h8xo.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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