From patchwork Tue Mar 5 22:14:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31726 Received: (qmail 75744 invoked by alias); 5 Mar 2019 22:14:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 75699 invoked by uid 89); 5 Mar 2019 22:14:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2030, HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Mar 2019 22:14:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7282A5614D; Tue, 5 Mar 2019 17:14:05 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 5clER0rcAPMi; Tue, 5 Mar 2019 17:14:05 -0500 (EST) Received: from murgatroyd.Home (75-166-85-218.hlrn.qwest.net [75.166.85.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 1EB935614B; Tue, 5 Mar 2019 17:14:05 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Remove some Python 3 #ifs Date: Tue, 5 Mar 2019 15:14:01 -0700 Message-Id: <20190305221401.8519-1-tromey@adacore.com> MIME-Version: 1.0 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 * 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 unicode_to_encoded_string (PyObject *unicode_str, const char *charset) { - gdb::unique_xmalloc_ptr 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 + (xstrdup (PyBytes_AsString (string.get ()))); } /* Returns a PyObject with the contents of the given unicode string