[binutils-gdb] Don't use PyLong_FromLong

Tom Tromey tromey@sourceware.org
Tue Sep 15 17:13:21 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=062534d44f3eeb81903cc01ef0230cee5b3e4eb2

commit 062534d44f3eeb81903cc01ef0230cee5b3e4eb2
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Sep 15 11:08:56 2020 -0600

    Don't use PyLong_FromLong
    
    This changes gdb to avoid PyLong_FromLong, preferring to
    gdb_py_object_from_longest instead.
    
    gdb/ChangeLog
    2020-09-15  Tom Tromey  <tromey@adacore.com>
    
            * python/python.c (gdbpy_parameter_value): Use
            gdb_py_object_from_longest.
            * python/py-type.c (convert_field, typy_range): Use
            gdb_py_object_from_longest.
            * python/py-tui.c (gdbpy_tui_width, gdbpy_tui_height): Use
            gdb_py_object_from_longest.
            * python/py-lazy-string.c (stpy_get_length): Use
            gdb_py_object_from_longest.
            * python/py-infthread.c (thpy_get_num, thpy_get_global_num): Use
            gdb_py_object_from_longest.
            * python/py-infevents.c (create_memory_changed_event_object): Use
            gdb_py_object_from_longest.
            * python/py-inferior.c (infpy_get_num): Use
            gdb_py_object_from_longest.
            (infpy_get_pid): Likewise.

Diff:
---
 gdb/ChangeLog               | 18 ++++++++++++++++++
 gdb/python/py-inferior.c    |  4 ++--
 gdb/python/py-infevents.c   |  2 +-
 gdb/python/py-infthread.c   |  8 ++++++--
 gdb/python/py-lazy-string.c |  2 +-
 gdb/python/py-tui.c         |  8 ++++++--
 gdb/python/py-type.c        |  6 +++---
 gdb/python/python.c         |  2 +-
 8 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 504a916314f..eed367a49ac 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,21 @@
+2020-09-15  Tom Tromey  <tromey@adacore.com>
+
+	* python/python.c (gdbpy_parameter_value): Use
+	gdb_py_object_from_longest.
+	* python/py-type.c (convert_field, typy_range): Use
+	gdb_py_object_from_longest.
+	* python/py-tui.c (gdbpy_tui_width, gdbpy_tui_height): Use
+	gdb_py_object_from_longest.
+	* python/py-lazy-string.c (stpy_get_length): Use
+	gdb_py_object_from_longest.
+	* python/py-infthread.c (thpy_get_num, thpy_get_global_num): Use
+	gdb_py_object_from_longest.
+	* python/py-infevents.c (create_memory_changed_event_object): Use
+	gdb_py_object_from_longest.
+	* python/py-inferior.c (infpy_get_num): Use
+	gdb_py_object_from_longest.
+	(infpy_get_pid): Likewise.
+
 2020-09-15  Tom Tromey  <tromey@adacore.com>
 
 	* python/python-internal.h (gdb_py_long_from_ulongest): Remove
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index a7699510db7..7204356ac73 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -423,7 +423,7 @@ infpy_get_num (PyObject *self, void *closure)
 
   INFPY_REQUIRE_VALID (inf);
 
-  return PyLong_FromLong (inf->inferior->num);
+  return gdb_py_object_from_longest (inf->inferior->num).release ();
 }
 
 static PyObject *
@@ -433,7 +433,7 @@ infpy_get_pid (PyObject *self, void *closure)
 
   INFPY_REQUIRE_VALID (inf);
 
-  return PyLong_FromLong (inf->inferior->pid);
+  return gdb_py_object_from_longest (inf->inferior->pid).release ();
 }
 
 static PyObject *
diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c
index 3cf746103c7..f303c395c13 100644
--- a/gdb/python/py-infevents.c
+++ b/gdb/python/py-infevents.c
@@ -104,7 +104,7 @@ create_memory_changed_event_object (CORE_ADDR addr, ssize_t len)
   if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0)
     return NULL;
 
