aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-11-12 11:57:45 -0700
committerTom Tromey <tom@tromey.com>2017-01-10 19:13:57 -0700
commit3b4e0e01f8b19269d720948ee2350cb753f8ede4 (patch)
treeb17dc15d471ccf73143cc7fb1cb7656767e9e648 /gdb
parent17a22718b113a220de121ef4211fc3990d9b1745 (diff)
downloadgdb-3b4e0e01f8b19269d720948ee2350cb753f8ede4.zip
gdb-3b4e0e01f8b19269d720948ee2350cb753f8ede4.tar.gz
gdb-3b4e0e01f8b19269d720948ee2350cb753f8ede4.tar.bz2
Use gdbpy_ref in py_print_frame
This changes py_print_frame to use gdbpy_ref in a few spots. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (py_print_frame): Use gdbpy_ref.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog4
-rw-r--r--gdb/python/py-framefilter.c41
2 files changed, 16 insertions, 29 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 32e6d13..b08f1dd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
2017-01-10 Tom Tromey <tom@tromey.com>
+ * python/py-framefilter.c (py_print_frame): Use gdbpy_ref.
+
+2017-01-10 Tom Tromey <tom@tromey.com>
+
* python/python.c (ensure_python_env, restore_python_env):
Remove.
* python/python-internal.h (ensure_python_env): Don't declare.
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 115e38a..3a7132b 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1171,8 +1171,7 @@ py_print_frame (PyObject *filter, int flags,
/* Print frame function name. */
if (PyObject_HasAttrString (filter, "function"))
{
- PyObject *py_func = PyObject_CallMethod (filter, "function", NULL);
- struct cleanup *py_func_cleanup;
+ gdbpy_ref py_func (PyObject_CallMethod (filter, "function", NULL));
const char *function = NULL;
if (py_func == NULL)
@@ -1180,11 +1179,10 @@ py_print_frame (PyObject *filter, int flags,
do_cleanups (cleanup_stack);
return EXT_LANG_BT_ERROR;
}
- py_func_cleanup = make_cleanup_py_decref (py_func);
- if (gdbpy_is_string (py_func))
+ if (gdbpy_is_string (py_func.get ()))
{
- function_to_free = python_string_to_host_string (py_func);
+ function_to_free = python_string_to_host_string (py_func.get ());
if (function_to_free == NULL)
{
@@ -1194,12 +1192,12 @@ py_print_frame (PyObject *filter, int flags,
function = function_to_free.get ();
}
- else if (PyLong_Check (py_func))
+ else if (PyLong_Check (py_func.get ()))
{
CORE_ADDR addr;
struct bound_minimal_symbol msymbol;
- if (get_addr_from_python (py_func, &addr) < 0)
+ if (get_addr_from_python (py_func.get (), &addr) < 0)
{
do_cleanups (cleanup_stack);
return EXT_LANG_BT_ERROR;
@@ -1233,8 +1231,6 @@ py_print_frame (PyObject *filter, int flags,
return EXT_LANG_BT_ERROR;
}
END_CATCH
-
- do_cleanups (py_func_cleanup);
}
}
@@ -1267,20 +1263,18 @@ py_print_frame (PyObject *filter, int flags,
if (PyObject_HasAttrString (filter, "filename"))
{
- PyObject *py_fn = PyObject_CallMethod (filter, "filename", NULL);
- struct cleanup *py_fn_cleanup;
+ gdbpy_ref py_fn (PyObject_CallMethod (filter, "filename", NULL));
if (py_fn == NULL)
{
do_cleanups (cleanup_stack);
return EXT_LANG_BT_ERROR;
}
- py_fn_cleanup = make_cleanup_py_decref (py_fn);
if (py_fn != Py_None)
{
gdb::unique_xmalloc_ptr<char>
- filename (python_string_to_host_string (py_fn));
+ filename (python_string_to_host_string (py_fn.get ()));
if (filename == NULL)
{
@@ -1304,13 +1298,11 @@ py_print_frame (PyObject *filter, int flags,
}
END_CATCH
}
- do_cleanups (py_fn_cleanup);
}
if (PyObject_HasAttrString (filter, "line"))
{
- PyObject *py_line = PyObject_CallMethod (filter, "line", NULL);
- struct cleanup *py_line_cleanup;
+ gdbpy_ref py_line (PyObject_CallMethod (filter, "line", NULL));
int line;
if (py_line == NULL)
@@ -1318,11 +1310,10 @@ py_print_frame (PyObject *filter, int flags,
do_cleanups (cleanup_stack);
return EXT_LANG_BT_ERROR;
}
- py_line_cleanup = make_cleanup_py_decref (py_line);
if (py_line != Py_None)
{
- line = PyLong_AsLong (py_line);
+ line = PyLong_AsLong (py_line.get ());
if (PyErr_Occurred ())
{
do_cleanups (cleanup_stack);
@@ -1343,7 +1334,6 @@ py_print_frame (PyObject *filter, int flags,
}
END_CATCH
}
- do_cleanups (py_line_cleanup);
}
}
@@ -1376,17 +1366,13 @@ py_print_frame (PyObject *filter, int flags,
}
{
- PyObject *elided;
- struct cleanup *elided_cleanup;
-
/* Finally recursively print elided frames, if any. */
- elided = get_py_iter_from_func (filter, "elided");
+ gdbpy_ref elided (get_py_iter_from_func (filter, "elided"));
if (elided == NULL)
{
do_cleanups (cleanup_stack);
return EXT_LANG_BT_ERROR;
}
- elided_cleanup = make_cleanup_py_decref (elided);
if (elided != Py_None)
{
@@ -1397,17 +1383,15 @@ py_print_frame (PyObject *filter, int flags,
if (! out->is_mi_like_p ())
indent++;
- while ((item = PyIter_Next (elided)))
+ while ((item = PyIter_Next (elided.get ())))
{
- struct cleanup *item_cleanup = make_cleanup_py_decref (item);
+ gdbpy_ref item_ref (item);
enum ext_lang_bt_status success = py_print_frame (item, flags,
args_type, out,
indent,
levels_printed);
- do_cleanups (item_cleanup);
-
if (success == EXT_LANG_BT_ERROR)
{
do_cleanups (cleanup_stack);
@@ -1420,7 +1404,6 @@ py_print_frame (PyObject *filter, int flags,
return EXT_LANG_BT_ERROR;
}
}
- do_cleanups (elided_cleanup);
}
do_cleanups (cleanup_stack);