Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 4/5] [gdb/python] Use py_{none,false} more often
Date: Fri, 15 May 2026 15:58:33 +0200	[thread overview]
Message-ID: <20260515135834.2502165-4-tdevries@suse.de> (raw)
In-Reply-To: <20260515135834.2502165-1-tdevries@suse.de>

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


  parent reply	other threads:[~2026-05-15 14:01 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 ` Tom de Vries [this message]
2026-05-15 17:39   ` [PATCH v3 4/5] [gdb/python] Use py_{none,false} more often 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

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-4-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