Don't use gdb_py_long_from_ulongest
authorTom Tromey <tromey@adacore.com>
Tue, 15 Sep 2020 17:08:56 +0000 (11:08 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 15 Sep 2020 17:08:56 +0000 (11:08 -0600)
Remove the gdb_py_long_from_ulongest defines and change the Python
layer to prefer gdb_py_object_from_ulongest.  While writing this I
noticed that the error handling in archpy_disassemble was incorrect --
it could call PyDict_SetItemString with a NULL value.  This patch also
fixes this bug.

gdb/ChangeLog
2020-09-15  Tom Tromey  <tromey@adacore.com>

* python/python-internal.h (gdb_py_long_from_ulongest): Remove
defines.
* python/py-value.c (valpy_long): Use
gdb_py_object_from_ulongest.
* python/py-symtab.c (salpy_get_pc): Use
gdb_py_object_from_ulongest.
(salpy_get_last): Likewise.
* python/py-record-btrace.c (recpy_bt_insn_pc): Use
gdb_py_object_from_ulongest.
* python/py-lazy-string.c (stpy_get_address): Use
gdb_py_object_from_ulongest.
* python/py-frame.c (frapy_pc): Use gdb_py_object_from_ulongest.
* python/py-arch.c (archpy_disassemble): Use
gdb_py_object_from_ulongest and gdb_py_object_from_longest.  Fix
error handling.

gdb/ChangeLog
gdb/python/py-arch.c
gdb/python/py-frame.c
gdb/python/py-lazy-string.c
gdb/python/py-record-btrace.c
gdb/python/py-symtab.c
gdb/python/py-value.c
gdb/python/python-internal.h

index 6df6633b00ab0d6a3f171d965e2648f9be69a47b..504a916314f6adbf060c905dca8f298379bc61cd 100644 (file)
@@ -1,3 +1,21 @@
+2020-09-15  Tom Tromey  <tromey@adacore.com>
+
+       * python/python-internal.h (gdb_py_long_from_ulongest): Remove
+       defines.
+       * python/py-value.c (valpy_long): Use
+       gdb_py_object_from_ulongest.
+       * python/py-symtab.c (salpy_get_pc): Use
+       gdb_py_object_from_ulongest.
+       (salpy_get_last): Likewise.
+       * python/py-record-btrace.c (recpy_bt_insn_pc): Use
+       gdb_py_object_from_ulongest.
+       * python/py-lazy-string.c (stpy_get_address): Use
+       gdb_py_object_from_ulongest.
+       * python/py-frame.c (frapy_pc): Use gdb_py_object_from_ulongest.
+       * python/py-arch.c (archpy_disassemble): Use
+       gdb_py_object_from_ulongest and gdb_py_object_from_longest.  Fix
+       error handling.
+
 2020-09-15  Tom Tromey  <tromey@adacore.com>
 
        * python/python-internal.h (gdb_py_long_from_longest): Remove
index d9eaf81a30a76f57abd69586607eef3916a587f9..3f8e769ff59ee8e61bf19d4d06b40d3b2aa5cbb8 100644 (file)
@@ -209,14 +209,23 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
          return NULL;
         }
 
-      if (PyDict_SetItemString (insn_dict.get (), "addr",
-                                gdb_py_long_from_ulongest (pc))
-          || PyDict_SetItemString (insn_dict.get (), "asm",
-                                   PyString_FromString (!stb.empty ()
-                                                       ? stb.c_str ()
-                                                       : "<unknown>"))
-          || PyDict_SetItemString (insn_dict.get (), "length",
-                                   PyInt_FromLong (insn_len)))
+      gdbpy_ref<> pc_obj = gdb_py_object_from_ulongest (pc);
+      if (pc_obj == nullptr)
+       return nullptr;
+
+      gdbpy_ref<> asm_obj (PyString_FromString (!stb.empty ()
+                                               ? stb.c_str ()
+                                               : "<unknown>"));
+      if (asm_obj == nullptr)
+       return nullptr;
+
+      gdbpy_ref<> len_obj = gdb_py_object_from_longest (insn_len);
+      if (len_obj == nullptr)
+       return nullptr;
+
+      if (PyDict_SetItemString (insn_dict.get (), "addr", pc_obj.get ())
+          || PyDict_SetItemString (insn_dict.get (), "asm", asm_obj.get ())
+          || PyDict_SetItemString (insn_dict.get (), "length", len_obj.get ()))
        return NULL;
 
       pc += insn_len;
