Remove some Python 3 #ifs
authorTom Tromey <tromey@adacore.com>
Tue, 5 Mar 2019 21:58:24 +0000 (14:58 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 5 Mar 2019 22:01:59 +0000 (15:01 -0700)
A recent patch from Kevin Buettner taught me that the PyBytes API is
available on Python 2.  This patch removes a couple of related #ifs in
the Python code.

Tested on x86-64 Fedora 29, using both Python 3.7 and Python 2.7.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

* python/py-prettyprint.c (print_string_repr): Remove #if.
* python/py-utils.c (unicode_to_encoded_string): Remove #if.

gdb/ChangeLog
gdb/python/py-prettyprint.c
gdb/python/py-utils.c

index 120cce01ca97b9987199eab10a34bcf0227dea7e..7c4a06f83279ed8d6c34530eff614e6a9af0aa5b 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-05  Tom Tromey  <tromey@adacore.com>
+
+       * python/py-prettyprint.c (print_string_repr): Remove #if.
+       * python/py-utils.c (unicode_to_encoded_string): Remove #if.
+
 2019-03-05  Tom Tromey  <tromey@adacore.com>
 
        * target.c (the_dummy_target): Move later.  Change type to
index b069ca3a9f94428e88e21e6947131d8d9739d195..e64d1f88af892c38b7a2b97a572f62a25cada696 100644 (file)
@@ -312,13 +312,8 @@ print_string_repr (PyObject *printer, const char *hint,
              long length;
              struct type *type;
 
-#ifdef IS_PY3K
              output = PyBytes_AS_STRING (string.get ());
              length = PyBytes_GET_SIZE (string.get ());
-#else
-             output = PyString_AsString (string.get ());
-             length = PyString_Size (string.get ());
-#endif
              type = builtin_type (gdbarch)->builtin_char;
 
              if (hint && !strcmp (hint, "string"))
index a380b34afe85410ccce6eac68a0224609b85b502..d470000219589f7a9f40c6280f138becc367bd95 100644 (file)
@@ -66,20 +66,13 @@ python_string_to_unicode (PyObject *obj)
 static gdb::unique_xmalloc_ptr<char>
 unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
 {
-  gdb::unique_xmalloc_ptr<char> result;
-
   /* Translate string to named charset.  */
   gdbpy_ref<> string (PyUnicode_AsEncodedString (unicode_str, charset, NULL));
   if (string == NULL)
     return NULL;
 
-#ifdef IS_PY3K
-  result.reset (xstrdup (PyBytes_AsString (string.get ())));
-#else
-  result.reset (xstrdup (PyString_AsString (string.get ())));
-#endif
-
-  return result;
+  return gdb::unique_xmalloc_ptr<char>
+    (xstrdup (PyBytes_AsString (string.get ())));
 }
 
 /* Returns a PyObject with the contents of the given unicode string
This page took 0.026561 seconds and 4 git commands to generate.