]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use PyBool_FromLong
authorTom Tromey <tromey@adacore.com>
Tue, 7 Jun 2022 15:15:24 +0000 (09:15 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 23 Jun 2022 15:27:30 +0000 (09:27 -0600)
I noticed a few spots that were explicitly creating new references to
Py_True or Py_False.  It's simpler here to use PyBool_FromLong, so
this patch changes all the places I found.

gdb/python/py-cmd.c
gdb/python/py-symbol.c
gdb/python/py-type.c

index f80318374d394993857b241e92fdca1bec8fbf59..5cc392af175651c49c6e47079b4dea402772f599 100644 (file)
@@ -128,8 +128,7 @@ cmdpy_function (const char *args, int from_tty, cmd_list_element *command)
       error (_("Could not convert arguments to Python string."));
     }
 
-  gdbpy_ref<> ttyobj
-    = gdbpy_ref<>::new_reference (from_tty ? Py_True : Py_False);
+  gdbpy_ref<> ttyobj (PyBool_FromLong (from_tty));
   gdbpy_ref<> result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst,
                                                  argobj.get (), ttyobj.get (),
                                                  NULL));
index 02c35acd1e93af4a1f7622951847d80028b3a469..23495b66d422352a8c15eac7bda131ad69e65261 100644 (file)
@@ -426,8 +426,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
     }
   PyTuple_SET_ITEM (ret_tuple.get (), 0, sym_obj);
 
-  bool_obj = (is_a_field_of_this.type != NULL) ? Py_True : Py_False;
-  Py_INCREF (bool_obj);
+  bool_obj = PyBool_FromLong (is_a_field_of_this.type != NULL);
   PyTuple_SET_ITEM (ret_tuple.get (), 1, bool_obj);
 
   return ret_tuple.release ();
index 5352ead84bdd94a48703cac443b3a39155454e13..0e772ad44b4a9d397ae8465bb4cafe613885ede9 100644 (file)
@@ -220,14 +220,12 @@ convert_field (struct type *type, int field)
   if (PyObject_SetAttrString (result.get (), "name", arg.get ()) < 0)
     return NULL;
 
-  arg = gdbpy_ref<>::new_reference (TYPE_FIELD_ARTIFICIAL (type, field)
-                                   ? Py_True : Py_False);
+  arg.reset (PyBool_FromLong (TYPE_FIELD_ARTIFICIAL (type, field)));
   if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0)
     return NULL;
 
   if (type->code () == TYPE_CODE_STRUCT)
-    arg = gdbpy_ref<>::new_reference (field < TYPE_N_BASECLASSES (type)
-                                     ? Py_True : Py_False);
+    arg.reset (PyBool_FromLong (field < TYPE_N_BASECLASSES (type)));
   else
     arg = gdbpy_ref<>::new_reference (Py_False);
   if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0)