mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-05 23:26:51 +08:00
gdb/python: remove Python 2/3 compatibility macros
New in this version: - Rebase on master, fix a few more issues that appeared. python-internal.h contains a number of macros that helped make the code work with both Python 2 and 3. Remove them and adjust the code to use the Python 3 functions. Change-Id: I99a3d80067fb2d65de4f69f6473ba6ffd16efb2d
This commit is contained in:
@ -685,7 +685,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
|
||||
}
|
||||
|
||||
if (to_string)
|
||||
return PyString_FromString (to_string_res.c_str ());
|
||||
return PyUnicode_FromString (to_string_res.c_str ());
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
@ -931,7 +931,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
|
||||
|
||||
if (arg != NULL && strlen (arg) > 0)
|
||||
{
|
||||
unparsed.reset (PyString_FromString (arg));
|
||||
unparsed.reset (PyUnicode_FromString (arg));
|
||||
if (unparsed == NULL)
|
||||
return NULL;
|
||||
}
|
||||
@ -1093,7 +1093,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
|
||||
|
||||
if (PyCallable_Check (hook.get ()))
|
||||
{
|
||||
gdbpy_ref<> current_prompt (PyString_FromString (current_gdb_prompt));
|
||||
gdbpy_ref<> current_prompt (PyUnicode_FromString (current_gdb_prompt));
|
||||
if (current_prompt == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
@ -1112,7 +1112,7 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
|
||||
/* Return type should be None, or a String. If it is None,
|
||||
fall through, we will not set a prompt. If it is a
|
||||
string, set PROMPT. Anything else, set an exception. */
|
||||
if (result != Py_None && ! PyString_Check (result.get ()))
|
||||
if (result != Py_None && !PyUnicode_Check (result.get ()))
|
||||
{
|
||||
PyErr_Format (PyExc_RuntimeError,
|
||||
_("Return from prompt_hook must " \
|
||||
@ -1171,7 +1171,7 @@ gdbpy_colorize (const std::string &filename, const std::string &contents)
|
||||
if (!PyCallable_Check (hook.get ()))
|
||||
return {};
|
||||
|
||||
gdbpy_ref<> fname_arg (PyString_FromString (filename.c_str ()));
|
||||
gdbpy_ref<> fname_arg (PyUnicode_FromString (filename.c_str ()));
|
||||
if (fname_arg == nullptr)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
@ -1385,7 +1385,7 @@ gdbpy_format_address (PyObject *self, PyObject *args, PyObject *kw)
|
||||
/* Format the address, and return it as a string. */
|
||||
string_file buf;
|
||||
print_address (gdbarch, addr, &buf);
|
||||
return PyString_FromString (buf.c_str ());
|
||||
return PyUnicode_FromString (buf.c_str ());
|
||||
}
|
||||
|
||||
|
||||
@ -2081,22 +2081,22 @@ do_start_initialization ()
|
||||
#include "py-event-types.def"
|
||||
#undef GDB_PY_DEFINE_EVENT_TYPE
|
||||
|
||||
gdbpy_to_string_cst = PyString_FromString ("to_string");
|
||||
gdbpy_to_string_cst = PyUnicode_FromString ("to_string");
|
||||
if (gdbpy_to_string_cst == NULL)
|
||||
return false;
|
||||
gdbpy_children_cst = PyString_FromString ("children");
|
||||
gdbpy_children_cst = PyUnicode_FromString ("children");
|
||||
if (gdbpy_children_cst == NULL)
|
||||
return false;
|
||||
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
|
||||
gdbpy_display_hint_cst = PyUnicode_FromString ("display_hint");
|
||||
if (gdbpy_display_hint_cst == NULL)
|
||||
return false;
|
||||
gdbpy_doc_cst = PyString_FromString ("__doc__");
|
||||
gdbpy_doc_cst = PyUnicode_FromString ("__doc__");
|
||||
if (gdbpy_doc_cst == NULL)
|
||||
return false;
|
||||
gdbpy_enabled_cst = PyString_FromString ("enabled");
|
||||
gdbpy_enabled_cst = PyUnicode_FromString ("enabled");
|
||||
if (gdbpy_enabled_cst == NULL)
|
||||
return false;
|
||||
gdbpy_value_cst = PyString_FromString ("value");
|
||||
gdbpy_value_cst = PyUnicode_FromString ("value");
|
||||
if (gdbpy_value_cst == NULL)
|
||||
return false;
|
||||
|
||||
@ -2311,7 +2311,7 @@ do_initialize (const struct extension_language_defn *extlang)
|
||||
}
|
||||
if (sys_path && PyList_Check (sys_path))
|
||||
{
|
||||
gdbpy_ref<> pythondir (PyString_FromString (gdb_pythondir.c_str ()));
|
||||
gdbpy_ref<> pythondir (PyUnicode_FromString (gdb_pythondir.c_str ()));
|
||||
if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ()))
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user