index e121afb222da46092eb9d7652458d69a5f19817f..090705507e6560187d227a990bf6ab175cd468c4 100644 (file)
@@ -232,7 +232,7 @@ frapy_pc (PyObject *self, PyObject *args)
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  return gdb_py_long_from_ulongest (pc);
+  return gdb_py_object_from_ulongest (pc).release ();
 }
 
 /* Implementation of gdb.Frame.read_register (self, register) -> gdb.Value.
index f71bb1d613dcdbebcd378b12bc4d929480ebdfba..401c0a6fdf5fe495c5296c932fed717fbcb477ae 100644 (file)
@@ -61,7 +61,7 @@ stpy_get_address (PyObject *self, void *closure)
 {
   lazy_string_object *self_string = (lazy_string_object *) self;
 
-  return gdb_py_long_from_ulongest (self_string->address);
+  return gdb_py_object_from_ulongest (self_string->address).release ();
 }
 
 static PyObject *
index 84a3d9eae73caf2ecb40318619283ba289526f94..762c0bcbcc00dfaac51c44a7beec3a3b60b2344f 100644 (file)
@@ -232,7 +232,7 @@ recpy_bt_insn_pc (PyObject *self, void *closure)
   if (insn == NULL)
     return NULL;
 
-  return gdb_py_long_from_ulongest (insn->pc);
+  return gdb_py_object_from_ulongest (insn->pc).release ();
 }
 
 /* Implementation of RecordInstruction.size [int] for btrace.
index 6229bc5123b963912d5d02a9377dbe815983fecf..b0e7618af7ed58e67766d9ec05c4aacf9406e2fb 100644 (file)
@@ -264,7 +264,7 @@ salpy_get_pc (PyObject *self, void *closure)
 
   SALPY_REQUIRE_VALID (self, sal);
 
-  return gdb_py_long_from_ulongest (sal->pc);
+  return gdb_py_object_from_ulongest (sal->pc).release ();
 }
 
 /* Implementation of the get method for the 'last' attribute of
@@ -278,7 +278,7 @@ salpy_get_last (PyObject *self, void *closure)
   SALPY_REQUIRE_VALID (self, sal);
 
   if (sal->end > 0)
-    return gdb_py_long_from_ulongest (sal->end - 1);
+    return gdb_py_object_from_ulongest (sal->end - 1).release ();
   else
     Py_RETURN_NONE;
 }
index 504a9de9cee363264285e46a0eff0392a5a21b48..bb88bf358908d1636f2d46b3c112574ebb61078c 100644 (file)
@@ -1731,7 +1731,7 @@ valpy_long (PyObject *self)
     }
 
   if (type->is_unsigned ())
-    return gdb_py_long_from_ulongest (l);
+    return gdb_py_object_from_ulongest (l).release ();
   else
     return gdb_py_object_from_longest (l).release ();
 }
index b93c78fd6e1d52f14f0ba85d9b5765e3e9d2fb62..2c4195f3d03e7f9fe31177977e281b95466690d2 100644 (file)
 #define GDB_PY_LLU_ARG "K"
 typedef PY_LONG_LONG gdb_py_longest;
 typedef unsigned PY_LONG_LONG gdb_py_ulongest;
-#define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong
 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
 
 #else /* HAVE_LONG_LONG */
@@ -135,7 +134,6 @@ typedef unsigned PY_LONG_LONG gdb_py_ulongest;
 #define GDB_PY_LLU_ARG "K"
 typedef long gdb_py_longest;
 typedef unsigned long gdb_py_ulongest;
-#define gdb_py_long_from_ulongest PyLong_FromUnsignedLong
 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
 
 #endif /* HAVE_LONG_LONG */
This page took 0.035007 seconds and 4 git commands to generate.