[PATCH 1/3] Use gdbpy_convert_exception in a few more spots

Tom Tromey tom@tromey.com
Tue Dec 25 19:54:00 GMT 2018


I noticed a few places were converting a gdb exception to a Python
exception "by hand".  It's better to use the existing
gdbpy_convert_exception helper function, as this handles memory errors
correctly, and in the future may be enhanced in other ways.

gdb/ChangeLog
2018-12-25  Tom Tromey  <tom@tromey.com>

	* python/py-value.c (convert_value_from_python): Use
	gdbpy_convert_exception.
	* python/py-param.c (parmpy_init): Use gdbpy_convert_exception.
	* python/py-cmd.c (cmdpy_init): Use gdbpy_convert_exception.
	* python/py-breakpoint.c (bppy_init): Use
	gdbpy_convert_exception.
---
 gdb/ChangeLog              | 9 +++++++++
 gdb/python/py-breakpoint.c | 4 +---
 gdb/python/py-cmd.c        | 4 +---
 gdb/python/py-param.c      | 4 +---
 gdb/python/py-value.c      | 4 +---
 5 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index d144bcf2e6..29f6761554 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -874,9 +874,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   CATCH (except, RETURN_MASK_ALL)
     {
       bppy_pending_object = NULL;
-      PyErr_Format (except.reason == RETURN_QUIT
-		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
-		    "%s", except.message);
+      gdbpy_convert_exception (except);
       return -1;
     }
   END_CATCH
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index d560b3a44e..0f0e298e7d 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -585,9 +585,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
       xfree (docstring);
       xfree (pfx_name);
       Py_DECREF (self);
-      PyErr_Format (except.reason == RETURN_QUIT
-		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
-		    "%s", except.message);
+      gdbpy_convert_exception (except);
       return -1;
     }
   END_CATCH
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index bff5d60fc2..f8b151f098 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -738,9 +738,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
     {
       xfree (cmd_name);
       Py_DECREF (self);
-      PyErr_Format (except.reason == RETURN_QUIT
-		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
-		    "%s", except.message);
+      gdbpy_convert_exception (except);
       return -1;
     }
   END_CATCH
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index d21c2faf64..430415b2f9 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1732,9 +1732,7 @@ convert_value_from_python (PyObject *obj)
     }
   CATCH (except, RETURN_MASK_ALL)
     {
-      PyErr_Format (except.reason == RETURN_QUIT
-		    ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
-		    "%s", except.message);
+      gdbpy_convert_exception (except);
       return NULL;
     }
   END_CATCH
-- 
2.17.2



More information about the Gdb-patches mailing list