Re: [PATCH] Add gdb.Value.format_string ()

Kevin Buettner
2019-03-17T20:50:29Z

Hi Marco,

Overall, I like this patch. See below for my comments.

Kevin

On Sat, 16 Mar 2019 11:18:36 +0000
Marco Barisione <mbarisione@undo.io> wrote:

> gdb/doc/ChangeLog:
>
> 2019-03-16 Marco Barisione <mbarisione@undo.io>
>
> * python.texi: Document gdb.Value.format_string ()

A period is needed at the end of this ChangeLog entry.

> diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
> index dd6a536b6a..46a0f563e4 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -588,6 +588,162 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
> encoding, errors);
> }
>
> +/* Given a Python object, copy its truth value to a C int (the value
> + pointed by dest).
> + If src_obj is NULL, then *dest is not modified.
> +
> + Return 1 in case of success, -1 otherwise. */

Why not use a bool return type to indicate success or failure?

> +
> +static int
> +copy_py_bool_obj (int *dest, PyObject *src_obj)
> +{
> + if (src_obj)
> + {
> + int cmp = PyObject_IsTrue (src_obj);
> + if (cmp < 0)
> + return -1;
> + *dest = cmp;
> + }
> +
> + return 1;
> +}