public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] gdb/python: remove Python 2/3 compatibility macros
Date: Fri,  7 Jan 2022 10:29:20 -0500	[thread overview]
Message-ID: <20220107152921.2858909-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20220107152921.2858909-1-simon.marchi@polymtl.ca>

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
---
 gdb/python/py-arch.c          | 11 +++++------
 gdb/python/py-breakpoint.c    | 12 ++++++------
 gdb/python/py-cmd.c           | 10 +++++-----
 gdb/python/py-connection.c    |  4 ++--
 gdb/python/py-frame.c         |  2 +-
 gdb/python/py-inferior.c      |  4 ++--
 gdb/python/py-infthread.c     |  2 +-
 gdb/python/py-lazy-string.c   |  2 +-
 gdb/python/py-membuf.c        |  2 +-
 gdb/python/py-objfile.c       |  6 +++---
 gdb/python/py-param.c         | 16 ++++++++--------
 gdb/python/py-record-btrace.c |  8 ++++----
 gdb/python/py-record-full.c   |  4 ++--
 gdb/python/py-record.c        |  2 +-
 gdb/python/py-registers.c     |  6 +++---
 gdb/python/py-signalevent.c   |  2 +-
 gdb/python/py-symbol.c        |  6 +++---
 gdb/python/py-symtab.c        |  4 ++--
 gdb/python/py-type.c          | 12 ++++++------
 gdb/python/py-unwind.c        |  6 +++---
 gdb/python/py-utils.c         |  8 ++++----
 gdb/python/py-xmethods.c      |  6 +++---
 gdb/python/python-internal.h  | 22 ----------------------
 gdb/python/python.c           | 26 +++++++++++++-------------
 24 files changed, 80 insertions(+), 103 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index e87881a8fd39..da6af8755739 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -100,7 +100,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
@@ -158,7 +158,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,
@@ -207,9 +207,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;
 
@@ -332,7 +331,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)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index f00bd6f78e61..6eb980be9b25 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -224,7 +224,7 @@ bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `thread' attribute."));
       return -1;
     }
-  else if (PyInt_Check (newvalue))
+  else if (PyLong_Check (newvalue))
     {
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
@@ -266,7 +266,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `task' attribute."));
       return -1;
     }
-  else if (PyInt_Check (newvalue))
+  else if (PyLong_Check (newvalue))
     {
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
@@ -341,7 +341,7 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
 		       _("Cannot delete `ignore_count' attribute."));
       return -1;
     }
