{
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. */
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
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
Py_DECREF (item->event);
xfree (item);
}
-
- do_cleanups (cleanup);
}
/* Submit an event to the gdb thread. */
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;
}
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;
}
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)
done:
Py_XDECREF (type_module);
Py_XDECREF (func);
- do_cleanups (cleanups);
}
/* If TYPE is recognized by some type printer, store in *PRETTIED_TYPE
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;
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)
Py_XDECREF (type_module);
Py_XDECREF (func);
Py_XDECREF (result_obj);
- do_cleanups (cleanups);
if (result != NULL)
{
*prettied_type = result.release ();
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)
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 */