public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-pmuldoon-python-backtrace: Fix some memory leaks and reorganize tuple interrogation
@ 2012-04-26 13:24 pmuldoon
0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2012-04-26 13:24 UTC (permalink / raw)
To: archer-commits
The branch, archer-pmuldoon-python-backtrace has been updated
via e4ca4731c3094c5e61bd20effc10012341be942b (commit)
from 6560e7ffa74235e628c2817727b7393c6bd14e99 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit e4ca4731c3094c5e61bd20effc10012341be942b
Author: Phil Muldoon <pmuldoon@redhat.com>
Date: Thu Apr 26 14:23:53 2012 +0100
Fix some memory leaks and reorganize tuple interrogation
-----------------------------------------------------------------------
Summary of changes:
gdb/python/py-framefilter.c | 380 ++++++++++++++++++++++---------------------
1 files changed, 191 insertions(+), 189 deletions(-)
First 500 lines of diff:
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index c1d44e4..fec12f3 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -44,14 +44,17 @@ search_frame_filter_list (PyObject *list, PyObject *frame,
{
Py_ssize_t list_size, list_index;
- PyObject *function;
PyObject *filter = NULL;
- PyObject *slimit;
- PyObject *arg;
+ PyObject *slimit = PyLong_FromLong (limit);
+
+ if (! slimit)
+ return NULL;
list_size = PyList_Size (list);
for (list_index = 0; list_index < list_size; list_index++)
{
+ PyObject *function;
+
function = PyList_GetItem (list, list_index);
if (! function)
return NULL;
@@ -74,13 +77,19 @@ search_frame_filter_list (PyObject *list, PyObject *frame,
continue;
}
- slimit = PyLong_FromLong (limit);
filter = PyObject_CallFunctionObjArgs (function, frame, slimit, NULL);
+ Py_DECREF (slimit);
if (! filter)
- return NULL;
+ {
+ Py_DECREF (slimit);
+ return NULL;
+ }
else if (filter != Py_None)
- return filter;
+ {
+ Py_DECREF (slimit);
+ return filter;
+ }
Py_DECREF (filter);
}
@@ -218,7 +227,6 @@ py_print_locals (PyObject *filter,
struct value_print_options opts)
{
int indent = 4;
- struct ui_stream *stb;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
if (PyObject_HasAttrString (filter, "frame_locals"))
@@ -242,96 +250,91 @@ py_print_locals (PyObject *filter,
size = PyList_Size (result);
- if (size > 0)
+ for (list_index = 0; list_index < size; list_index++)
{
- for (list_index = 0; list_index < size; list_index++)
+ PyObject *sym_tuple, *sym, *value;
+ char *sym_name;
+ struct value *val;
+ struct symbol *symbol;
+
+ sym_tuple = PyList_GetItem (result, list_index);
+ if (! sym_tuple)
+ goto locals_error;
+
+ if (! PyTuple_Check (sym_tuple)
+ && PyTuple_Size (sym_tuple) != 2)
{
- PyObject *sym_tuple, *sym, *value;
- char *sym_name;
- struct value *val;
- struct symbol *symbol;
+ PyErr_SetString (PyExc_RuntimeError,
+ _("frame_locals list must contain a Python tuple."));
+ goto locals_error;
+ }
- sym_tuple = PyList_GetItem (result, list_index);
- if (! sym_tuple)
- goto locals_error;
+ /* Each element in the locals arguments list should be a
+ tuple containing two elements. The local name,
+ which can be a string or a gdb.Symbol, and the
+ value. */
- if (! PyTuple_Check (sym_tuple)
- && PyTuple_Size (sym_tuple) != 2)
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("frame_locals list must contain a Python tuple."));
- goto locals_error;
- }
-
- /* Each element in the locals arguments list should be a
- tuple containing two elements. The local name,
- which can be a string or a gdb.Symbol, and the
- value. */
-
- /* Name. */
- sym = PyTuple_GetItem (sym_tuple, 0);
- if (! sym)
- goto locals_error;
-
- /* Value. */
- value = PyTuple_GetItem (sym_tuple, 1);
- if (! value)
+ /* Name. */
+ sym = PyTuple_GetItem (sym_tuple, 0);
+ if (! sym)
+ goto locals_error;
+
+ /* Value. */
+ value = PyTuple_GetItem (sym_tuple, 1);
+ if (! value)
+ goto locals_error;
+
+ /* For arg name, the user can return a symbol or a
+ string. */
+ if (PyString_Check (sym))
+ {
+ sym_name = python_string_to_host_string (sym);
+ language = current_language;
+ if (! sym_name)
goto locals_error;
+ }
+ else
+ {
+ symbol = symbol_object_to_symbol (sym);
+ sym_name = xstrdup (SYMBOL_PRINT_NAME (symbol));
- /* For arg name, the user can return a symbol or a
- string. */
- if (PyString_Check (sym))
- {
- sym_name = python_string_to_host_string (sym);
- language = current_language;
- if (! sym_name)
- goto locals_error;
- }
+ if (language_mode == language_mode_auto)
+ language = language_def (SYMBOL_LANGUAGE (symbol));
else
- {
- symbol = symbol_object_to_symbol (sym);
- sym_name = xstrdup (SYMBOL_PRINT_NAME (symbol));
-
- if (language_mode == language_mode_auto)
- language = language_def (SYMBOL_LANGUAGE (symbol));
- else
- language = current_language;
- }
-
- fprintf_filtered (gdb_stdout, "%s%s = ",
- n_spaces (2 * indent), sym_name);
-
- xfree (sym_name);
- val = value_object_to_value (value);
- if (! val)
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("Invalid value in frame."));
-
- goto locals_error;
- }
-
- TRY_CATCH (except, RETURN_MASK_ERROR)
- {
- opts.deref_ref = 1;
- common_val_print (val, gdb_stdout, indent, &opts, language);
- }
- if (except.reason < 0)
- {
- PyErr_SetString (PyExc_RuntimeError,
- except.message);
- goto locals_error;
- }
- fprintf_filtered (gdb_stdout, "\n");
-
- gdb_flush (gdb_stdout);
+ language = current_language;
+ }
+
+ fprintf_filtered (gdb_stdout, "%s%s = ",
+ n_spaces (2 * indent), sym_name);
+ xfree (sym_name);
+
+ val = value_object_to_value (value);
+ if (! val)
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ _("Invalid value in frame."));
+ goto locals_error;
+ }
+
+ TRY_CATCH (except, RETURN_MASK_ERROR)
+ {
+ opts.deref_ref = 1;
+ common_val_print (val, gdb_stdout, indent, &opts, language);
+ }
+ if (except.reason < 0)
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ except.message);
+ goto locals_error;
}
+ fprintf_filtered (gdb_stdout, "\n");
+
+ gdb_flush (gdb_stdout);
}
}
else
goto locals_error;
}
-
do_cleanups (old_chain);
return 1;
@@ -379,102 +382,100 @@ py_print_args (PyObject *filter,
size = PyList_Size (result);
- if (size > 0)
+ for (list_index = 0; list_index < size; list_index++)
{
- for (list_index = 0; list_index < size; list_index++)
+ PyObject *sym_tuple, *sym, *value;
+ const char *sym_name;
+ struct value *val;
+ struct symbol *symbol;
+
+ sym_tuple = PyList_GetItem (result, list_index);
+ if (! sym_tuple)
+ goto args_error;
+
+ if (! PyTuple_Check (sym_tuple)
+ && PyTuple_Size (sym_tuple) != 2)
{
- PyObject *sym_tuple, *sym, *value;
- const char *sym_name;
- struct value *val;
- struct symbol *symbol;
+ PyErr_SetString (PyExc_RuntimeError,
+ _("frame_arg list must contain a Python tuple."));
+ goto args_error;
+ }
- sym_tuple = PyList_GetItem (result, list_index);
- if (! sym_tuple)
- goto args_error;
+ /* Each element in the frame arguments list should be a
+ tuple containing two elements. The argument name,
+ which can be a string or a gdb.Symbol, and the
+ value. */
- if (! PyTuple_Check (sym_tuple)
- && PyTuple_Size (sym_tuple) != 2)
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("frame_arg list must contain a Python tuple."));
- goto args_error;
- }
-
- /* Each element in the frame arguments list should be a
- tuple containing two elements. The argument name,
- which can be a string or a gdb.Symbol, and the
- value. */
-
- /* Name. */
- sym = PyTuple_GetItem (sym_tuple, 0);
- if (! sym)
- goto args_error;
-
- /* Value. */
- value = PyTuple_GetItem (sym_tuple, 1);
- if (! value)
- goto args_error;
+ /* Name. */
+ sym = PyTuple_GetItem (sym_tuple, 0);
+ if (! sym)
+ goto args_error;
- /* For arg name, the user can return a symbol or a
- string. */
- if (PyString_Check (sym))
- {
- sym_name = PyString_AsString (sym);
- language = current_language;
- if (! sym_name)
- goto args_error;
- }
+ /* Value. */
+ value = PyTuple_GetItem (sym_tuple, 1);
+ if (! value)
+ goto args_error;
+
+ /* For arg name, the user can return a symbol or a
+ string. */
+ if (PyString_Check (sym))
+ {
+ sym_name = PyString_AsString (sym);
+ language = current_language;
+ if (! sym_name)
+ goto args_error;
+ }
+ else
+ {
+ symbol = symbol_object_to_symbol (sym);
+ sym_name = SYMBOL_PRINT_NAME (symbol);
+ if (language_mode == language_mode_auto)
+ language = language_def (SYMBOL_LANGUAGE (symbol));
else
- {
- symbol = symbol_object_to_symbol (sym);
- sym_name = SYMBOL_PRINT_NAME (symbol);
- if (language_mode == language_mode_auto)
- language = language_def (SYMBOL_LANGUAGE (symbol));
- else
- language = current_language;
- }
-
- annotate_arg_begin ();
- ui_out_field_string (out, "name", sym_name);
- ui_out_text (out, "=");
-
- val = value_object_to_value (value);
- if (! val)
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("Invalid value in frame."));
- goto args_error;
- }
-
- annotate_arg_value (value_type (val));
+ language = current_language;
+ }
- opts.deref_ref = 1;
+ annotate_arg_begin ();
+ ui_out_field_string (out, "name", sym_name);
+ ui_out_text (out, "=");
+
+ val = value_object_to_value (value);
+ if (! val)
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ _("Invalid value in frame."));
+ goto args_error;
+ }
+
+ annotate_arg_value (value_type (val));
+
+ opts.deref_ref = 1;
- /* True in "summary" mode, false otherwise. */
- opts.summary = !strcmp (print_args_type, "scalars");
-
- TRY_CATCH (except, RETURN_MASK_ALL)
- {
- common_val_print (val, stb, 2, &opts, language);
- }
- if (except.reason > 0)
- {
- PyErr_SetString (PyExc_RuntimeError,
- except.message);
- goto args_error;
- }
-
- ui_out_field_stream (out, "value", stb);
-
- if (size != 1 && list_index < size-1)
- ui_out_text (out, ", ");
- annotate_arg_end ();
+ /* True in "summary" mode, false otherwise. */
+ opts.summary = !strcmp (print_args_type, "scalars");
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ common_val_print (val, stb, 2, &opts, language);
+ }
+ if (except.reason > 0)
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ except.message);
+ goto args_error;
}
+
+ ui_out_field_stream (out, "value", stb);
+
+ if (size != 1 && list_index < size-1)
+ ui_out_text (out, ", ");
+ annotate_arg_end ();
}
}
else
goto args_error;
}
+
ui_out_text (out, ")");
do_cleanups (old_chain);
@@ -503,28 +504,6 @@ py_print_frame (PyObject *filter,
struct frame_info *frame = NULL;
volatile struct gdb_exception except;
- /* Get the frame. */
- if (PyObject_HasAttrString (filter, "inferior_frame"))
- {
- PyObject *result = PyObject_CallMethod (filter, "inferior_frame", NULL);
-
- if (! result)
- goto error;
- frame = frame_object_to_frame_info (result);
- if (! frame)
- {
- Py_DECREF (result);
- goto error;
- }
- gdbarch = get_frame_arch (frame);
- }
- else
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("frame filter must implement inferior_frame callback."));
- goto error;
- }
-
/* First check to see if this frame is to be omitted. */
if (PyObject_HasAttrString (filter, "omit"))
{
@@ -555,6 +534,30 @@ py_print_frame (PyObject *filter,
goto error;
}
+ /* Get the frame. */
+ if (PyObject_HasAttrString (filter, "inferior_frame"))
+ {
+ PyObject *result = PyObject_CallMethod (filter, "inferior_frame", NULL);
+
+ if (! result)
+ goto error;
+ frame = frame_object_to_frame_info (result);
+ if (! frame)
+ {
+ Py_DECREF (result);
+ goto error;
+ }
+
+ Py_DECREF (result);
+ gdbarch = get_frame_arch (frame);
+ }
+ else
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ _("frame filter must implement inferior_frame callback."));
+ goto error;
+ }
+
if (PyObject_HasAttrString (filter, "elide"))
{
PyObject *result = PyObject_CallMethod (filter, "elide", NULL);
@@ -592,7 +595,6 @@ py_print_frame (PyObject *filter,
PyObject *result = PyObject_CallMethod (filter, "level", "i",
frame_relative_level (frame),
NULL);
-
if (result)
{
level = PyLong_AsLong (result);
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-04-26 13:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-26 13:24 [SCM] archer-pmuldoon-python-backtrace: Fix some memory leaks and reorganize tuple interrogation pmuldoon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).