[binutils-gdb] gdb/python: move PyLong_From* calls into py-utils.c

Andrew Burgess aburgess@sourceware.org
Mon Jun 21 19:40:11 GMT 2021


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

commit 8b9c48b287d42d1c816f441e4273dcb8c7af1876
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Wed May 26 21:28:11 2021 +0100

    gdb/python: move PyLong_From* calls into py-utils.c
    
    We already have two helper functions in py-utils.c:
    
      gdb_py_object_from_longest (LONGEST l)
      gdb_py_object_from_ulongest (ULONGEST l)
    
    these wrap around calls to either PyLong_FromLongLong,
    PyLong_FromLong, or PyInt_From_Long (if Python 2 is being used).
    
    There is one place in gdb/python/* where a call to PyLong_FromLong was
    added outside of the above utility functions, this was done in the
    recent commit:
    
      commit 55789354fcbaf879f3ca8475b647b2747dec486e
      Date:   Fri May 14 11:56:31 2021 +0200
    
          gdb/python: add a 'connection_num' attribute to Inferior objects
    
    In this commit I replace the direct use of PyLong_FromLong with a call
    to gdb_py_object_from_longest.  The only real change with this commit,
    is that, for Python 2, we will now end up calling PyInt_FromLong
    instead of PyLong_FromLong, but this should be invisible to the user.
    For Python 3 there should be absolutely no change.
    
    gdb/ChangeLog:
    
            * python/py-inferior.c (infpy_get_connection_num): Call
            gdb_py_object_from_longest instead of PyLong_FromLong directly.

Diff:
---
 gdb/ChangeLog            | 5 +++++
 gdb/python/py-inferior.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a221a841e0a..24aeaa41639 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-06-21  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* python/py-inferior.c (infpy_get_connection_num): Call
+	gdb_py_object_from_longest instead of PyLong_FromLong directly.
+
 2021-06-21  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* python/py-unwind.c (unwind_infopy_add_saved_register): Handle
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 336c6426b8c..39efa804d80 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -441,7 +441,7 @@ infpy_get_connection_num (PyObject *self, void *closure)
   if (target == nullptr)
     Py_RETURN_NONE;
 
-  return PyLong_FromLong (target->connection_number);
+  return gdb_py_object_from_longest (target->connection_number).release ();
 }
 
 static PyObject *


More information about the Gdb-cvs mailing list