]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/python] Introduce py_{none,true,false,notimplemented} functions
authorTom de Vries <tdevries@suse.de>
Fri, 15 May 2026 19:38:12 +0000 (21:38 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 15 May 2026 19:38:12 +0000 (21:38 +0200)
commitb37f2bd246c3fb15e4e242ae5be95fc62a8858da
treefa08507a6625bc37775098aefb9849c1d3ab46f7
parent776715ea683b93c0415fc4eb31b4fcec5f2153fc
[gdb/python] Introduce py_{none,true,false,notimplemented} functions

I came across this code:
...
   if (c)
     return v;
   else
     Py_RETURN_NONE;
...
and realized I couldn't easily rewrite it into "return c ? v : ...".

Probably something like this would work:
...
  return c ? v : ([] { Py_RETURN_NONE; } ());
...
but it made me wonder if we can get rid of Py_RETURN_NONE.

The only point of it seems to be to increase the reference count on the
Py_None object for older python versions.

Add a refcount-safe wrapper py_none (returning a gdbpy_ref), with the aim of
replacing all uses of Py_RETURN_NONE with "return py_none ().release ()".

Likewise for Py_RETURN_TRUE/Py_RETURN_FALSE/Py_RETURN_NOTIMPLEMENTED.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34145
gdb/python/python-internal.h