* [FYI] Remove some Python 3 #ifs
@ 2019-03-05 22:14 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-03-05 22:14 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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 | 5 +++++
gdb/python/py-prettyprint.c | 5 -----
gdb/python/py-utils.c | 11 ++---------
3 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index b069ca3a9f9..e64d1f88af8 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -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"))
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index a380b34afe8..d4700002195 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -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
--
2.20.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-03-05 22:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-05 22:14 [FYI] Remove some Python 3 #ifs Tom Tromey
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).