From patchwork Thu Nov 10 22:19:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17393 Received: (qmail 61362 invoked by alias); 10 Nov 2016 22:20:13 -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 60923 invoked by uid 89); 10 Nov 2016 22:20:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=Submit, 8858 X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 10 Nov 2016 22:20:01 +0000 Received: (qmail 9415 invoked by uid 0); 10 Nov 2016 22:20:00 -0000 Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy10.mail.unifiedlayer.com with SMTP; 10 Nov 2016 22:20:00 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id 6NKx1u0082f2jeq01NL05B; Thu, 10 Nov 2016 15:20:00 -0700 X-Authority-Analysis: v=2.1 cv=fZg+lSgF c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=IMUvTdQu3dtEL3JrwpAA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:60120 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c4xhM-0002sd-Q8; Thu, 10 Nov 2016 15:19:56 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 08/20] Use gdbpy_enter in python.c Date: Thu, 10 Nov 2016 15:19:35 -0700 Message-Id: <1478816387-27064-9-git-send-email-tom@tromey.com> In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com> References: <1478816387-27064-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c4xhM-0002sd-Q8 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:60120 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== Change the simple parts of python.c to use gdbpy_enter. 2016-11-10 Tom Tromey * python/python.c (gdbpy_eval_from_control_command) (gdbpy_source_script, gdbpy_run_events) (gdbpy_source_objfile_script, gdbpy_execute_objfile_script) (gdbpy_free_type_printers, gdbpy_finish_initialization): Use gdbpy_enter. --- gdb/ChangeLog | 8 ++++++++ gdb/python/python.c | 38 ++++++++------------------------------ 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3a25270..e93e36b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2016-11-10 Tom Tromey + * python/python.c (gdbpy_eval_from_control_command) + (gdbpy_source_script, gdbpy_run_events) + (gdbpy_source_objfile_script, gdbpy_execute_objfile_script) + (gdbpy_free_type_printers, gdbpy_finish_initialization): Use + gdbpy_enter. + +2016-11-10 Tom Tromey + * python/py-progspace.c (py_free_pspace): Use gdbpy_enter. 2016-11-10 Tom Tromey diff --git a/gdb/python/python.c b/gdb/python/python.c index 78b4507..de75b0e 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -434,20 +434,17 @@ gdbpy_eval_from_control_command (const struct extension_language_defn *extlang, { int ret; char *script; - struct cleanup *cleanup; if (cmd->body_count != 1) error (_("Invalid \"python\" block structure.")); - cleanup = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); script = compute_python_string (cmd->body_list[0]); ret = PyRun_SimpleString (script); xfree (script); if (ret) error (_("Error while executing Python code.")); - - do_cleanups (cleanup); } /* Implementation of the gdb "python" command. */ @@ -888,11 +885,8 @@ static void gdbpy_source_script (const struct extension_language_defn *extlang, FILE *file, const char *filename) { - struct cleanup *cleanup; - - cleanup = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); python_run_simple_file (file, filename); - do_cleanups (cleanup); } @@ -924,9 +918,7 @@ static struct serial_event *gdbpy_serial_event; static void gdbpy_run_events (int error, gdb_client_data client_data) { - struct cleanup *cleanup; - - cleanup = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); /* Clear the event fd. Do this before flushing the events list, so that any new event post afterwards is sure to re-awake the event @@ -953,8 +945,6 @@ gdbpy_run_events (int error, gdb_client_data client_data) Py_DECREF (item->event); xfree (item); } - - do_cleanups (cleanup); } /* Submit an event to the gdb thread. */ @@ -1297,17 +1287,14 @@ gdbpy_source_objfile_script (const struct extension_language_defn *extlang, struct objfile *objfile, FILE *file, const char *filename) { - struct cleanup *cleanups; - if (!gdb_python_initialized) return; - cleanups = ensure_python_env (get_objfile_arch (objfile), current_language); + gdbpy_enter enter_py (get_objfile_arch (objfile), current_language); gdbpy_current_objfile = objfile; python_run_simple_file (file, filename); - do_cleanups (cleanups); gdbpy_current_objfile = NULL; } @@ -1322,17 +1309,14 @@ gdbpy_execute_objfile_script (const struct extension_language_defn *extlang, struct objfile *objfile, const char *name, const char *script) { - struct cleanup *cleanups; - if (!gdb_python_initialized) return; - cleanups = ensure_python_env (get_objfile_arch (objfile), current_language); + gdbpy_enter enter_py (get_objfile_arch (objfile), current_language); gdbpy_current_objfile = objfile; PyRun_SimpleString (script); - do_cleanups (cleanups); gdbpy_current_objfile = NULL; } @@ -1383,13 +1367,12 @@ static void gdbpy_start_type_printers (const struct extension_language_defn *extlang, struct ext_lang_type_printers *ext_printers) { - struct cleanup *cleanups; PyObject *type_module, *func = NULL, *printers_obj = NULL; if (!gdb_python_initialized) return; - cleanups = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); type_module = PyImport_ImportModule ("gdb.types"); if (type_module == NULL) @@ -1414,7 +1397,6 @@ gdbpy_start_type_printers (const struct extension_language_defn *extlang, done: Py_XDECREF (type_module); Py_XDECREF (func); - do_cleanups (cleanups); } /* If TYPE is recognized by some type printer, store in *PRETTIED_TYPE @@ -1429,7 +1411,6 @@ gdbpy_apply_type_printers (const struct extension_language_defn *extlang, const struct ext_lang_type_printers *ext_printers, struct type *type, char **prettied_type) { - struct cleanup *cleanups; PyObject *type_obj, *type_module = NULL, *func = NULL; PyObject *result_obj = NULL; PyObject *printers_obj = (PyObject *) ext_printers->py_type_printers; @@ -1441,7 +1422,7 @@ gdbpy_apply_type_printers (const struct extension_language_defn *extlang, if (!gdb_python_initialized) return EXT_LANG_RC_NOP; - cleanups = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); type_obj = type_to_type_object (type); if (type_obj == NULL) @@ -1484,7 +1465,6 @@ gdbpy_apply_type_printers (const struct extension_language_defn *extlang, Py_XDECREF (type_module); Py_XDECREF (func); Py_XDECREF (result_obj); - do_cleanups (cleanups); if (result != NULL) { *prettied_type = result.release (); @@ -1500,7 +1480,6 @@ static void gdbpy_free_type_printers (const struct extension_language_defn *extlang, struct ext_lang_type_printers *ext_printers) { - struct cleanup *cleanups; PyObject *printers = (PyObject *) ext_printers->py_type_printers; if (printers == NULL) @@ -1509,9 +1488,8 @@ gdbpy_free_type_printers (const struct extension_language_defn *extlang, if (!gdb_python_initialized) return; - cleanups = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); Py_DECREF (printers); - do_cleanups (cleanups); } #else /* HAVE_PYTHON */