From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 08/20] Use gdbpy_enter in python.c
Date: Thu, 10 Nov 2016 22:20:00 -0000 [thread overview]
Message-ID: <1478816387-27064-9-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com>
Change the simple parts of python.c to use gdbpy_enter.
2016-11-10 Tom Tromey <tom@tromey.com>
* 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 <tom@tromey.com>
+ * 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 <tom@tromey.com>
+
* python/py-progspace.c (py_free_pspace): Use gdbpy_enter.
2016-11-10 Tom Tromey <tom@tromey.com>
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);
}
\f
@@ -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 */
--
2.7.4
next prev parent reply other threads:[~2016-11-10 22:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 22:20 [RFA 00/20] more use of C++ in the Python layer Tom Tromey
2016-11-10 22:20 ` [RFA 14/20] Use gdbpy_enter in gdbpy_before_prompt_hook Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-12 17:04 ` Tom Tromey
2016-11-10 22:20 ` [RFA 05/20] Use gdbpy_enter in py-inferior.c Tom Tromey
2016-11-10 22:20 ` [RFA 07/20] Use gdbpy_enter in py-progspace.c Tom Tromey
2016-11-10 22:20 ` [RFA 01/20] Introduce gdbpy_enter Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-10 22:20 ` Tom Tromey [this message]
2016-11-10 22:20 ` [RFA 04/20] Use gdbpy_enter in py-finishbreakpoint.c Tom Tromey
2016-11-10 22:20 ` [RFA 15/20] Use gdbpy_enter in python_interactive_command Tom Tromey
2016-11-10 22:20 ` [RFA 03/20] Use gdbpy_enter in py-cmd.c Tom Tromey
2016-11-10 22:20 ` [RFA 10/20] Use gdbpy_enter in py-xmethods.c Tom Tromey
2016-11-10 22:20 ` [RFA 11/20] Use gdbpy_enter in py-unwind.c Tom Tromey
2016-11-10 22:20 ` [RFA 09/20] Use gdbpy_enter in py-type.c Tom Tromey
2016-11-10 22:20 ` [RFA 17/20] Use gdbpy_reference in invoke_match_method Tom Tromey
2016-11-10 22:20 ` [RFA 16/20] Use gdbpy_enter in gdbpy_get_matching_xmethod_workers Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-11 3:19 ` Tom Tromey
2016-11-11 3:24 ` Pedro Alves
2016-11-12 17:09 ` Tom Tromey
2016-11-10 22:20 ` [RFA 02/20] Use gdbpy_enter in py-breakpoint.c Tom Tromey
2016-11-10 22:20 ` [RFA 13/20] Use gdbpy_enter in py-prettyprint.c Tom Tromey
2016-11-10 22:20 ` [RFA 06/20] Use gdbpy_enter in py-objfile.c Tom Tromey
2016-11-10 22:26 ` [RFA 19/20] Introduce gdbpy_enter_varobj and use it Tom Tromey
2016-11-10 22:26 ` [RFA 12/20] Introduce htab_up and use gdbpy_enter in py-framefilter.c Tom Tromey
2016-11-10 22:26 ` [RFA 20/20] Use gdbpy_enter_varobj in py-varobj.c Tom Tromey
2016-11-10 22:26 ` [RFA 18/20] Use gdbpy_enter in py-xmethod.c Tom Tromey
2016-11-10 23:52 ` [RFA 00/20] more use of C++ in the Python layer Pedro Alves
2016-11-11 3:19 ` Tom Tromey
2016-11-12 17:24 ` Tom Tromey
2016-11-15 14:57 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478816387-27064-9-git-send-email-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox