From patchwork Fri Oct 26 09:35:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vrany X-Patchwork-Id: 29902 Received: (qmail 58690 invoked by alias); 26 Oct 2018 09:35:24 -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 58534 invoked by uid 89); 26 Oct 2018 09:35:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:may, H*r:forged, benson, Benson X-HELO: relay.fit.cvut.cz Received: from relay.fit.cvut.cz (HELO relay.fit.cvut.cz) (147.32.232.237) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Oct 2018 09:35:20 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [147.32.232.238]) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id w9Q9ZF3O033824 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Oct 2018 11:35:17 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Received: from localhost (027f482b.bb.sky.com [2.127.72.43] (may be forged)) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id w9Q9ZER1042316 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 26 Oct 2018 11:35:15 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [PATCH] python: Make Windows-specific code work with Python 3 Date: Fri, 26 Oct 2018 10:35:01 +0100 Message-Id: <20181026093501.9377-1-jan.vrany@fit.cvut.cz> MIME-Version: 1.0 Windows workaround in python_run_simple_file() used Python 2 APIs which were removed in Python 3. This commit adds a conditionally compiled variant that uses Python 3 APIs. gdb/ChangeLog: * python/python.c (python_run_simple_file): Fix for Python 3. --- gdb/ChangeLog | 5 +++++ gdb/python/python.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b3cc64659f..5cdf6d2600 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-16-11 Jan Vrany + + * python/python.c (python_run_simple_file): Fix for + Python 3. + 2018-10-11 Gary Benson * interps.h (interp::m_name): Make private and mutable. diff --git a/gdb/python/python.c b/gdb/python/python.c index 8fbce78469..3cf0a7a325 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -346,15 +346,24 @@ python_run_simple_file (FILE *file, const char *filename) /* Because we have a string for a filename, and are using Python to open the file, we need to expand any tilde in the path first. */ gdb::unique_xmalloc_ptr full_path (tilde_expand (filename)); + +# ifdef IS_PY3K + FILE *python_file = _Py_fopen (full_path.get (), (char *) "r"); + if (python_file == NULL) + { + gdbpy_print_stack (); + error (_("Error while opening file: %s"), full_path.get ()); + } + PyRun_SimpleFile (python_file, filename); +# else gdbpy_ref<> python_file (PyFile_FromString (full_path.get (), (char *) "r")); if (python_file == NULL) { gdbpy_print_stack (); error (_("Error while opening file: %s"), full_path.get ()); } - PyRun_SimpleFile (PyFile_AsFile (python_file.get ()), filename); - +# endif /* IS_PY3K */ #endif /* _WIN32 */ }