* [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE}
@ 2026-05-12 16:34 Tom de Vries
2026-05-12 16:34 ` [PATCH 1/2] [gdb/python] Add init_py_immortals Tom de Vries
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Tom de Vries @ 2026-05-12 16:34 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.
ISTM unnecessary to increase the reference count for each Py_RETURN_NONE use.
Instead, increase the reference count of Py_None once, and use a simple
"return Py_None" instead of Py_RETURN_NONE everywhere.
Tom de Vries (2):
[gdb/python] Add init_py_immortals
[gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE}
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 | 49 ++++++++++++++++++++---------
29 files changed, 241 insertions(+), 220 deletions(-)
base-commit: 2d7f2dbbd4adadf7c388fa0d8b9ce95d9dfde641
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] [gdb/python] Add init_py_immortals
2026-05-12 16:34 [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
@ 2026-05-12 16:34 ` Tom de Vries
2026-05-12 16:34 ` [PATCH 2/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
2026-05-13 14:44 ` [PATCH 0/2] " Tom Tromey
2 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-05-12 16:34 UTC (permalink / raw)
To: gdb-patches
Add and call init_py_immortals, allowing to use "return Py_None" instead of
Py_RETURN_NONE, and likewise for Py_RETURN_{TRUE,FALSE}.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34145
---
gdb/python/python.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 502fe682b2c..d4c3454bbee 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -2587,6 +2587,25 @@ py_initialize ()
#endif
}
+/* Increase the refcount for Py_None/Py_True/Py_False, if necessary. This
+ allows us to use a simple "return Py_None" instead of Py_RETURN_NONE
+ everywhere else. */
+
+static void
+init_py_immortals ()
+{
+ [[maybe_unused]] static PyObject *py_none = nullptr;
+ [[maybe_unused]] static PyObject *py_true = nullptr;
+ [[maybe_unused]] static PyObject *py_false = nullptr;
+
+ gdb_assert (py_none == nullptr);
+
+ /* Increase refcount for Py_None/Py_True/Py_False, if necessary. */
+ py_none = [] { Py_RETURN_NONE; } ();
+ py_true = [] { Py_RETURN_TRUE; } ();
+ py_false = [] { Py_RETURN_FALSE; } ();
+}
+
static bool
do_start_initialization ()
{
@@ -2606,6 +2625,8 @@ do_start_initialization ()
PyEval_InitThreads ();
#endif
+ init_py_immortals ();
+
gdb_module = PyImport_ImportModule ("_gdb");
if (gdb_module == NULL)
return false;
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE}
2026-05-12 16:34 [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
2026-05-12 16:34 ` [PATCH 1/2] [gdb/python] Add init_py_immortals Tom de Vries
@ 2026-05-12 16:34 ` Tom de Vries
2026-05-13 14:44 ` [PATCH 0/2] " Tom Tromey
2 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-05-12 16:34 UTC (permalink / raw)
To: gdb-patches
Result of:
...
$ sed -i 's/Py_RETURN_NONE/return Py_None/' gdb/python/*.{c,h}
...
with the change in init_py_immortals reverted.
Likewise for Py_RETURN_TRUE and Py_RETURN_FALSE.
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..73eedbca38e 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;
}
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;
}
/* 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;
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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* __repr__ implementation for gdb.Block. */
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index d96c67694b3..96873290579 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;
+ return Py_False;
}
/* 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;
if (self_bp->bp->enable_state == bp_enabled)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
+ return Py_True;
+ return Py_False;
}
/* 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;
+ return Py_False;
}
/* 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;
}
@@ -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;
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;
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;
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;
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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
if (pending_breakpoint_p (self_bp->bp))
- Py_RETURN_TRUE;
+ return Py_True;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
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;
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;
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;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
}
/* 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;
}
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;
}
/* 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..bb54deef4a4 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;
}
\f
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index a8bea4d832f..36791aca71e 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
}
/* Python specific initialization for this file. */
diff --git a/gdb/python/py-corefile.c b/gdb/python/py-corefile.c
index 0fa4e90488c..dd66a78e197 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
\f
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 1c5661dd307..c2dc31a206c 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
}
/* Implement DisassembleInfo.read_memory(LENGTH, OFFSET). Read LENGTH
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index 9d12d0161f1..ddc0d59d200 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;
}
/* 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;
if (PySequence_DelItem (callback_list, index) < 0)
return NULL;
- Py_RETURN_NONE;
+ return Py_None;
}
/* 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..c7890da37fa 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;
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..55e1c501437 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
}
/* 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;
}
/* 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;
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;
+ return Py_False;
}
/* 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..e388b98d1b2 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;
return NULL;
}
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 1a30f4ee378..1f016c5725b 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;
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;
+ return Py_False;
}
/* 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;
}
/* 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;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
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;
return host_string_to_python_string (name).release ();
}
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 672546e106d..659358e0417 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;
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;
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;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
}
static int
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 2afa9b033e7..183b8fb69d6 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;
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;
}
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_linetable);
diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c
index 27c79d60636..458d92190cb 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;
}
diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c
index 6edea04ccb5..029b5a5cbb8 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;
+ return Py_True;
}
/* 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..71c960c8710 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
}
/* 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;
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;
return symbol_to_symbol_object (sym).release ();
}
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 0cf0cde881c..06db50a71cc 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;
}
/* Subroutine of find_pretty_printer to simplify it.
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 37b92a64634..226dc201fdd 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;
}
/* 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;
}
/* 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;
}
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;
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;
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;
if (block)
return block_to_block_object (block, cust->objfile ()).release ();
- Py_RETURN_NONE;
+ return Py_None;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
\f
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 6026de91e67..9c3f06efc8e 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;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
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;
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;
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;
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;
else
- Py_RETURN_FALSE;
+ return Py_False;
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;
else
- Py_RETURN_FALSE;
+ return Py_False;
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;
config = btrace_conf (&tinfo->btrace);
if (config == NULL)
- Py_RETURN_NONE;
+ return Py_None;
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;
if (tinfo->btrace.replay == NULL)
- Py_RETURN_NONE;
+ return Py_None;
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;
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return Py_None;
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;
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return Py_None;
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;
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return Py_None;
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;
btrace_fetch (tinfo, record_btrace_get_cpu ());
if (btrace_is_empty (tinfo))
- Py_RETURN_NONE;
+ return Py_None;
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;
}
/* 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;
}
/* BtraceList methods. */
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index 294da0725e1..b048a8896f5 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;
else
- Py_RETURN_FALSE;
+ return Py_False;
case Py_NE:
if (obj1->thread != obj2->thread
|| obj1->method != obj2->method
|| obj1->number != obj2->number)
- Py_RETURN_TRUE;
+ return Py_True;
else
- Py_RETURN_FALSE;
+ return Py_False;
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;
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;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_record);
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index c6e0748e935..3dbb24df467 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;
}
/* See python-internal.h. */
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 6293b658ea1..e2d9849edaa 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;
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;
+ return Py_False;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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..46a937ba133 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;
}
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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
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;
}
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;
}
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;
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;
- Py_RETURN_TRUE;
+ return Py_True;
}
static void
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index be19193770f..c22302c7b87 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;
}
\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;
+ return Py_False;
}
/* 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;
}
/* 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;
}
/* Return the width of the TUI window. */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 263d48a9365..895cfd92b01 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;
/* 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;
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;
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;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
else
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
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;
+ return Py_False;
}
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;
+ return Py_False;
}
\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;
}
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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..74756cf121b 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;
}
}
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;
}
/* 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;
- Py_RETURN_TRUE;
+ return Py_True;
}
/* 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;
}
/* 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;
}
/* Implementation of
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index a5b2303728c..febd1d7d3ac 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;
}
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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
}
/* 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;
case Py_NE:
case Py_GT:
case Py_GE:
- Py_RETURN_TRUE;
+ return Py_True;
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;
- Py_RETURN_FALSE;
+ return Py_False;
}
/* 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;
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;
}
/* 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..e35ab88fb1f 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;
}
gdbpy_ref<> match_method (PyObject_GetAttrString (matcher,
diff --git a/gdb/python/python.c b/gdb/python/python.c
index d4c3454bbee..7fbe93401b7 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -521,9 +521,9 @@ gdbpy_parameter_value (const setting &var)
case var_boolean:
{
if (var.get<bool> ())
- Py_RETURN_TRUE;
+ return Py_True;
else
- Py_RETURN_FALSE;
+ return Py_False;
}
case var_auto_boolean:
@@ -531,11 +531,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;
else if (ab == AUTO_BOOLEAN_FALSE)
- Py_RETURN_FALSE;
+ return Py_False;
else
- Py_RETURN_NONE;
+ return Py_None;
}
case var_uinteger:
@@ -561,7 +561,7 @@ gdbpy_parameter_value (const setting &var)
&& *l->val == -1)
value = -1;
else
- Py_RETURN_NONE;
+ return Py_None;
}
else if (l->val.has_value ())
value = *l->val;
@@ -800,7 +800,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;
}
/* Implementation of Python rbreak command. Take a REGEX and
@@ -1105,7 +1105,7 @@ static PyObject *
gdbpy_invalidate_cached_frames (PyObject *self, PyObject *args)
{
reinit_frame_cache ();
- Py_RETURN_NONE;
+ return Py_None;
}
/* Read a file as Python code.
@@ -1194,7 +1194,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;
}
/* Interrupt the current operation on the main thread. */
@@ -1218,7 +1218,7 @@ gdbpy_interrupt (PyObject *self, PyObject *args)
}
#endif
- Py_RETURN_NONE;
+ return Py_None;
}
\f
@@ -1617,7 +1617,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- Py_RETURN_NONE;
+ return Py_None;
}
/* A python function to flush a gdb stream. The optional keyword
@@ -1653,7 +1653,7 @@ gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
gdb_flush (gdb_stdout);
}
- Py_RETURN_NONE;
+ return Py_None;
}
/* Implement gdb.warning(). Takes a single text string argument and emit a
@@ -1687,7 +1687,7 @@ gdbpy_warning (PyObject *self, PyObject *args, PyObject *kw)
return gdbpy_handle_gdb_exception (nullptr, ex);
}
- Py_RETURN_NONE;
+ return Py_None;
}
/* Return non-zero if print-stack is not "none". */
@@ -1860,7 +1860,7 @@ static PyObject *
gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2)
{
if (! gdbpy_current_objfile)
- Py_RETURN_NONE;
+ return Py_None;
return objfile_to_objfile_object (gdbpy_current_objfile).release ();
}
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE}
2026-05-12 16:34 [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
2026-05-12 16:34 ` [PATCH 1/2] [gdb/python] Add init_py_immortals Tom de Vries
2026-05-12 16:34 ` [PATCH 2/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
@ 2026-05-13 14:44 ` Tom Tromey
2026-05-13 16:42 ` Tom de Vries
2 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2026-05-13 14:44 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
Tom> The only point of it seems to be to increase the reference count on the
Tom> Py_None object for older python versions.
Tom> ISTM unnecessary to increase the reference count for each Py_RETURN_NONE use.
I mentioned this in the bug, but for the record on the list, I think
this patch will not work for versions of Python before the immortality
changes.
In particular if a gdb method returns a new reference, it means the
caller is free to decref the reference. However this series changes gdb
to assume that the decref will not happen for certain objects.
thanks,
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE}
2026-05-13 14:44 ` [PATCH 0/2] " Tom Tromey
@ 2026-05-13 16:42 ` Tom de Vries
0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-05-13 16:42 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 5/13/26 4:44 PM, Tom Tromey wrote:
> Tom> The only point of it seems to be to increase the reference count on the
> Tom> Py_None object for older python versions.
>
> Tom> ISTM unnecessary to increase the reference count for each Py_RETURN_NONE use.
>
> I mentioned this in the bug, but for the record on the list, I think
> this patch will not work for versions of Python before the immortality
> changes.
>
Hi Tom,
thank you for review comments.
I can confirm that this is the case. I ran into a test failures with
python 3.6, and managed to fix some of them by making gdbpy_ref aware of
None/True/False:
...
diff --git a/gdb/python/py-ref.h b/gdb/python/py-ref.h
index dc0b14814af..b2eb2811408 100644
--- a/gdb/python/py-ref.h
+++ b/gdb/python/py-ref.h
@@ -27,11 +27,19 @@ struct gdbpy_ref_policy
{
static void incref (PyObject *ptr)
{
+ if (ptr == Py_None
+ || ptr == Py_True
+ || ptr == Py_False)
+ return;
Py_INCREF (ptr);
}
static void decref (PyObject *ptr)
{
+ if (ptr == Py_None
+ || ptr == Py_True
+ || ptr == Py_False)
+ return;
Py_DECREF (ptr);
}
};
...
but a few test-cases still failed, AFAIU because of using Py_DECREF on
None/True/False.
I could have tried to fix this by replacing Py_DECREF et al by
gdb-specific overrides that handle None/True/False in the appropriate
way, but that would be way beyond the scope of what I was trying to achieve.
So instead, I've written a v2 that wraps Py_RETURN_{NONE,FALSE,TRUE} in
functions that return gdbpy_ref, and used those instead (
https://sourceware.org/pipermail/gdb-patches/2026-May/227374.html ).
Please let me know what you think about this approach.
Thanks,
- Tom
> In particular if a gdb method returns a new reference, it means the
> caller is free to decref the reference. However this series changes gdb
> to assume that the decref will not happen for certain objects.
>
> thanks,
> Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-13 16:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-12 16:34 [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
2026-05-12 16:34 ` [PATCH 1/2] [gdb/python] Add init_py_immortals Tom de Vries
2026-05-12 16:34 ` [PATCH 2/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
2026-05-13 14:44 ` [PATCH 0/2] " Tom Tromey
2026-05-13 16:42 ` 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