diff options
Diffstat (limited to 'gdb/python/py-arch.c')
-rw-r--r-- | gdb/python/py-arch.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 0f273b344e4..d8098a2d161 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -62,16 +62,25 @@ arch_object_data_init (struct gdbarch *gdbarch) } /* Returns the struct gdbarch value corresponding to the given Python - architecture object OBJ. */ + architecture object OBJ, which must be a gdb.Architecture object. */ struct gdbarch * arch_object_to_gdbarch (PyObject *obj) { - arch_object *py_arch = (arch_object *) obj; + gdb_assert (gdbpy_is_architecture (obj)); + arch_object *py_arch = (arch_object *) obj; return py_arch->gdbarch; } +/* See python-internal.h. */ + +bool +gdbpy_is_architecture (PyObject *obj) +{ + return PyObject_TypeCheck (obj, &arch_object_type); +} + /* Returns the Python architecture object corresponding to GDBARCH. Returns a new reference to the arch_object associated as data with GDBARCH. */ @@ -100,7 +109,7 @@ archpy_name (PyObject *self, PyObject *args) ARCHPY_REQUIRE_VALID (self, gdbarch); name = (gdbarch_bfd_arch_info (gdbarch))->printable_name; - return PyString_FromString (name); + return PyUnicode_FromString (name); } /* Implementation of @@ -139,12 +148,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) conversion process. */ if (PyLong_Check (end_obj)) end = PyLong_AsUnsignedLongLong (end_obj); -#if PY_MAJOR_VERSION == 2 - else if (PyInt_Check (end_obj)) - /* If the end_pc value is specified without a trailing 'L', end_obj will - be an integer and not a long integer. */ - end = PyInt_AsLong (end_obj); -#endif else { PyErr_SetString (PyExc_TypeError, @@ -164,7 +167,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) } if (count_obj) { - count = PyInt_AsLong (count_obj); + count = PyLong_AsLong (count_obj); if (PyErr_Occurred () || count < 0) { PyErr_SetString (PyExc_TypeError, @@ -213,9 +216,8 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) if (pc_obj == nullptr) return nullptr; - gdbpy_ref<> asm_obj (PyString_FromString (!stb.empty () - ? stb.c_str () - : "<unknown>")); + gdbpy_ref<> asm_obj + (PyUnicode_FromString (!stb.empty () ? stb.c_str () : "<unknown>")); if (asm_obj == nullptr) return nullptr; @@ -338,7 +340,7 @@ gdbpy_all_architecture_names (PyObject *self, PyObject *args) std::vector<const char *> name_list = gdbarch_printable_names (); for (const char *name : name_list) { - gdbpy_ref <> py_name (PyString_FromString (name)); + gdbpy_ref <> py_name (PyUnicode_FromString (name)); if (py_name == nullptr) return nullptr; if (PyList_Append (list.get (), py_name.get ()) < 0) |