-  else if (! PyInt_Check (newvalue))
+  else if (! PyLong_Check (newvalue))
     {
       PyErr_SetString (PyExc_TypeError,
 		       _("The value of `ignore_count' must be an integer."));
@@ -780,9 +780,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
   if (lineobj != NULL)
     {
-      if (PyInt_Check (lineobj))
-	line = xstrprintf ("%ld", PyInt_AsLong (lineobj));
-      else if (PyString_Check (lineobj))
+      if (PyLong_Check (lineobj))
+	line = xstrprintf ("%ld", PyLong_AsLong (lineobj));
+      else if (PyUnicode_Check (lineobj))
 	line = python_string_to_host_string (lineobj);
       else
 	{
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 3a4e6490cf09..9181aadcd011 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -233,7 +233,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command,
   if (resultobj == NULL)
     return;
 
-  if (PyInt_Check (resultobj.get ()))
+  if (PyLong_Check (resultobj.get ()))
     {
       /* User code may also return one of the completion constants,
 	 thus requesting that sort of completion.  We are only
@@ -277,7 +277,7 @@ cmdpy_completer (struct cmd_list_element *command,
   if (resultobj == NULL)
     return;
 
-  if (PyInt_Check (resultobj.get ()))
+  if (PyLong_Check (resultobj.get ()))
     {
       /* User code may also return one of the completion constants,
 	 thus requesting that sort of completion.  */
@@ -592,10 +592,10 @@ gdbpy_initialize_commands (void)
 			      (PyObject *) &cmdpy_object_type) < 0)
     return -1;
 
-  invoke_cst = PyString_FromString ("invoke");
+  invoke_cst = PyUnicode_FromString ("invoke");
   if (invoke_cst == NULL)
     return -1;
-  complete_cst = PyString_FromString ("complete");
+  complete_cst = PyUnicode_FromString ("complete");
   if (complete_cst == NULL)
     return -1;
 
@@ -684,7 +684,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
 
       for (char *arg : c_argv)
 	{
-	  gdbpy_ref<> argp (PyString_FromString (arg));
+	  gdbpy_ref<> argp (PyUnicode_FromString (arg));
 
 	  if (argp == NULL
 	      || PyList_Append (py_argv.get (), argp.get ()) < 0)
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index 7c33a1f93d43..c125e4754375 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -204,9 +204,9 @@ connpy_repr (PyObject *obj)
   process_stratum_target *target = self->target;
 
   if (target == nullptr)
-    return PyString_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
+    return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
 
-  return PyString_FromFormat ("<%s num=%d, what=\"%s\">",
+  return PyUnicode_FromFormat ("<%s num=%d, what=\"%s\">",
 			      Py_TYPE (obj)->tp_name,
 			      target->connection_number,
 			      make_target_connection_string (target).c_str ());
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 0cab8e159465..bf9eba89c5fd 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -80,7 +80,7 @@ static PyObject *
 frapy_str (PyObject *self)
 {
   const frame_id &fid = ((frame_object *) self)->frame_id;
-  return PyString_FromString (fid.to_string ().c_str ());
+  return PyUnicode_FromString (fid.to_string ().c_str ());
 }
 
 /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 45e33f9e28a7..87b5a20cf1e4 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -754,9 +754,9 @@ infpy_repr (PyObject *obj)
   inferior *inf = self->inferior;
 
   if (inf == nullptr)
-    return PyString_FromString ("<gdb.Inferior (invalid)>");
+    return PyUnicode_FromString ("<gdb.Inferior (invalid)>");
 
-  return PyString_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
+  return PyUnicode_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
 			      inf->num, inf->pid);
 }
 
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index e568d8d916e4..fdf337f056a3 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -73,7 +73,7 @@ thpy_get_name (PyObject *self, void *ignore)
   if (name == NULL)
     Py_RETURN_NONE;
 
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 static int
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 69b1bc52ab9a..c49987e25300 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -73,7 +73,7 @@ stpy_get_encoding (PyObject *self, void *closure)
   /* An encoding can be set to NULL by the user, so check before
      attempting a Python FromString call.  If NULL return Py_None.  */
   if (self_string->encoding)
-    result = PyString_FromString (self_string->encoding);
+    result = PyUnicode_FromString (self_string->encoding);
   else
     {
       result = Py_None;
diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
index fa8731a515f9..ee49b97aa44d 100644
--- a/gdb/python/py-membuf.c
+++ b/gdb/python/py-membuf.c
@@ -73,7 +73,7 @@ mbpy_str (PyObject *self)
 {
   membuf_object *membuf_obj = (membuf_object *) self;
 
-  return PyString_FromFormat (_("Memory buffer for address %s, \
+  return PyUnicode_FromFormat (_("Memory buffer for address %s, \
 which is %s bytes long."),
 			      paddress (python_gdbarch, membuf_obj->addr),
 			      pulongest (membuf_obj->length));
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 38052245bde7..12b4e15c3442 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -510,10 +510,10 @@ objfpy_repr (PyObject *self_)
   objfile *obj = self->objfile;
 
   if (obj == nullptr)
-    return PyString_FromString ("<gdb.Objfile (invalid)>");
+    return PyUnicode_FromString ("<gdb.Objfile (invalid)>");
 
-  return PyString_FromFormat ("<gdb.Objfile filename=%s>",
-			      objfile_filename (obj));
+  return PyUnicode_FromFormat ("<gdb.Objfile filename=%s>",
+			       objfile_filename (obj));
 }
 
 /* Subroutine of gdbpy_lookup_objfile_by_build_id to simplify it.
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index a601790102c1..c86f0ee538ed 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -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)
@@ -389,7 +389,7 @@ get_set_value (const char *args, int from_tty,
   gdb::unique_xmalloc_ptr<char> set_doc_string;
 
   gdbpy_enter enter_py (get_current_arch (), current_language);
-  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)
     {
@@ -424,7 +424,7 @@ get_show_value (struct ui_file *file, int from_tty,
   gdb::unique_xmalloc_ptr<char> show_doc_string;
 
   gdbpy_enter enter_py (get_current_arch (), current_language);
-  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)
     {
@@ -434,7 +434,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)
 	{
@@ -773,10 +773,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;
 
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index bee17e0e3cc2..85401010f0a0 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -471,9 +471,9 @@ btpy_list_slice (PyObject *self, PyObject *value)
   const Py_ssize_t length = btpy_list_length (self);
   Py_ssize_t start, stop, step, slicelength;
 
-  if (PyInt_Check (value))
+  if (PyLong_Check (value))
     {
-      Py_ssize_t index = PyInt_AsSsize_t (value);
+      Py_ssize_t index = PyLong_AsSsize_t (value);
 
       /* Emulate Python behavior for negative indices.  */
       if (index < 0)
@@ -607,7 +607,7 @@ btpy_list_richcompare (PyObject *self, PyObject *other, int op)
 PyObject *
 recpy_bt_method (PyObject *self, void *closure)
 {
-  return PyString_FromString ("btrace");
+  return PyUnicode_FromString ("btrace");
 }
 
 /* Implementation of
@@ -628,7 +628,7 @@ recpy_bt_format (PyObject *self, void *closure)
   if (config == NULL)
     Py_RETURN_NONE;
 
-  return PyString_FromString (btrace_format_short_string (config->format));
+  return PyUnicode_FromString (btrace_format_short_string (config->format));
 }
 
 /* Implementation of
diff --git a/gdb/python/py-record-full.c b/gdb/python/py-record-full.c
index 1caec735c497..ecae08bfc956 100644
--- a/gdb/python/py-record-full.c
+++ b/gdb/python/py-record-full.c
@@ -26,7 +26,7 @@
 PyObject *
 recpy_full_method (PyObject *self, void *closure)
 {
-  return PyString_FromString ("full");
+  return PyUnicode_FromString ("full");
 }
 
 /* Implementation of
@@ -35,5 +35,5 @@ recpy_full_method (PyObject *self, void *closure)
 PyObject *
 recpy_full_format (PyObject *self, void *closure)
 {
-  return PyString_FromString ("full");
+  return PyUnicode_FromString ("full");
 }
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index a4ab2936b014..51084dfac72c 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -474,7 +474,7 @@ recpy_gap_reason_string (PyObject *self, void *closure)
 {
   const recpy_gap_object * const obj = (const recpy_gap_object *) self;
 
-  return PyString_FromString (obj->reason_string);
+  return PyUnicode_FromString (obj->reason_string);
 }
 
 /* Record method list.  */
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index b3f784e7fc51..eab88a30b3b7 100644
--- a/gdb/python/py-registers.c
+++ b/gdb/python/py-registers.c
@@ -138,7 +138,7 @@ gdbpy_reggroup_to_string (PyObject *self)
   struct reggroup *reggroup = group->reggroup;
 
   const char *name = reggroup_name (reggroup);
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implement gdb.RegisterGroup.name (self) -> String.
@@ -196,7 +196,7 @@ gdbpy_register_descriptor_to_string (PyObject *self)
   int regnum = reg->regnum;
 
   const char *name = gdbarch_register_name (gdbarch, regnum);
-  return PyString_FromString (name);
+  return PyUnicode_FromString (name);
 }
 
 /* Implement gdb.RegisterDescriptor.name attribute get function.  Return a
@@ -391,7 +391,7 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
 	}
     }
   /* The register could be its internal GDB register number.  */
-  else if (PyInt_Check (pyo_reg_id))
+  else if (PyLong_Check (pyo_reg_id))
     {
       long value;
       if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index e349f6107b29..69eeebbfaaa7 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -31,7 +31,7 @@ create_signal_event_object (enum gdb_signal stop_signal)
 
   const char *signal_name = gdb_signal_to_name (stop_signal);
 
-  gdbpy_ref<> signal_name_obj (PyString_FromString (signal_name));
+  gdbpy_ref<> signal_name_obj (PyUnicode_FromString (signal_name));
   if (signal_name_obj == NULL)
     return NULL;
   if (evpy_add_attribute (signal_event_obj.get (),
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 508f445e1001..b06a24a942b0 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -60,7 +60,7 @@ sympy_str (PyObject *self)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  result = PyString_FromString (symbol->print_name ());
+  result = PyUnicode_FromString (symbol->print_name ());
 
   return result;
 }
@@ -101,7 +101,7 @@ sympy_get_name (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyString_FromString (symbol->natural_name ());
+  return PyUnicode_FromString (symbol->natural_name ());
 }
 
 static PyObject *
@@ -111,7 +111,7 @@ sympy_get_linkage_name (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  return PyString_FromString (symbol->linkage_name ());
+  return PyUnicode_FromString (symbol->linkage_name ());
 }
 
 static PyObject *
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index db19e4b1213e..c3e1cf340354 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -93,7 +93,7 @@ stpy_str (PyObject *self)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  result = PyString_FromString (symtab_to_filename_for_display (symtab));
+  result = PyUnicode_FromString (symtab_to_filename_for_display (symtab));
 
   return result;
 }
@@ -234,7 +234,7 @@ salpy_str (PyObject *self)
       filename = symtab_to_filename_for_display (symtab);
     }
 
-  return PyString_FromFormat ("symbol and line for %s, line %d", filename,
+  return PyUnicode_FromFormat ("symbol and line for %s, line %d", filename,
 			      sal->line);
 }
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index ed487d82cac3..aa5d9b46b341 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -210,7 +210,7 @@ convert_field (struct type *type, int field)
 
       if (field_name[0] != '\0')
 	{
-	  arg.reset (PyString_FromString (type->field (field).name ()));
+	  arg.reset (PyUnicode_FromString (type->field (field).name ()));
 	  if (arg == NULL)
 	    return NULL;
 	}
@@ -262,7 +262,7 @@ field_name (struct type *type, int field)
   gdbpy_ref<> result;
 
   if (type->field (field).name ())
-    result.reset (PyString_FromString (type->field (field).name ()));
+    result.reset (PyUnicode_FromString (type->field (field).name ()));
   else
     result = gdbpy_ref<>::new_reference (Py_None);
 
@@ -400,9 +400,9 @@ typy_get_name (PyObject *self, void *closure)
     {
       std::string name = ada_decode (type->name (), false);
       if (!name.empty ())
-	return PyString_FromString (name.c_str ());
+	return PyUnicode_FromString (name.c_str ());
     }
-  return PyString_FromString (type->name ());
+  return PyUnicode_FromString (type->name ());
 }
 
 /* Return the type's tag, or None.  */
@@ -419,7 +419,7 @@ typy_get_tag (PyObject *self, void *closure)
 
   if (tagname == nullptr)
     Py_RETURN_NONE;
-  return PyString_FromString (tagname);
+  return PyUnicode_FromString (tagname);
 }
 
 /* Return the type's objfile, or None.  */
@@ -506,7 +506,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
 
   if (n2_obj)
     {
-      if (!PyInt_Check (n2_obj))
+      if (!PyLong_Check (n2_obj))
 	{
 	  PyErr_SetString (PyExc_RuntimeError,
 			   _("Array bound must be an integer"));
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index a884c83ec269..f82dd9474c02 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -213,7 +213,7 @@ unwind_infopy_str (PyObject *self)
     stb.puts (")");
   }
 
-  return PyString_FromString (stb.c_str ());
+  return PyUnicode_FromString (stb.c_str ());
 }
 
 /* Create UnwindInfo instance for given PendingFrame and frame ID.
@@ -349,7 +349,7 @@ pending_framepy_str (PyObject *self)
   const char *pc_str = NULL;
 
   if (frame == NULL)
-    return PyString_FromString ("Stale PendingFrame instance");
+    return PyUnicode_FromString ("Stale PendingFrame instance");
   try
     {
       sp_str = core_addr_to_string_nz (get_frame_sp (frame));
@@ -360,7 +360,7 @@ pending_framepy_str (PyObject *self)
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
+  return PyUnicode_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
 }
 
 /* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 0d1a55734671..8027fa469acf 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -150,8 +150,8 @@ python_string_to_host_string (PyObject *obj)
 gdbpy_ref<>
 host_string_to_python_string (const char *str)
 {
-  return gdbpy_ref<> (PyString_Decode (str, strlen (str), host_charset (),
-				       NULL));
+  return gdbpy_ref<> (PyUnicode_Decode (str, strlen (str), host_charset (),
+					NULL));
 }
 
 /* Return true if OBJ is a Python string or unicode object, false
@@ -292,13 +292,13 @@ gdb_py_object_from_ulongest (ULONGEST l)
   return gdbpy_ref<> (PyLong_FromUnsignedLong (l));
 }
 
-/* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts
+/* Like PyLong_AsLong, but returns 0 on failure, 1 on success, and puts
    the value into an out parameter.  */
 
 int
 gdb_py_int_as_long (PyObject *obj, long *result)
 {
-  *result = PyInt_AsLong (obj);
+  *result = PyLong_AsLong (obj);
   return ! (*result == -1 && PyErr_Occurred ());
 }
 
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index fd3673029a02..897f58cc7131 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -103,7 +103,7 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
   if (match_method == NULL)
     return NULL;
 
-  gdbpy_ref<> py_xmethod_name (PyString_FromString (xmethod_name));
+  gdbpy_ref<> py_xmethod_name (PyUnicode_FromString (xmethod_name));
   if (py_xmethod_name == NULL)
     return NULL;
 
@@ -601,12 +601,12 @@ python_xmethod_worker::python_xmethod_worker (PyObject *py_worker,
 int
 gdbpy_initialize_xmethods (void)
 {
-  py_match_method_name = PyString_FromString (match_method_name);
+  py_match_method_name = PyUnicode_FromString (match_method_name);
   if (py_match_method_name == NULL)
     return -1;
 
   py_get_arg_types_method_name
-    = PyString_FromString (get_arg_types_method_name);
+    = PyUnicode_FromString (get_arg_types_method_name);
   if (py_get_arg_types_method_name == NULL)
     return -1;
 
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 421031c9609d..b38d69258add 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -89,15 +89,6 @@
 
 #define Py_TPFLAGS_CHECKTYPES 0
 
-#define PyInt_Check PyLong_Check
-#define PyInt_AsLong PyLong_AsLong
-#define PyInt_AsSsize_t PyLong_AsSsize_t
-
-#define PyString_FromString PyUnicode_FromString
-#define PyString_Decode PyUnicode_Decode
-#define PyString_FromFormat PyUnicode_FromFormat
-#define PyString_Check PyUnicode_Check
-
 /* If Python.h does not define WITH_THREAD, then the various
    GIL-related functions will not be defined.  However,
    PyGILState_STATE will be.  */
@@ -141,19 +132,6 @@ typedef long Py_hash_t;
 #define PyMem_RawMalloc PyMem_Malloc
 #endif
 
-/* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
-   to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
-   Wrap it ourselves, so that callers don't need to care.  */
-
-static inline void
-gdb_Py_DECREF (void *op) /* ARI: editCase function */
-{
-  Py_DECREF (op);
-}
-
-#undef Py_DECREF
-#define Py_DECREF(op) gdb_Py_DECREF (op)
-
 /* PyObject_CallMethod's 'method' and 'format' parameters were missing
    the 'const' qualifier before Python 3.4.  Hence, we wrap the
    function in our own version to avoid errors with string literals.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index ebfe7823d743..a9dfb6f5877b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -656,7 +656,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;
 }
 
@@ -902,7 +902,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;
     }
@@ -1064,7 +1064,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 ();
@@ -1083,7 +1083,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 " \
@@ -1136,13 +1136,13 @@ 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 ();
       return {};
     }
-  gdbpy_ref<> contents_arg (PyString_FromString (contents.c_str ()));
+  gdbpy_ref<> contents_arg (PyUnicode_FromString (contents.c_str ()));
   if (contents_arg == nullptr)
     {
       gdbpy_print_stack ();
@@ -1871,22 +1871,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;
 
@@ -2101,7 +2101,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;
     }
-- 
2.34.1


  reply	other threads:[~2022-01-07 15:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 15:29 [PATCH 1/3] gdb/python: remove Python 2 support Simon Marchi
2022-01-07 15:29 ` Simon Marchi [this message]
2022-01-07 15:29 ` [PATCH 3/3] gdb/python: drop support for Python < 3.4 Simon Marchi
2022-01-07 16:33   ` Eli Zaretskii
2022-01-07 17:14     ` Simon Marchi
2022-01-07 15:33 ` [PATCH 1/3] gdb/python: remove Python 2 support Paul Koning
2022-01-07 15:41   ` Simon Marchi
2022-01-07 17:44 ` Andrew Burgess
2022-01-08  8:18   ` Joel Brobecker
2022-01-10  2:28     ` Simon Marchi
2022-01-10  2:59       ` Joel Brobecker
2022-01-10 16:39         ` Simon Marchi
2022-01-11  3:26           ` Joel Brobecker
2022-01-10 16:26       ` Tom Tromey
2022-03-03 16:31 ` Andrew Burgess
2022-03-03 17:40   ` Simon Marchi
2022-03-21 14:46 ` [PATCH v2 0/2] Remove " Simon Marchi
2022-03-21 14:46   ` [PATCH v2 1/2] gdb/python: remove " Simon Marchi
2022-03-21 14:50     ` Simon Marchi
2022-03-21 14:58     ` Eli Zaretskii
2022-03-21 15:04       ` Simon Marchi
2022-03-21 15:33         ` Pedro Alves
2022-03-21 16:31           ` Simon Marchi
2022-03-21 16:55             ` Pedro Alves
2022-03-21 17:04               ` Simon Marchi
2022-03-21 14:46   ` [PATCH v2 2/2] gdb/python: remove Python 2/3 compatibility macros Simon Marchi
2022-03-23 11:46   ` [PATCH v2 0/2] Remove Python 2 support Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220107152921.2858909-2-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).