* python/python.c (gdbpy_decode_line): Move cleanup creation out

of TRY_CATCH.  Fix error handling.
	* python/py-value.c (convert_value_from_python): Move 'old'
	declaration to innermost scope.
This commit is contained in:
Tom Tromey 2012-03-30 20:05:55 +00:00
parent f87a302320
commit 9bc3523d11
3 changed files with 30 additions and 9 deletions

View file

@ -1,3 +1,10 @@
2012-03-30 Tom Tromey <tromey@redhat.com>
* python/python.c (gdbpy_decode_line): Move cleanup creation out
of TRY_CATCH. Fix error handling.
* python/py-value.c (convert_value_from_python): Move 'old'
declaration to innermost scope.
2012-03-29 Joel Brobecker <brobecker@adacore.com> 2012-03-29 Joel Brobecker <brobecker@adacore.com>
Andrey Smirnov <andrew.smirnov@gmail.com> Andrey Smirnov <andrew.smirnov@gmail.com>

View file

@ -1250,7 +1250,6 @@ struct value *
convert_value_from_python (PyObject *obj) convert_value_from_python (PyObject *obj)
{ {
struct value *value = NULL; /* -Wall */ struct value *value = NULL; /* -Wall */
struct cleanup *old;
volatile struct gdb_exception except; volatile struct gdb_exception except;
int cmp; int cmp;
@ -1319,6 +1318,8 @@ convert_value_from_python (PyObject *obj)
s = python_string_to_target_string (obj); s = python_string_to_target_string (obj);
if (s != NULL) if (s != NULL)
{ {
struct cleanup *old;
old = make_cleanup (xfree, s); old = make_cleanup (xfree, s);
value = value_cstring (s, strlen (s), builtin_type_pychar); value = value_cstring (s, strlen (s), builtin_type_pychar);
do_cleanups (old); do_cleanups (old);

View file

@ -503,7 +503,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
appease gcc. */ appease gcc. */
struct symtab_and_line sal; struct symtab_and_line sal;
const char *arg = NULL; const char *arg = NULL;
char *copy = NULL; char *copy_to_free = NULL, *copy = NULL;
struct cleanup *cleanups; struct cleanup *cleanups;
PyObject *result = NULL; PyObject *result = NULL;
PyObject *return_result = NULL; PyObject *return_result = NULL;
@ -515,14 +515,14 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
cleanups = make_cleanup (null_cleanup, NULL); cleanups = make_cleanup (null_cleanup, NULL);
sals.sals = NULL;
TRY_CATCH (except, RETURN_MASK_ALL) TRY_CATCH (except, RETURN_MASK_ALL)
{ {
if (arg) if (arg)
{ {
copy = xstrdup (arg); copy = xstrdup (arg);
make_cleanup (xfree, copy); copy_to_free = copy;
sals = decode_line_1 (&copy, 0, 0, 0); sals = decode_line_1 (&copy, 0, 0, 0);
make_cleanup (xfree, sals.sals);
} }
else else
{ {
@ -532,6 +532,13 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
sals.nelts = 1; sals.nelts = 1;
} }
} }
if (sals.sals != NULL && sals.sals != &sal)
{
make_cleanup (xfree, copy_to_free);
make_cleanup (xfree, sals.sals);
}
if (except.reason < 0) if (except.reason < 0)
{ {
do_cleanups (cleanups); do_cleanups (cleanups);
@ -575,7 +582,16 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
} }
if (copy && strlen (copy) > 0) if (copy && strlen (copy) > 0)
{
unparsed = PyString_FromString (copy); unparsed = PyString_FromString (copy);
if (unparsed == NULL)
{
Py_DECREF (result);
Py_DECREF (return_result);
return_result = NULL;
goto error;
}
}
else else
{ {
unparsed = Py_None; unparsed = Py_None;
@ -585,13 +601,10 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
PyTuple_SetItem (return_result, 0, unparsed); PyTuple_SetItem (return_result, 0, unparsed);
PyTuple_SetItem (return_result, 1, result); PyTuple_SetItem (return_result, 1, result);
error:
do_cleanups (cleanups); do_cleanups (cleanups);
return return_result; return return_result;
error:
do_cleanups (cleanups);
return NULL;
} }
/* Parse a string and evaluate it as an expression. */ /* Parse a string and evaluate it as an expression. */