* [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions
@ 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
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 13:58 UTC (permalink / raw)
To: gdb-patches
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 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 | 44 ++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 3147156d5be..7c58309e4d4 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -1343,4 +1343,48 @@ class gdbpy_memoizing_registry_storage
extern int eval_python_command (const char *command, int start_symbol,
const char *filename = nullptr);
+/* The following four functions are refcount-safe wrappers around
+ Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED}.
+
+ Starting with python 3.12, None, True, False and Py_NotImplemented are
+ immortal, and increasing and decreasing refcount for such objects is a
+ no-op, and consequently for the limited C API 3.12 and newer,
+ Py_RETURN_NONE is simply "return Py_None".
+
+ So for the limited C API 3.12 and newer, we could just return a
+ "PyObject *" instead.
+
+ For the limited C API 3.12 and newer, while returning gdbpy_ref<> there's
+ an imbalance (we do a Py_DECREF in gdbpy_ref_policy::decref, without
+ corresponding Py_INCREF in Py_RETURN_NONE), but this is not harmful because
+ Py_DECREF is no-op for immortal objects. */
+
+static inline gdbpy_ref<>
+py_none ()
+{
+ auto f = [] { Py_RETURN_NONE; };
+ return gdbpy_ref<> (f ());
+}
+
+static inline gdbpy_ref<>
+py_true ()
+{
+ auto f = [] { Py_RETURN_TRUE; };
+ return gdbpy_ref<> (f ());
+}
+
+static inline gdbpy_ref<>
+py_false ()
+{
+ auto f = [] { Py_RETURN_FALSE; };
+ return gdbpy_ref<> (f ());
+}
+
+static inline gdbpy_ref<>
+py_notimplemented ()
+{
+ auto f = [] { Py_RETURN_NOTIMPLEMENTED; };
+ return gdbpy_ref<> (f ());
+}
+
#endif /* GDB_PYTHON_PYTHON_INTERNAL_H */
base-commit: 79fcceafcbfe9aa02441445eb9444718b17330df
--
2.51.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 2/5] [gdb/python] Remove Py_RETURN_{NONE, TRUE, FALSE, NOTIMPLEMENTED}
2026-05-15 13:58 [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom de Vries
@ 2026-05-15 13:58 ` Tom de Vries
2026-05-15 13:58 ` [PATCH v3 3/5] [gdb/python] Undefine " Tom de Vries
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 13:58 UTC (permalink / raw)
To: gdb-patches
Result of:
...
$ sed -i 's/Py_RETURN_NONE/return py_none ().release ()/' gdb/python/*.{c,h}
...
with the changes in py_none reverted.
Likewise for Py_RETURN_TRUE,Py_RETURN_FALSE and Py_RETURN_NOTIMPLEMENTED.
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34145
---
gdb/python/py-block.c | 22 ++++++-------
gdb/python/py-breakpoint.c | 54 ++++++++++++++++----------------
gdb/python/py-cmd.c | 2 +-
gdb/python/py-connection.c | 6 ++--
gdb/python/py-corefile.c | 8 ++---
gdb/python/py-disasm.c | 6 ++--
gdb/python/py-evtregistry.c | 6 ++--
gdb/python/py-finishbreakpoint.c | 2 +-
gdb/python/py-frame.c | 14 ++++-----
gdb/python/py-framefilter.c | 2 +-
gdb/python/py-inferior.c | 26 +++++++--------
gdb/python/py-infthread.c | 24 +++++++-------
gdb/python/py-linetable.c | 14 ++++-----
gdb/python/py-mi.c | 2 +-
gdb/python/py-micmd.c | 4 +--
gdb/python/py-objfile.c | 22 ++++++-------
gdb/python/py-prettyprint.c | 2 +-
gdb/python/py-progspace.c | 18 +++++------
gdb/python/py-record-btrace.c | 48 ++++++++++++++--------------
gdb/python/py-record.c | 12 +++----
gdb/python/py-registers.c | 2 +-
gdb/python/py-symbol.c | 10 +++---
gdb/python/py-symtab.c | 18 +++++------
gdb/python/py-tui.c | 10 +++---
gdb/python/py-type.c | 36 ++++++++++-----------
gdb/python/py-unwind.c | 12 +++----
gdb/python/py-value.c | 28 ++++++++---------
gdb/python/py-xmethods.c | 2 +-
gdb/python/python.c | 28 ++++++++---------
29 files changed, 220 insertions(+), 220 deletions(-)
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index d9751d26378..17c9cbdaff0 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -166,7 +166,7 @@ blpy_get_function (PyObject *self, void *closure)
if (sym)
return symbol_to_symbol_object (sym).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static PyObject *
@@ -182,7 +182,7 @@ blpy_get_superblock (PyObject *self, void *closure)
if (super_block)
return block_to_block_object (super_block, self_obj->objfile).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement gdb.Block.subblocks attribute. Return a list of gdb.Block
@@ -245,7 +245,7 @@ blpy_get_static_block (PyObject *self, void *closure)
BLPY_REQUIRE_VALID (self, block);
if (block->superblock () == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
static_block = block->static_block ();
@@ -263,9 +263,9 @@ blpy_is_global (PyObject *self, void *closure)
BLPY_REQUIRE_VALID (self, block);
if (block->superblock ())
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.Block.is_static (self) -> Boolean.
@@ -280,9 +280,9 @@ blpy_is_static (PyObject *self, void *closure)
if (block->superblock () != NULL
&& block->superblock ()->superblock () == NULL)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Given a string, returns the gdb.Symbol representing that symbol in this
@@ -465,9 +465,9 @@ blpy_is_valid (PyObject *self, PyObject *args)
block = block_object_to_block (self);
if (block == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.BlockIterator.is_valid (self) -> Boolean.
@@ -480,9 +480,9 @@ blpy_iter_is_valid (PyObject *self, PyObject *args)
(block_syms_iterator_object *) self;
if (iter_obj->source->block == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* __repr__ implementation for gdb.Block. */
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index d96c67694b3..68d4f77c608 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -139,8 +139,8 @@ bppy_is_valid (PyObject *self, PyObject *args)
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
if (self_bp->bp)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Python function to test whether or not the breakpoint is enabled. */
@@ -151,10 +151,10 @@ bppy_get_enabled (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (! self_bp->bp)
- Py_RETURN_FALSE;
+ return py_false ().release ();
if (self_bp->bp->enable_state == bp_enabled)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Python function to test whether or not the breakpoint is silent. */
@@ -165,8 +165,8 @@ bppy_get_silent (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (self_bp->bp->silent)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Python function to set the enabled state of a breakpoint. */
@@ -444,7 +444,7 @@ bppy_delete_breakpoint (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
@@ -532,7 +532,7 @@ bppy_get_location (PyObject *self, void *closure)
if (obj->bp->type != bp_breakpoint
&& obj->bp->type != bp_hardware_breakpoint)
- Py_RETURN_NONE;
+ return py_none ().release ();
const char *str = obj->bp->locspec->to_string ();
if (str == nullptr)
@@ -550,7 +550,7 @@ bppy_get_expression (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (obj);
if (!is_watchpoint (obj->bp))
- Py_RETURN_NONE;
+ return py_none ().release ();
watchpoint *wp = gdb::checked_static_cast<watchpoint *> (obj->bp);
@@ -572,7 +572,7 @@ bppy_get_condition (PyObject *self, void *closure)
str = obj->bp->cond_string.get ();
if (! str)
- Py_RETURN_NONE;
+ return py_none ().release ();
return host_string_to_python_string (str).release ();
}
@@ -627,7 +627,7 @@ bppy_get_commands (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (! self_bp->bp->commands)
- Py_RETURN_NONE;
+ return py_none ().release ();
string_file stb;
@@ -703,9 +703,9 @@ bppy_get_visibility (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (user_breakpoint_p (self_bp->bp))
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Python function to determine if the breakpoint is a temporary
@@ -720,9 +720,9 @@ bppy_get_temporary (PyObject *self, void *closure)
if (self_bp->bp->disposition == disp_del
|| self_bp->bp->disposition == disp_del_at_next_stop)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Python function to determine if the breakpoint is a pending
@@ -736,11 +736,11 @@ bppy_get_pending (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (is_watchpoint (self_bp->bp))
- Py_RETURN_FALSE;
+ return py_false ().release ();
if (pending_breakpoint_p (self_bp->bp))
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Python function to get the breakpoint's number. */
@@ -763,7 +763,7 @@ bppy_get_thread (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (self_bp->bp->thread == -1)
- Py_RETURN_NONE;
+ return py_none ().release ();
return gdb_py_object_from_longest (self_bp->bp->thread).release ();
}
@@ -777,7 +777,7 @@ bppy_get_inferior (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (self_bp->bp->inferior == -1)
- Py_RETURN_NONE;
+ return py_none ().release ();
return gdb_py_object_from_longest (self_bp->bp->inferior).release ();
}
@@ -791,7 +791,7 @@ bppy_get_task (PyObject *self, void *closure)
BPPY_REQUIRE_VALID (self_bp);
if (self_bp->bp->task == -1)
- Py_RETURN_NONE;
+ return py_none ().release ();
return gdb_py_object_from_longest (self_bp->bp->task).release ();
}
@@ -1598,9 +1598,9 @@ bplocpy_get_enabled (PyObject *py_self, void *closure)
BPLOCPY_REQUIRE_VALID (self->owner, self);
if (self->bp_loc->enabled)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Python function to get address of breakpoint location. */
@@ -1673,7 +1673,7 @@ bplocpy_get_source_location (PyObject *py_self, void *closure)
return tup.release ();
}
else
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Python function to get the function name of where this location was set. */
@@ -1687,7 +1687,7 @@ bplocpy_get_function (PyObject *py_self, void *closure)
const auto fn_name = self->bp_loc->function_name.get ();
if (fn_name != nullptr)
return host_string_to_python_string (fn_name).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static PyObject *
@@ -1726,7 +1726,7 @@ bplocpy_get_fullname (PyObject *py_self, void *closure)
= host_string_to_python_string (symtab->fullname ());
return fullname.release ();
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* De-allocation function to be called for the Python object. */
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 3fbc26b0cde..bcb1ba37d93 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -76,7 +76,7 @@ static PyObject *
cmdpy_dont_repeat (PyObject *self, PyObject *args)
{
dont_repeat ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
\f
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index a8bea4d832f..2d0b2e94659 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -216,9 +216,9 @@ connpy_is_valid (PyObject *self, PyObject *args)
connection_object *conn = (connection_object *) self;
if (conn->target == nullptr)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Return the id number of this connection. */
@@ -274,7 +274,7 @@ connpy_get_connection_details (PyObject *self, void *closure)
if (details != nullptr)
return host_string_to_python_string (details).release ();
else
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Python specific initialization for this file. */
diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c
index 0fa4e90488c..2c5596d093c 100644
--- a/gdb/python/py-corefile.c
+++ b/gdb/python/py-corefile.c
@@ -199,9 +199,9 @@ cfpy_is_valid (PyObject *self, PyObject *args)
corefile_object *obj = (corefile_object *) self;
if (!cfpy_corefile_object_is_valid (obj))
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implement gdb.Corefile.mapped_files (). Return a List of
@@ -469,9 +469,9 @@ cfmf_is_main_exec (PyObject *self, void *closure)
= (corefile_mapped_file_object *) self;
if (obj->is_main_exec_p)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
\f
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 1c5661dd307..d4d50e90035 100644
--- a/gdb/python/py-disasm.c
+++ b/gdb/python/py-disasm.c
@@ -318,9 +318,9 @@ disasmpy_info_is_valid (PyObject *self, PyObject *args)
disasm_info_object *disasm_obj = (disasm_info_object *) self;
if (disasm_info_object_is_valid (disasm_obj))
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Set the Python exception to be a gdb.MemoryError object, with ADDRESS
@@ -625,7 +625,7 @@ disasmpy_set_enabled (PyObject *self, PyObject *args, PyObject *kw)
return nullptr;
python_print_insn_enabled = newstate == Py_True;
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement DisassembleInfo.read_memory(LENGTH, OFFSET). Read LENGTH
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index 9d12d0161f1..8d2a68da2a4 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -45,7 +45,7 @@ evregpy_connect (PyObject *self, PyObject *function)
if (PyList_Append (callback_list, func) < 0)
return NULL;
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of EventRegistry.disconnect () -> NULL.
@@ -63,12 +63,12 @@ evregpy_disconnect (PyObject *self, PyObject *function)
index = PySequence_Index (callback_list, func);
if (index < 0)
- Py_RETURN_NONE;
+ return py_none ().release ();
if (PySequence_DelItem (callback_list, index) < 0)
return NULL;
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Create a new event registry. This function uses PyObject_New
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index fbbb705a864..f85f4fff766 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -73,7 +73,7 @@ bpfinishpy_get_returnvalue (PyObject *self, void *closure)
(struct finish_breakpoint_object *) self;
if (!self_finishbp->return_value)
- Py_RETURN_NONE;
+ return py_none ().release ();
Py_INCREF (self_finishbp->return_value);
return self_finishbp->return_value;
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 1420d2ac5b9..2a674ba52f8 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -119,9 +119,9 @@ frapy_is_valid (PyObject *self, PyObject *args)
}
if (frame == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.Frame.name (self) -> String.
@@ -354,7 +354,7 @@ frapy_function (PyObject *self, PyObject *args)
if (sym)
return symbol_to_symbol_object (sym).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Convert a frame_info struct to a Python Frame object.
@@ -583,7 +583,7 @@ frapy_select (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* The stack frame level for this frame. */
@@ -645,7 +645,7 @@ frapy_static_link (PyObject *self, PyObject *args)
}
if (link == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return frame_info_to_frame_object (link).release ();
}
@@ -739,8 +739,8 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)
result = Py_NE;
if (op == result)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Sets up the Frame API in the gdb module. */
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 26172d9f80e..f256a26807c 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -279,7 +279,7 @@ get_py_iter_from_func (PyObject *filter, const char *func)
}
}
else
- Py_RETURN_NONE;
+ return py_none ().release ();
return NULL;
}
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 1a30f4ee378..d2fc159c227 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -439,7 +439,7 @@ infpy_get_connection_num (PyObject *self, void *closure)
process_stratum_target *target = inf->inferior->process_target ();
if (target == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return gdb_py_object_from_longest (target->connection_number).release ();
}
@@ -461,8 +461,8 @@ infpy_get_was_attached (PyObject *self, void *closure)
INFPY_REQUIRE_VALID (inf);
if (inf->inferior->attach_flag)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Getter of gdb.Inferior.progspace. */
@@ -609,7 +609,7 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, ex);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of
@@ -686,7 +686,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
if (found)
return gdb_py_object_from_ulongest (found_addr).release ();
else
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
@@ -698,9 +698,9 @@ infpy_is_valid (PyObject *self, PyObject *args)
inferior_object *inf = (inferior_object *) self;
if (! inf->inferior)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.Inferior.thread_from_handle (self, handle)
@@ -759,7 +759,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of gdb.Inferior.architecture. */
@@ -799,7 +799,7 @@ infpy_clear_env (PyObject *obj)
INFPY_REQUIRE_VALID (self);
self->inferior->environment.clear ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement set_env. */
@@ -818,7 +818,7 @@ infpy_set_env (PyObject *obj, PyObject *args, PyObject *kw)
return nullptr;
self->inferior->environment.set (name, val);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement unset_env. */
@@ -835,7 +835,7 @@ infpy_unset_env (PyObject *obj, PyObject *args, PyObject *kw)
return nullptr;
self->inferior->environment.unset (name);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Getter for "arguments". */
@@ -849,7 +849,7 @@ infpy_get_args (PyObject *self, void *closure)
const std::string &args = inf->inferior->args ();
if (args.empty ())
- Py_RETURN_NONE;
+ return py_none ().release ();
return host_string_to_python_string (args.c_str ()).release ();
}
@@ -938,7 +938,7 @@ infpy_get_main_name (PyObject *self, void *closure)
}
if (name == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return host_string_to_python_string (name).release ();
}
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 672546e106d..ddb67a284ac 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -77,7 +77,7 @@ thpy_get_name (PyObject *self, void *ignore)
const char *name = thread_name (thread_obj->thread);
if (name == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
return PyUnicode_FromString (name);
}
@@ -105,7 +105,7 @@ thpy_get_details (PyObject *self, void *ignore)
return gdbpy_handle_gdb_exception (nullptr, except);
}
if (extra_info == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return PyUnicode_FromString (extra_info);
}
@@ -246,7 +246,7 @@ thpy_switch (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of InferiorThread.is_stopped () -> Boolean.
@@ -260,9 +260,9 @@ thpy_is_stopped (PyObject *self, PyObject *args)
THPY_REQUIRE_VALID (thread_obj);
if (thread_obj->thread->state () == THREAD_STOPPED)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implementation of InferiorThread.is_running () -> Boolean.
@@ -276,9 +276,9 @@ thpy_is_running (PyObject *self, PyObject *args)
THPY_REQUIRE_VALID (thread_obj);
if (thread_obj->thread->state () == THREAD_RUNNING)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implementation of InferiorThread.is_exited () -> Boolean.
@@ -292,9 +292,9 @@ thpy_is_exited (PyObject *self, PyObject *args)
THPY_REQUIRE_VALID (thread_obj);
if (thread_obj->thread->state () == THREAD_EXITED)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implementation of gdb.InfThread.is_valid (self) -> Boolean.
@@ -307,9 +307,9 @@ thpy_is_valid (PyObject *self, PyObject *args)
thread_object *thread_obj = (thread_object *) self;
if (! thread_obj->thread)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.InferiorThread.handle (self) -> handle. */
@@ -400,7 +400,7 @@ gdbpy_selected_thread (PyObject *self, PyObject *args)
if (inferior_ptid != null_ptid)
return thread_to_thread_object (inferior_thread ()).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static int
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 2afa9b033e7..d2d85026a32 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -124,7 +124,7 @@ build_line_table_tuple_from_entries
int i;
if (entries.size () < 1)
- Py_RETURN_NONE;
+ return py_none ().release ();
gdbpy_ref<> tuple (PyTuple_New (entries.size ()));
@@ -204,10 +204,10 @@ ltpy_has_line (PyObject *self, PyObject *args)
{
const linetable_entry *item = &(symtab->linetable ()->item[index]);
if (item->line == py_line)
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implementation of gdb.LineTable.source_lines (self) -> List.
@@ -266,9 +266,9 @@ ltpy_is_valid (PyObject *self, PyObject *args)
symtab = symtab_object_to_symtab (get_symtab (self));
if (symtab == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Deconstructor for the line table object. Decrement the reference
@@ -427,9 +427,9 @@ ltpy_iter_is_valid (PyObject *self, PyObject *args)
symtab = symtab_object_to_symtab (get_symtab (iter_obj->source));
if (symtab == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_linetable);
diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c
index 27c79d60636..1bcb276da8a 100644
--- a/gdb/python/py-mi.c
+++ b/gdb/python/py-mi.c
@@ -406,5 +406,5 @@ gdbpy_notify_mi (PyObject *self, PyObject *args, PyObject *kwargs)
gdb_flush (mi->event_channel);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c
index 6edea04ccb5..73f5297bd70 100644
--- a/gdb/python/py-micmd.c
+++ b/gdb/python/py-micmd.c
@@ -490,8 +490,8 @@ micmdpy_get_installed (PyObject *self, void *closure)
struct micmdpy_object *micmd_obj = (struct micmdpy_object *) self;
if (micmd_obj->mi_command == nullptr)
- Py_RETURN_FALSE;
- Py_RETURN_TRUE;
+ return py_false ().release ();
+ return py_true ().release ();
}
/* Set the gdb.MICommand.installed property. The property can be set to
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index d427f149429..ec8b82fbe13 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -87,7 +87,7 @@ objfpy_get_filename (PyObject *self, void *closure)
if (obj->objfile)
return (host_string_to_python_string (objfile_name (obj->objfile))
.release ());
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* An Objfile method which returns the objfile's file name, as specified
@@ -105,7 +105,7 @@ objfpy_get_username (PyObject *self, void *closure)
return host_string_to_python_string (username).release ();
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Get the 'is_file' attribute. */
@@ -117,7 +117,7 @@ objfpy_get_is_file (PyObject *o, void *ignore)
if (self->objfile != nullptr)
return PyBool_FromLong ((self->objfile->flags & OBJF_NOT_FILENAME) == 0);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* If SELF is a separate debug-info file, return the "backlink" field.
@@ -135,7 +135,7 @@ objfpy_get_owner (PyObject *self, void *closure)
owner = objfile->separate_debug_objfile_backlink;
if (owner != NULL)
return objfile_to_objfile_object (owner).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* An Objfile method which returns the objfile's build id, or None. */
@@ -165,7 +165,7 @@ objfpy_get_build_id (PyObject *self, void *closure)
return host_string_to_python_string (hex_form.c_str ()).release ();
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* An Objfile method which returns the objfile's progspace, or None. */
@@ -178,7 +178,7 @@ objfpy_get_progspace (PyObject *self, void *closure)
if (obj->objfile)
return pspace_to_pspace_object (obj->objfile->pspace ()).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static void
@@ -415,9 +415,9 @@ objfpy_is_valid (PyObject *self, PyObject *args)
objfile_object *obj = (objfile_object *) self;
if (! obj->objfile)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.Objfile.add_separate_debug_file (self, string). */
@@ -445,7 +445,7 @@ objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of
@@ -471,7 +471,7 @@ objfpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
struct symbol *sym = lookup_global_symbol_from_objfile
(obj->objfile, GLOBAL_BLOCK, symbol_name, flags).symbol;
if (sym == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return symbol_to_symbol_object (sym).release ();
}
@@ -504,7 +504,7 @@ objfpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
struct symbol *sym = lookup_global_symbol_from_objfile
(obj->objfile, STATIC_BLOCK, symbol_name, flags).symbol;
if (sym == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return symbol_to_symbol_object (sym).release ();
}
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 0cf0cde881c..a561196a2a9 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -119,7 +119,7 @@ find_pretty_printer_from_objfiles (PyObject *value)
return function.release ();
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Subroutine of find_pretty_printer to simplify it.
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 37b92a64634..48e52328e9c 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -106,7 +106,7 @@ pspy_get_filename (PyObject *self, void *closure)
return (host_string_to_python_string (objfile_name (objfile))
.release ());
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement the gdb.Progspace.symbol_file attribute. Return the
@@ -126,7 +126,7 @@ pspy_get_symbol_file (PyObject *self, void *closure)
if (objfile != nullptr)
return objfile_to_objfile_object (objfile).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement the gdb.Progspace.executable_filename attribute. Return a
@@ -145,7 +145,7 @@ pspy_get_exec_file (PyObject *self, void *closure)
if (filename != nullptr)
return host_string_to_python_string (filename).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static void
@@ -456,7 +456,7 @@ pspy_solib_name (PyObject *o, PyObject *args)
const char *soname = solib_name_from_address (self->pspace, pc);
if (soname == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return host_string_to_python_string (soname).release ();
}
@@ -479,7 +479,7 @@ pspy_objfile_for_address (PyObject *o, PyObject *args)
struct objfile *objf = self->pspace->objfile_for_address (addr);
if (objf == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return objfile_to_objfile_object (objf).release ();
}
@@ -518,12 +518,12 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
}
if (cust == NULL || cust->objfile () == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
if (block)
return block_to_block_object (block, cust->objfile ()).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of the find_pc_line function.
@@ -568,9 +568,9 @@ pspy_is_valid (PyObject *o, PyObject *args)
pspace_object *self = (pspace_object *) o;
if (self->pspace == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
\f
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 6026de91e67..5f1c93170c6 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -262,9 +262,9 @@ recpy_bt_insn_is_speculative (PyObject *self, void *closure)
return NULL;
if (insn->flags & BTRACE_INSN_FLAG_SPECULATIVE)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implementation of RecordInstruction.data [buffer] for btrace.
@@ -352,7 +352,7 @@ recpy_bt_func_symbol (PyObject *self, void *closure)
return NULL;
if (func->sym == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
return symbol_to_symbol_object (func->sym).release ();
}
@@ -392,7 +392,7 @@ recpy_bt_func_up (PyObject *self, void *closure)
return NULL;
if (func->up == 0)
- Py_RETURN_NONE;
+ return py_none ().release ();
return recpy_func_new (((recpy_element_object *) self)->thread,
RECORD_METHOD_BTRACE, func->up);
@@ -410,7 +410,7 @@ recpy_bt_func_prev (PyObject *self, void *closure)
return NULL;
if (func->prev == 0)
- Py_RETURN_NONE;
+ return py_none ().release ();
return recpy_func_new (((recpy_element_object *) self)->thread,
RECORD_METHOD_BTRACE, func->prev);
@@ -428,7 +428,7 @@ recpy_bt_func_next (PyObject *self, void *closure)
return NULL;
if (func->next == 0)
- Py_RETURN_NONE;
+ return py_none ().release ();
return recpy_func_new (((recpy_element_object *) self)->thread,
RECORD_METHOD_BTRACE, func->next);
@@ -634,9 +634,9 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
&& obj1->first == obj2->first
&& obj1->last == obj2->last
&& obj1->step == obj2->step)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
case Py_NE:
if (obj1->thread != obj2->thread
@@ -644,9 +644,9 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
|| obj1->first != obj2->first
|| obj1->last != obj2->last
|| obj1->step != obj2->step)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
default:
break;
@@ -676,12 +676,12 @@ recpy_bt_format (PyObject *self, void *closure)
const struct btrace_config * config;
if (tinfo == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
config = btrace_conf (&tinfo->btrace);
if (config == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
return PyUnicode_FromString (btrace_format_short_string (config->format));
}
@@ -696,10 +696,10 @@ recpy_bt_replay_position (PyObject *self, void *closure)
thread_info * tinfo = record->thread;
if (tinfo == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
if (tinfo->btrace.replay == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
return btpy_item_new (tinfo, btrace_insn_number (tinfo->btrace.replay));
}
@@ -715,12 +715,12 @@ recpy_bt_begin (PyObject *self, void *closure)
struct btrace_insn_iterator iterator;
if (tinfo == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_insn_begin (&iterator, &tinfo->btrace);
return btpy_item_new (tinfo, btrace_insn_number (&iterator));
@@ -737,12 +737,12 @@ recpy_bt_end (PyObject *self, void *closure)
struct btrace_insn_iterator iterator;
if (tinfo == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_insn_end (&iterator, &tinfo->btrace);
return btpy_item_new (tinfo, btrace_insn_number (&iterator));
@@ -761,12 +761,12 @@ recpy_bt_instruction_history (PyObject *self, void *closure)
unsigned long last = 0;
if (tinfo == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_insn_begin (&iterator, &tinfo->btrace);
first = btrace_insn_number (&iterator);
@@ -790,12 +790,12 @@ recpy_bt_function_call_history (PyObject *self, void *closure)
unsigned long last = 0;
if (tinfo == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return py_none ().release ();
btrace_call_begin (&iterator, &tinfo->btrace);
first = btrace_call_number (&iterator);
@@ -943,7 +943,7 @@ recpy_bt_goto (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of BtraceRecord.clear (self) -> None. */
@@ -956,7 +956,7 @@ recpy_bt_clear (PyObject *self, PyObject *args)
btrace_clear (tinfo);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* BtraceList methods. */
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index 294da0725e1..753826f88c4 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -427,17 +427,17 @@ recpy_element_richcompare (PyObject *self, PyObject *other, int op)
if (obj1->thread == obj2->thread
&& obj1->method == obj2->method
&& obj1->number == obj2->number)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
case Py_NE:
if (obj1->thread != obj2->thread
|| obj1->method != obj2->method
|| obj1->number != obj2->number)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
default:
break;
@@ -691,7 +691,7 @@ gdbpy_current_recording (PyObject *self, PyObject *args)
recpy_record_object *ret = NULL;
if (find_record_target () == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
ret = PyObject_New (recpy_record_object, &recpy_record_type);
if (ret == nullptr)
@@ -717,7 +717,7 @@ gdbpy_stop_recording (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_record);
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index c6e0748e935..14cf19a6e66 100644
--- a/gdb/python/py-registers.c
+++ b/gdb/python/py-registers.c
@@ -348,7 +348,7 @@ register_descriptor_iter_find (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_get_register_descriptor (gdbarch, regnum).release ();
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* See python-internal.h. */
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 6293b658ea1..bf803a3b487 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -84,7 +84,7 @@ sympy_get_symtab (PyObject *self, void *closure)
SYMPY_REQUIRE_VALID (self, symbol);
if (!symbol->is_objfile_owned ())
- Py_RETURN_NONE;
+ return py_none ().release ();
return symtab_to_symtab_object (symbol->symtab ()).release ();
}
@@ -224,8 +224,8 @@ sympy_needs_frame (PyObject *self, void *closure)
}
if (result)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Implementation of gdb.Symbol.line -> int.
@@ -251,9 +251,9 @@ sympy_is_valid (PyObject *self, PyObject *args)
symbol = symbol_object_to_symbol (self);
if (symbol == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implementation of gdb.Symbol.value (self[, frame]) -> gdb.Value. Returns
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index c5e18543740..f1fbfa58d65 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -146,7 +146,7 @@ stpy_get_producer (PyObject *self, void *closure)
return host_string_to_python_string (producer).release ();
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static PyObject *
@@ -172,9 +172,9 @@ stpy_is_valid (PyObject *self, PyObject *args)
symtab = symtab_object_to_symtab (self);
if (symtab == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Return the GLOBAL_BLOCK of the underlying symtab. */
@@ -247,7 +247,7 @@ stpy_source_lines (PyObject *self, PyObject *args, PyObject *kw)
std::optional<int> last_lineno = last_symtab_line (symtab);
if (!last_lineno.has_value ())
- Py_RETURN_NONE;
+ return py_none ().release ();
if (first < 1)
@@ -294,7 +294,7 @@ stpy_source_lines (PyObject *self, PyObject *args, PyObject *kw)
= make_scoped_restore (&source_styling, required_styling);
if (!g_source_cache.get_source_lines (symtab, first, last, &lines))
- Py_RETURN_NONE;
+ return py_none ().release ();
}
gdbpy_ref<> list (PyList_New (0));
@@ -387,7 +387,7 @@ salpy_get_last (PyObject *self, void *closure)
if (sal->end > 0)
return gdb_py_object_from_ulongest (sal->end - 1).release ();
else
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static PyObject *
@@ -408,7 +408,7 @@ salpy_get_symtab (PyObject *self, void *closure)
SALPY_REQUIRE_VALID (self, sal);
if (sal->symtab == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
else
return symtab_to_symtab_object (sal->symtab).release ();
}
@@ -423,9 +423,9 @@ salpy_is_valid (PyObject *self, PyObject *args)
sal = sal_object_to_symtab_and_line (self);
if (sal == NULL)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
static void
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index be19193770f..111e0f4c9e3 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -428,7 +428,7 @@ gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
\f
@@ -462,8 +462,8 @@ gdbpy_tui_is_valid (PyObject *self, PyObject *args)
gdbpy_tui_window *win = (gdbpy_tui_window *) self;
if (win->is_valid ())
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
/* Python function that erases the TUI window. */
@@ -476,7 +476,7 @@ gdbpy_tui_erase (PyObject *self, PyObject *args)
win->window->erase ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Python function that writes some text to a TUI window. */
@@ -497,7 +497,7 @@ gdbpy_tui_write (PyObject *self, PyObject *args, PyObject *kw)
win->window->output (text, full_window);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Return the width of the TUI window. */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 263d48a9365..89ff19cd759 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -349,7 +349,7 @@ typy_get_name (PyObject *self, void *closure)
struct type *type = ((type_object *) self)->type;
if (type->name () == NULL)
- Py_RETURN_NONE;
+ return py_none ().release ();
/* Ada type names are encoded, but it is better for users to see the
decoded form. */
if (ADA_TYPE_P (type))
@@ -374,7 +374,7 @@ typy_get_tag (PyObject *self, void *closure)
tagname = type->name ();
if (tagname == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return PyUnicode_FromString (tagname);
}
@@ -386,7 +386,7 @@ typy_get_objfile (PyObject *self, void *closure)
struct objfile *objfile = type->objfile_owner ();
if (objfile == nullptr)
- Py_RETURN_NONE;
+ return py_none ().release ();
return objfile_to_objfile_object (objfile).release ();
}
@@ -398,9 +398,9 @@ typy_is_scalar (PyObject *self, void *closure)
struct type *type = ((type_object *) self)->type;
if (is_scalar_type (type))
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Return true if this type is signed. Raises a ValueError if this type
@@ -419,9 +419,9 @@ typy_is_signed (PyObject *self, void *closure)
}
if (type->is_unsigned ())
- Py_RETURN_FALSE;
+ return py_false ().release ();
else
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Return true if this type is array-like. */
@@ -443,9 +443,9 @@ typy_is_array_like (PyObject *self, void *closure)
}
if (result)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Return true if this type is string-like. */
@@ -467,9 +467,9 @@ typy_is_string_like (PyObject *self, void *closure)
}
if (result)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Return the type, stripped of typedefs. */
@@ -777,7 +777,7 @@ typy_get_sizeof (PyObject *self, void *closure)
/* Ignore exceptions. */
if (size_varies)
- Py_RETURN_NONE;
+ return py_none ().release ();
return gdb_py_object_from_longest (type->length ()).release ();
}
@@ -819,8 +819,8 @@ typy_get_dynamic (PyObject *self, void *closure)
}
if (result)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
static struct type *
@@ -1140,8 +1140,8 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
}
if (op == (result ? Py_EQ : Py_NE))
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return py_true ().release ();
+ return py_false ().release ();
}
\f
@@ -1320,9 +1320,9 @@ typy_has_key (PyObject *self, PyObject *args)
const char *t_field_name = field.name ();
if (t_field_name && (strcmp_iw (t_field_name, field_name) == 0))
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Make an iterator object to iterate over keys, values, or items. */
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index dcf86f7db3d..6bff66849df 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -369,7 +369,7 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args, PyObject *kw)
here and True otherwise, but again that might require changes in
user code. So, handle this with minimal impact for the user, while
improving robustness: silently ignore the register/value pair. */
- Py_RETURN_NONE;
+ return py_none ().release ();
}
}
catch (const gdb_exception &except)
@@ -391,7 +391,7 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args, PyObject *kw)
if (!found)
unwind_info->saved_regs->emplace_back (regnum, std::move (new_value));
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* UnwindInfo cleanup. */
@@ -516,9 +516,9 @@ pending_framepy_is_valid (PyObject *self, PyObject *args)
pending_frame_object *pending_frame = (pending_frame_object *) self;
if (pending_frame->frame_info == nullptr)
- Py_RETURN_FALSE;
+ return py_false ().release ();
- Py_RETURN_TRUE;
+ return py_true ().release ();
}
/* Implement PendingFrame.name(). Return a string that is the name of the
@@ -549,7 +549,7 @@ pending_framepy_name (PyObject *self, PyObject *args)
return PyUnicode_Decode (name.get (), strlen (name.get ()),
host_charset (), nullptr);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement gdb.PendingFrame.pc(). Returns an integer containing the
@@ -693,7 +693,7 @@ pending_framepy_function (PyObject *self, PyObject *args)
if (sym != nullptr)
return symbol_to_symbol_object (sym).release ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index a5b2303728c..9443d0ed8c9 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -915,7 +915,7 @@ valpy_assign (PyObject *self_obj, PyObject *args)
if (!valpy_assign_core (self, val))
return nullptr;
- Py_RETURN_NONE;
+ return py_none ().release ();
}
static Py_ssize_t
@@ -1284,9 +1284,9 @@ valpy_get_is_optimized_out (PyObject *self, void *closure)
}
if (opt)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implements gdb.Value.is_unavailable. Return true if any part of the
@@ -1308,9 +1308,9 @@ valpy_get_is_unavailable (PyObject *self, void *closure)
}
if (!entirely_available)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implements gdb.Value.is_lazy. */
@@ -1330,9 +1330,9 @@ valpy_get_is_lazy (PyObject *self, void *closure)
}
if (opt)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Get gdb.Value.bytes attribute. */
@@ -1403,7 +1403,7 @@ valpy_fetch_lazy (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Calculate and return the address of the PyObject as the value of
@@ -1830,11 +1830,11 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
case Py_LT:
case Py_LE:
case Py_EQ:
- Py_RETURN_FALSE;
+ return py_false ().release ();
case Py_NE:
case Py_GT:
case Py_GE:
- Py_RETURN_TRUE;
+ return py_true ().release ();
default:
/* Can't happen. */
PyErr_SetString (PyExc_NotImplementedError,
@@ -1856,9 +1856,9 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
return NULL;
if (result == 1)
- Py_RETURN_TRUE;
+ return py_true ().release ();
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
/* Implements conversion to long. */
@@ -2186,7 +2186,7 @@ gdbpy_convenience_variable (PyObject *self, PyObject *args)
}
if (result == nullptr && !found)
- Py_RETURN_NONE;
+ return py_none ().release ();
return result.release ();
}
@@ -2231,7 +2231,7 @@ gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise. */
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index 24c8f48e1bd..673cf6e0769 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -94,7 +94,7 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
if (enabled == 0)
{
/* Return 'None' if the matcher is not enabled. */
- Py_RETURN_NONE;
+ return py_none ().release ();
}
gdbpy_ref<> match_method (PyObject_GetAttrString (matcher,
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 045626b70fd..4644d286855 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -522,9 +522,9 @@ gdbpy_parameter_value (const setting &var)
case var_boolean:
{
if (var.get<bool> ())
- Py_RETURN_TRUE;
+ return py_true ().release ();
else
- Py_RETURN_FALSE;
+ return py_false ().release ();
}
case var_auto_boolean:
@@ -532,11 +532,11 @@ gdbpy_parameter_value (const setting &var)
enum auto_boolean ab = var.get<enum auto_boolean> ();
if (ab == AUTO_BOOLEAN_TRUE)
- Py_RETURN_TRUE;
+ return py_true ().release ();
else if (ab == AUTO_BOOLEAN_FALSE)
- Py_RETURN_FALSE;
+ return py_false ().release ();
else
- Py_RETURN_NONE;
+ return py_none ().release ();
}
case var_uinteger:
@@ -562,7 +562,7 @@ gdbpy_parameter_value (const setting &var)
&& *l->val == -1)
value = -1;
else
- Py_RETURN_NONE;
+ return py_none ().release ();
}
else if (l->val.has_value ())
value = *l->val;
@@ -801,7 +801,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
if (to_string)
return PyUnicode_Decode (to_string_res.c_str (), to_string_res.size (),
host_charset (), nullptr);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implementation of Python rbreak command. Take a REGEX and
@@ -1106,7 +1106,7 @@ static PyObject *
gdbpy_invalidate_cached_frames (PyObject *self, PyObject *args)
{
reinit_frame_cache ();
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Read a file as Python code.
@@ -1195,7 +1195,7 @@ gdbpy_post_event (PyObject *self, PyObject *args)
gdbpy_event event (std::move (func_ref));
run_on_main_thread (event);
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Interrupt the current operation on the main thread. */
@@ -1219,7 +1219,7 @@ gdbpy_interrupt (PyObject *self, PyObject *args)
}
#endif
- Py_RETURN_NONE;
+ return py_none ().release ();
}
\f
@@ -1618,7 +1618,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* A python function to flush a gdb stream. The optional keyword
@@ -1654,7 +1654,7 @@ gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
gdb_flush (gdb_stdout);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Implement gdb.warning(). Takes a single text string argument and emit a
@@ -1688,7 +1688,7 @@ gdbpy_warning (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, ex);
}
- Py_RETURN_NONE;
+ return py_none ().release ();
}
/* Return non-zero if print-stack is not "none". */
@@ -1861,7 +1861,7 @@ static PyObject *
gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2)
{
if (! gdbpy_current_objfile)
- Py_RETURN_NONE;
+ return py_none ().release ();
return objfile_to_objfile_object (gdbpy_current_objfile).release ();
}
--
2.51.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 3/5] [gdb/python] Undefine Py_RETURN_{NONE, TRUE, FALSE, NOTIMPLEMENTED}
2026-05-15 13:58 [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions 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 ` 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
` (2 subsequent siblings)
4 siblings, 2 replies; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 13:58 UTC (permalink / raw)
To: gdb-patches
Now that we've removed all uses of Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED},
undefine them to enforce using the refcount-safe wrappers instead.
---
gdb/python/python-internal.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 7c58309e4d4..8e20ceefd85 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -1387,4 +1387,12 @@ py_notimplemented ()
return gdbpy_ref<> (f ());
}
+/* Undefine these to enforce using the refcount-safe wrappers py_none, py_true,
+ py_false and py_notimplemented. */
+
+#undef Py_RETURN_NONE
+#undef Py_RETURN_TRUE
+#undef Py_RETURN_FALSE
+#undef Py_RETURN_UNIMPLEMENTED
+
#endif /* GDB_PYTHON_PYTHON_INTERNAL_H */
--
2.51.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 4/5] [gdb/python] Use py_{none,false} more often
2026-05-15 13:58 [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions 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 13:58 ` 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:36 ` [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom Tromey
4 siblings, 1 reply; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 13:58 UTC (permalink / raw)
To: gdb-patches
Do:
...
$ sed -i \
"s/gdbpy_ref<>::new_reference (Py_False)/py_false ()/" \
gdb/python/*.{c,h}
...
Likewise for py_none.
---
gdb/python/py-cmd.c | 2 +-
gdb/python/py-connection.c | 2 +-
gdb/python/py-corefile.c | 4 ++--
gdb/python/py-frame.c | 4 ++--
gdb/python/py-inferior.c | 2 +-
gdb/python/py-prettyprint.c | 8 ++++----
gdb/python/py-record-btrace.c | 2 +-
gdb/python/py-symbol.c | 6 +++---
gdb/python/py-threadevent.c | 2 +-
gdb/python/py-type.c | 10 +++++-----
gdb/python/python.c | 4 ++--
11 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index bcb1ba37d93..c515446dad8 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -186,7 +186,7 @@ cmdpy_completer_helper (struct cmd_list_element *command,
if (word == NULL)
{
/* "brkchars" phase. */
- wordobj = gdbpy_ref<>::new_reference (Py_None);
+ wordobj = py_none ();
}
else
{
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index 2d0b2e94659..3f20e8876f9 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -74,7 +74,7 @@ gdbpy_ref<>
target_to_connection_object (process_stratum_target *target)
{
if (target == nullptr)
- return gdbpy_ref<>::new_reference (Py_None);
+ return py_none ();
gdbpy_ref <connection_object> conn_obj;
auto conn_obj_iter = all_connection_objects.find (target);
diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c
index 2c5596d093c..5acfd98d326 100644
--- a/gdb/python/py-corefile.c
+++ b/gdb/python/py-corefile.c
@@ -117,7 +117,7 @@ gdbpy_core_file_from_inferior (inferior *inf)
gdb_assert (inf->pspace != nullptr);
if (get_inferior_core_bfd (inf) == nullptr)
- return gdbpy_ref<>::new_reference (Py_None);
+ return py_none ();
PyObject *result = (PyObject *) cfpy_inferior_corefile_data_key.get (inf);
if (result != nullptr)
@@ -265,7 +265,7 @@ cfpy_mapped_files (PyObject *self, PyObject *args)
return nullptr;
}
else
- build_id = gdbpy_ref<>::new_reference (Py_None);
+ build_id = py_none ();
/* List to hold all the gdb.CorefileMappedFileRegion objects. */
gdbpy_ref<> regions (PyTuple_New (file.regions.size ()));
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 2a674ba52f8..068b6260af5 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -420,7 +420,7 @@ frapy_older (PyObject *self, PyObject *args)
if (prev)
prev_obj = frame_info_to_frame_object (prev);
else
- prev_obj = gdbpy_ref<>::new_reference (Py_None);
+ prev_obj = py_none ();
return prev_obj.release ();
}
@@ -449,7 +449,7 @@ frapy_newer (PyObject *self, PyObject *args)
if (next)
next_obj = frame_info_to_frame_object (next);
else
- next_obj = gdbpy_ref<>::new_reference (Py_None);
+ next_obj = py_none ();
return next_obj.release ();
}
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index d2fc159c227..426aec31e9e 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -1026,7 +1026,7 @@ python_context_changed (user_selected_what selection)
if (has_stack_frames ())
frame_obj = gdbpy_ref<> (gdbpy_selected_frame (nullptr, nullptr));
else
- frame_obj = gdbpy_ref<>::new_reference (Py_None);
+ frame_obj = py_none ();
if (frame_obj == nullptr)
{
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index a561196a2a9..72ad5efcf07 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -86,7 +86,7 @@ search_pp_list (PyObject *list, PyObject *value)
return printer;
}
- return gdbpy_ref<>::new_reference (Py_None);
+ return py_none ();
}
/* Subroutine of find_pretty_printer to simplify it.
@@ -151,11 +151,11 @@ find_pretty_printer_from_gdb (PyObject *value)
/* Fetch the global pretty printer list. */
if (gdb_python_module == NULL
|| ! PyObject_HasAttrString (gdb_python_module, "pretty_printers"))
- return gdbpy_ref<>::new_reference (Py_None);
+ return py_none ();
gdbpy_ref<> pp_list (PyObject_GetAttrString (gdb_python_module,
"pretty_printers"));
if (pp_list == NULL || ! PyList_Check (pp_list.get ()))
- return gdbpy_ref<>::new_reference (Py_None);
+ return py_none ();
return search_pp_list (pp_list.get (), value);
}
@@ -199,7 +199,7 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
try
{
if (!PyObject_HasAttr (printer, gdbpy_to_string_cst))
- result = gdbpy_ref<>::new_reference (Py_None);
+ result = py_none ();
else
{
result.reset (PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst,
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 5f1c93170c6..bacb172fec4 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -824,7 +824,7 @@ recpy_call_filter (const uint64_t payload, std::optional<uint64_t> ip,
gdbpy_ref<> py_ip;
if (!ip.has_value ())
- py_ip = gdbpy_ref<>::new_reference (Py_None);
+ py_ip = py_none ();
else
py_ip = gdb_py_object_from_ulongest (*ip);
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index bf803a3b487..224e5d90f26 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -450,7 +450,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
return nullptr;
}
else
- sym_obj = gdbpy_ref<>::new_reference (Py_None);
+ sym_obj = py_none ();
if (PyTuple_SetItem (ret_tuple.get (), 0, sym_obj.release ()) < 0)
return nullptr;
@@ -495,7 +495,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
return nullptr;
}
else
- sym_obj = gdbpy_ref<>::new_reference (Py_None);
+ sym_obj = py_none ();
return sym_obj.release ();
}
@@ -560,7 +560,7 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
return nullptr;
}
else
- sym_obj = gdbpy_ref<>::new_reference (Py_None);
+ sym_obj = py_none ();
return sym_obj.release ();
}
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index 13ce0d18daf..3c28aa1174a 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -33,7 +33,7 @@ py_get_event_thread (ptid_t ptid)
PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
return NULL;
}
- return gdbpy_ref<>::new_reference (Py_None);
+ return py_none ();
}
gdbpy_ref<>
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 89ff19cd759..775145a8135 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -147,7 +147,7 @@ convert_field (struct type *type, int field)
else
{
if (type->field (field).loc_is_dwarf_block ())
- arg = gdbpy_ref<>::new_reference (Py_None);
+ arg = py_none ();
else
arg = gdb_py_object_from_longest (type->field (field).loc_bitpos ());
attrstring = "bitpos";
@@ -173,7 +173,7 @@ convert_field (struct type *type, int field)
}
}
if (arg == NULL)
- arg = gdbpy_ref<>::new_reference (Py_None);
+ arg = py_none ();
if (PyObject_SetAttrString (result.get (), "name", arg.get ()) < 0)
return NULL;
@@ -185,7 +185,7 @@ convert_field (struct type *type, int field)
if (type->code () == TYPE_CODE_STRUCT)
arg.reset (PyBool_FromLong (field < TYPE_N_BASECLASSES (type)));
else
- arg = gdbpy_ref<>::new_reference (Py_False);
+ arg = py_false ();
if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0)
return NULL;
@@ -197,7 +197,7 @@ convert_field (struct type *type, int field)
/* A field can have a NULL type in some situations. */
if (type->field (field).type () == NULL)
- arg = gdbpy_ref<>::new_reference (Py_None);
+ arg = py_none ();
else
arg = type_to_type_object (type->field (field).type ());
if (arg == NULL)
@@ -219,7 +219,7 @@ field_name (struct type *type, int field)
if (type->field (field).name ())
result.reset (PyUnicode_FromString (type->field (field).name ()));
else
- result = gdbpy_ref<>::new_reference (Py_None);
+ result = py_none ();
return result;
}
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 4644d286855..fd254a340d8 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1030,7 +1030,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
}
}
else
- result = gdbpy_ref<>::new_reference (Py_None);
+ result = py_none ();
gdbpy_ref<> return_result (PyTuple_New (2));
if (return_result == NULL)
@@ -1043,7 +1043,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
return NULL;
}
else
- unparsed = gdbpy_ref<>::new_reference (Py_None);
+ unparsed = py_none ();
if (PyTuple_SetItem (return_result.get (), 0, unparsed.release ()) < 0
|| PyTuple_SetItem (return_result.get (), 1, result.release ()) < 0)
--
2.51.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 5/5] [gdb/python] Use py_{none,notimplemented} more often
2026-05-15 13:58 [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom de Vries
` (2 preceding siblings ...)
2026-05-15 13:58 ` [PATCH v3 4/5] [gdb/python] Use py_{none,false} more often Tom de Vries
@ 2026-05-15 13:58 ` Tom de Vries
2026-05-15 17:38 ` Tom Tromey
2026-05-15 17:36 ` [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom Tromey
4 siblings, 1 reply; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 13:58 UTC (permalink / raw)
To: gdb-patches
Replace:
...
{
Py_INCREF (Py_NotImplemented);
return Py_NotImplemented;
}
...
with:
...
return py_notimplemented ().release ();
...
Likewise for py_none.
---
gdb/python/py-block.c | 5 +----
gdb/python/py-connection.c | 3 +--
gdb/python/py-finishbreakpoint.c | 5 +----
gdb/python/py-frame.c | 8 ++------
gdb/python/py-lazy-string.c | 5 +----
gdb/python/py-record-btrace.c | 8 ++------
gdb/python/py-record.c | 8 ++------
gdb/python/py-symbol.c | 5 +----
gdb/python/py-type.c | 5 +----
gdb/python/py-value.c | 3 +--
10 files changed, 13 insertions(+), 42 deletions(-)
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index 17c9cbdaff0..6fe18e45564 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -550,10 +550,7 @@ blpy_richcompare (PyObject *self, PyObject *other, int op)
{
if (!PyObject_TypeCheck (other, &block_object_type)
|| (op != Py_EQ && op != Py_NE))
- {
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
- }
+ return py_notimplemented ().release ();
bool expected = self == other;
bool equal = op == Py_EQ;
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index 3f20e8876f9..43e03ad81f7 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -321,8 +321,7 @@ struct py_send_packet_callbacks : public send_remote_packet_callbacks
else
{
/* We didn't get back any result data; set the result to None. */
- Py_INCREF (Py_None);
- m_result.reset (Py_None);
+ m_result = py_none ();
}
}
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index f85f4fff766..49e12c00054 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -127,10 +127,7 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
gdbpy_print_stack ();
}
else
- {
- Py_INCREF (Py_None);
- self_finishbp->return_value = Py_None;
- }
+ self_finishbp->return_value = py_none ().release ();
}
catch (const gdb_exception &except)
{
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 068b6260af5..374b934a0d9 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -153,8 +153,7 @@ frapy_name (PyObject *self, PyObject *args)
}
else
{
- result = Py_None;
- Py_INCREF (Py_None);
+ result = py_none ().release ();
}
return result;
@@ -724,10 +723,7 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)
if (!PyObject_TypeCheck (other, &frame_object_type)
|| (op != Py_EQ && op != Py_NE))
- {
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
- }
+ return py_notimplemented ().release ();
frame_object *self_frame = (frame_object *) self;
frame_object *other_frame = (frame_object *) other;
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index fe191451e54..ba3920e07c3 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -72,10 +72,7 @@ stpy_get_encoding (PyObject *self, void *closure)
if (self_string->encoding)
result = PyUnicode_FromString (self_string->encoding);
else
- {
- result = Py_None;
- Py_INCREF (result);
- }
+ result = py_none ().release ();
return result;
}
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index bacb172fec4..f46b434313e 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -621,10 +621,7 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
const btpy_list_object * const obj2 = (btpy_list_object *) other;
if (Py_TYPE (self) != Py_TYPE (other))
- {
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
- }
+ return py_notimplemented ().release ();
switch (op)
{
@@ -652,8 +649,7 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
break;
}
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
+ return py_notimplemented ().release ();
}
/* Implementation of
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index 753826f88c4..3ceedecc165 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -416,10 +416,7 @@ recpy_element_richcompare (PyObject *self, PyObject *other, int op)
const recpy_element_object * const obj2 = (recpy_element_object *) other;
if (Py_TYPE (self) != Py_TYPE (other))
- {
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
- }
+ return py_notimplemented ().release ();
switch (op)
{
@@ -443,8 +440,7 @@ recpy_element_richcompare (PyObject *self, PyObject *other, int op)
break;
}
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
+ return py_notimplemented ().release ();
}
/* Create a new gdb.RecordGap object. */
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 224e5d90f26..76255f53f85 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -68,10 +68,7 @@ sympy_get_type (PyObject *self, void *closure)
SYMPY_REQUIRE_VALID (self, symbol);
if (symbol->type () == NULL)
- {
- Py_INCREF (Py_None);
- return Py_None;
- }
+ return py_none ().release ();
return type_to_type_object (symbol->type ()).release ();
}
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 775145a8135..cbb984309eb 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1118,10 +1118,7 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
/* We can only compare ourselves to another Type object, and only
for equality or inequality. */
if (type2 == NULL || (op != Py_EQ && op != Py_NE))
- {
- Py_INCREF (Py_NotImplemented);
- return Py_NotImplemented;
- }
+ return py_notimplemented ().release ();
if (type1 == type2)
result = true;
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 9443d0ed8c9..04b34758b90 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -416,8 +416,7 @@ valpy_get_address (PyObject *self, void *closure)
}
catch (const gdb_exception &except)
{
- val_obj->address = Py_None;
- Py_INCREF (Py_None);
+ val_obj->address = py_none ().release ();
}
}
--
2.51.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 3/5] [gdb/python] Undefine Py_RETURN_{NONE, TRUE, FALSE, NOTIMPLEMENTED}
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
1 sibling, 0 replies; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 14:05 UTC (permalink / raw)
To: gdb-patches
On 5/15/26 3:58 PM, Tom de Vries wrote:
> +#undef Py_RETURN_UNIMPLEMENTED
Review by an LLM (gemini pro 3.1) pointed out that this should be
Py_RETURN_NOTIMPLEMENTED.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions
2026-05-15 13:58 [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom de Vries
` (3 preceding siblings ...)
2026-05-15 13:58 ` [PATCH v3 5/5] [gdb/python] Use py_{none,notimplemented} " Tom de Vries
@ 2026-05-15 17:36 ` Tom Tromey
2026-05-15 17:44 ` Tom de Vries
4 siblings, 1 reply; 13+ messages in thread
From: Tom Tromey @ 2026-05-15 17:36 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 5/5] [gdb/python] Use py_{none,notimplemented} more often
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
0 siblings, 0 replies; 13+ messages in thread
From: Tom Tromey @ 2026-05-15 17:38 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> if (!PyObject_TypeCheck (other, &block_object_type)
Tom> || (op != Py_EQ && op != Py_NE))
Tom> - {
Tom> - Py_INCREF (Py_NotImplemented);
Tom> - return Py_NotImplemented;
Tom> - }
Tom> + return py_notimplemented ().release ();
Aha, I see now why you added py_notimplemented.
Sorry about that, I was reading the patches in order.
This is ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 4/5] [gdb/python] Use py_{none,false} more often
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
0 siblings, 0 replies; 13+ messages in thread
From: Tom Tromey @ 2026-05-15 17:39 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> Do:
Tom> ...
Tom> $ sed -i \
Tom> "s/gdbpy_ref<>::new_reference (Py_False)/py_false ()/" \
Tom> gdb/python/*.{c,h}
Tom> ...
Tom> Likewise for py_none.
Ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 3/5] [gdb/python] Undefine Py_RETURN_{NONE, TRUE, FALSE, NOTIMPLEMENTED}
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
1 sibling, 0 replies; 13+ messages in thread
From: Tom Tromey @ 2026-05-15 17:40 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> Now that we've removed all uses of Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED},
Tom> undefine them to enforce using the refcount-safe wrappers instead.
Tom> +/* Undefine these to enforce using the refcount-safe wrappers py_none, py_true,
Tom> + py_false and py_notimplemented. */
Tom> +
Tom> +#undef Py_RETURN_NONE
Tom> +#undef Py_RETURN_TRUE
Tom> +#undef Py_RETURN_FALSE
Tom> +#undef Py_RETURN_UNIMPLEMENTED
Ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions
2026-05-15 17:36 ` [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom Tromey
@ 2026-05-15 17:44 ` Tom de Vries
2026-05-15 18:36 ` Tom Tromey
0 siblings, 1 reply; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 17:44 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 5/15/26 7:36 PM, Tom Tromey wrote:
> 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.
Hi Tom,
I think the sentence is correct, and I still don't understand why you
think its incorrect.
What I'm trying to do here, is paraphrase the CPython implementation for
say Py_RETURN_None:
...
/* 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
...
AFAICT, I'm saying the exact same thing.
Is that not the case, or are you saying there's a bug in CPython?
Thanks,
- Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions
2026-05-15 17:44 ` Tom de Vries
@ 2026-05-15 18:36 ` Tom Tromey
2026-05-15 19:08 ` Tom de Vries
0 siblings, 1 reply; 13+ messages in thread
From: Tom Tromey @ 2026-05-15 18:36 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> On 5/15/26 7:36 PM, Tom Tromey wrote:
Tom> + So for the limited C API 3.12 and newer, we could just return a
Tom> + "PyObject *" instead.
Tom> I think the sentence is correct, and I still don't understand why you
Tom> think its incorrect.
It's not incorrect about the implementation of Python, but it posits
that in some situation these functions could return a PyObject*.
However such a change would not be good. For one thing these things are
useful in places that operate generically on gdbpy_ref<>. But for
another, gdb should treat CPython as a black box to the degree possible
and not try to avoid inc/dec-refs on immortal objects. Whether an
object is immortal is for CPython to manage.
Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions
2026-05-15 18:36 ` Tom Tromey
@ 2026-05-15 19:08 ` Tom de Vries
0 siblings, 0 replies; 13+ messages in thread
From: Tom de Vries @ 2026-05-15 19:08 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 5/15/26 8:36 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> On 5/15/26 7:36 PM, Tom Tromey wrote:
> Tom> + So for the limited C API 3.12 and newer, we could just return a
> Tom> + "PyObject *" instead.
>
> Tom> I think the sentence is correct, and I still don't understand why you
> Tom> think its incorrect.
>
> It's not incorrect about the implementation of Python, but it posits
> that in some situation these functions could return a PyObject*.
>
> However such a change would not be good. For one thing these things are
> useful in places that operate generically on gdbpy_ref<>. But for
> another, gdb should treat CPython as a black box to the degree possible
> and not try to avoid inc/dec-refs on immortal objects. Whether an
> object is immortal is for CPython to manage.
OK, understood.
I'll push this then with just this comment:
...
+/* The following four functions are refcount-safe wrappers around
+ Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED}. */
...
Thanks,
- Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-05-15 19:09 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-15 13:58 [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions 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 ` [PATCH v3 1/5] [gdb/python] Introduce py_{none, true, false, notimplemented} functions Tom Tromey
2026-05-15 17:44 ` Tom de Vries
2026-05-15 18:36 ` Tom Tromey
2026-05-15 19:08 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox