From: Tom de Vries Date: Fri, 15 May 2026 19:38:12 +0000 (+0200) Subject: [gdb/python] Use py_{none,notimplemented} more often X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=5cb6772600a90b7a214b84277fc795c5d45e98fa;p=thirdparty%2Fbinutils-gdb.git [gdb/python] Use py_{none,notimplemented} more often Replace: ... { Py_INCREF (Py_NotImplemented); return Py_NotImplemented; } ... with: ... return py_notimplemented ().release (); ... Likewise for py_none. Approved-By: Tom Tromey --- 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 (); } }