From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 5/5] [gdb/python] Use py_{none,notimplemented} more often
Date: Fri, 15 May 2026 15:58:34 +0200 [thread overview]
Message-ID: <20260515135834.2502165-5-tdevries@suse.de> (raw)
In-Reply-To: <20260515135834.2502165-1-tdevries@suse.de>
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
next prev parent reply other threads:[~2026-05-15 13:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Tom de Vries [this message]
2026-05-15 17:38 ` [PATCH v3 5/5] [gdb/python] Use py_{none,notimplemented} " 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260515135834.2502165-5-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox