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:
Simon Marchi 2022-03-21 10:07:41 -04:00
parent edae3fd660
commit 5aee458796
25 changed files with 93 additions and 116 deletions

View file

@ -125,7 +125,7 @@ static PyObject *show_doc_cst;
static PyObject *
get_attr (PyObject *obj, PyObject *attr_name)
{
if (PyString_Check (attr_name)
if (PyUnicode_Check (attr_name)
&& ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
{
parmpy_object *self = (parmpy_object *) obj;
@ -243,7 +243,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
long l;
int ok;
if (! PyInt_Check (value))
if (!PyLong_Check (value))
{
PyErr_SetString (PyExc_RuntimeError,
_("The value must be integer."));
@ -308,7 +308,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
static int
set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
{
if (PyString_Check (attr_name)
if (PyUnicode_Check (attr_name)
&& ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
{
if (!val)
@ -447,7 +447,7 @@ get_set_value (const char *args, int from_tty,
gdb::unique_xmalloc_ptr<char> set_doc_string;
gdbpy_enter enter_py;
gdbpy_ref<> set_doc_func (PyString_FromString ("get_set_string"));
gdbpy_ref<> set_doc_func (PyUnicode_FromString ("get_set_string"));
if (set_doc_func == NULL)
{
@ -482,7 +482,7 @@ get_show_value (struct ui_file *file, int from_tty,
gdb::unique_xmalloc_ptr<char> show_doc_string;
gdbpy_enter enter_py;
gdbpy_ref<> show_doc_func (PyString_FromString ("get_show_string"));
gdbpy_ref<> show_doc_func (PyUnicode_FromString ("get_show_string"));
if (show_doc_func == NULL)
{
@ -492,7 +492,7 @@ get_show_value (struct ui_file *file, int from_tty,
if (PyObject_HasAttr (obj, show_doc_func.get ()))
{
gdbpy_ref<> val_obj (PyString_FromString (value));
gdbpy_ref<> val_obj (PyUnicode_FromString (value));
if (val_obj == NULL)
{
@ -835,10 +835,10 @@ gdbpy_initialize_parameters (void)
if (PyType_Ready (&parmpy_object_type) < 0)
return -1;
set_doc_cst = PyString_FromString ("set_doc");
set_doc_cst = PyUnicode_FromString ("set_doc");
if (! set_doc_cst)
return -1;
show_doc_cst = PyString_FromString ("show_doc");
show_doc_cst = PyUnicode_FromString ("show_doc");
if (! show_doc_cst)
return -1;