-  gdbpy_ref<> len_obj (PyLong_FromLong (len));
+  gdbpy_ref<> len_obj = gdb_py_object_from_longest (len);
   if (len_obj == NULL)
     return NULL;
 
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index f350e367d5e..669b6d8b074 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -130,7 +130,9 @@ thpy_get_num (PyObject *self, void *closure)
 
   THPY_REQUIRE_VALID (thread_obj);
 
-  return PyLong_FromLong (thread_obj->thread->per_inf_num);
+  gdbpy_ref<> result
+    = gdb_py_object_from_longest (thread_obj->thread->per_inf_num);
+  return result.release ();
 }
 
 /* Getter for InferiorThread.global_num.  */
@@ -142,7 +144,9 @@ thpy_get_global_num (PyObject *self, void *closure)
 
   THPY_REQUIRE_VALID (thread_obj);
 
-  return PyLong_FromLong (thread_obj->thread->global_num);
+  gdbpy_ref<> result
+    = gdb_py_object_from_longest (thread_obj->thread->global_num);
+  return result.release ();
 }
 
 /* Getter for InferiorThread.ptid  -> (pid, lwp, tid).
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 401c0a6fdf5..aaee94f5e1f 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -88,7 +88,7 @@ stpy_get_length (PyObject *self, void *closure)
 {
   lazy_string_object *self_string = (lazy_string_object *) self;
 
-  return PyLong_FromLong (self_string->length);
+  return gdb_py_object_from_longest (self_string->length).release ();
 }
 
 static PyObject *
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 95c71f1d2dd..8a24f2f3af4 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -392,7 +392,9 @@ gdbpy_tui_width (PyObject *self, void *closure)
 {
   gdbpy_tui_window *win = (gdbpy_tui_window *) self;
   REQUIRE_WINDOW (win);
-  return PyLong_FromLong (win->window->viewport_width ());
+  gdbpy_ref<> result
+    = gdb_py_object_from_longest (win->window->viewport_width ());
+  return result.release ();
 }
 
 /* Return the height of the TUI window.  */
@@ -401,7 +403,9 @@ gdbpy_tui_height (PyObject *self, void *closure)
 {
   gdbpy_tui_window *win = (gdbpy_tui_window *) self;
   REQUIRE_WINDOW (win);
-  return PyLong_FromLong (win->window->viewport_height ());
+  gdbpy_ref<> result
+    = gdb_py_object_from_longest (win->window->viewport_height ());
+  return result.release ();
 }
 
 /* Return the title of the TUI window.  */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 229fde37efe..d487a392b11 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -233,7 +233,7 @@ convert_field (struct type *type, int field)
   if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0)
     return NULL;
 
-  arg.reset (PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field)));
+  arg = gdb_py_object_from_longest (TYPE_FIELD_BITSIZE (type, field));
   if (arg == NULL)
     return NULL;
   if (PyObject_SetAttrString (result.get (), "bitsize", arg.get ()) < 0)
@@ -596,11 +596,11 @@ typy_range (PyObject *self, PyObject *args)
       break;
     }
 
-  gdbpy_ref<> low_bound (PyLong_FromLong (low));
+  gdbpy_ref<> low_bound = gdb_py_object_from_longest (low);
   if (low_bound == NULL)
     return NULL;
 
-  gdbpy_ref<> high_bound (PyLong_FromLong (high));
+  gdbpy_ref<> high_bound = gdb_py_object_from_longest (high);
   if (high_bound == NULL)
     return NULL;
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 7787dce4b4c..9cc8af63338 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -496,7 +496,7 @@ gdbpy_parameter_value (enum var_types type, void *var)
       /* Fall through.  */
     case var_zinteger:
     case var_zuinteger_unlimited:
-      return PyLong_FromLong (* (int *) var);
+      return gdb_py_object_from_longest (* (int *) var).release ();
 
     case var_uinteger:
       {


More information about the Gdb-cvs mailing list