[Bug python/34145] New: [gdb/python] Remove Py_RETURN_NONE uses

vries at gcc dot gnu.org sourceware-bugzilla@sourceware.org
Tue May 12 14:13:49 GMT 2026


https://sourceware.org/bugzilla/show_bug.cgi?id=34145

            Bug ID: 34145
           Summary: [gdb/python] Remove Py_RETURN_NONE uses
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Py_RETURN_NONE used to be a shorthand for:
...
/* Macro for returning Py_None from a function */
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
...

Since python 3.12, Py_None is immutable [1]:
...
/* Macro for returning Py_None from a function.
 * Only treat Py_None as immortal in the limited C API 3.12 and newer. */
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030c0000
#  define Py_RETURN_NONE return Py_NewRef(Py_None)
#else
#  define Py_RETURN_NONE return Py_None
#endif
...

For the refcount case, it makes little sense to endlessly keep increasing the
refcount for this object.

Why not take a single reference once at initialization, and use "return
Py_None" everywhere else.

Probably similar for Py_RETURN_FALSE / Py_RETURN_TRUE.

[1] https://peps.python.org/pep-0683/

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list