diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2011-10-27 10:29:58 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2011-10-27 10:29:58 +0000 |
commit | f77b9a5df0dca976e9fa9c8731c313d5b54befe1 (patch) | |
tree | 4e62fbc1927a221759c1e9dc70ef8657124b52d8 /gdb | |
parent | c28a9f495181d46aa6644c6dfd4e48756ca4a437 (diff) | |
download | binutils-f77b9a5df0dca976e9fa9c8731c313d5b54befe1.zip binutils-f77b9a5df0dca976e9fa9c8731c313d5b54befe1.tar.gz binutils-f77b9a5df0dca976e9fa9c8731c313d5b54befe1.tar.bz2 |
2011-10-27 Phil Muldoon <pmuldoon@redhat.com>
PR python/13331
* python/py-function.c (fnpy_call): Check 'args' is not NULL.
(convert_values_to_python): Return on Python tuple allocation
failure. Return NULL on value conversion error.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/python/py-function.c | 32 |
2 files changed, 31 insertions, 9 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4acd4e5..f05a246 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2011-10-27 Phil Muldoon <pmuldoon@redhat.com> + PR python/13331 + + * python/py-function.c (fnpy_call): Check 'args' is not NULL. + (convert_values_to_python): Return on Python tuple allocation + failure. Return NULL on value conversion error. + +2011-10-27 Phil Muldoon <pmuldoon@redhat.com> + * python/py-breakpoint.c (bppy_set_enabled): Use TRY_CATCH. (bppy_set_task): Ditto. (bppy_delete_breakpoint): Ditto. diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c index dc78b29..de7e94c 100644 --- a/gdb/python/py-function.c +++ b/gdb/python/py-function.c @@ -38,6 +38,9 @@ convert_values_to_python (int argc, struct value **argv) { int i; PyObject *result = PyTuple_New (argc); + + if (! result) + return NULL; for (i = 0; i < argc; ++i) { @@ -45,7 +48,7 @@ convert_values_to_python (int argc, struct value **argv) if (! elt) { Py_DECREF (result); - error (_("Could not convert value to Python object.")); + return NULL; } PyTuple_SetItem (result, i, elt); } @@ -59,24 +62,35 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language, void *cookie, int argc, struct value **argv) { struct value *value = NULL; - PyObject *result, *callable, *args; + /* 'result' must be set to NULL, this initially indicates whether + the function was called, or not. */ + PyObject *result = NULL; + PyObject *callable, *args; struct cleanup *cleanup; cleanup = ensure_python_env (gdbarch, language); args = convert_values_to_python (argc, argv); + /* convert_values_to_python can return NULL on error. If we + encounter this, do not call the function, but allow the Python -> + error code conversion below to deal with the Python exception. + Note, that this is different if the function simply does not + have arguments. */ - callable = PyObject_GetAttrString ((PyObject *) cookie, "invoke"); - if (! callable) + if (args) { + callable = PyObject_GetAttrString ((PyObject *) cookie, "invoke"); + if (! callable) + { + Py_DECREF (args); + error (_("No method named 'invoke' in object.")); + } + + result = PyObject_Call (callable, args, NULL); + Py_DECREF (callable); Py_DECREF (args); - error (_("No method named 'invoke' in object.")); } - result = PyObject_Call (callable, args, NULL); - Py_DECREF (callable); - Py_DECREF (args); - if (!result) { PyObject *ptype, *pvalue, *ptraceback; |