This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
Hi Pedro
I found a typo ...
On Tue, 4 Apr 2017 18:25:46 +0100
Pedro Alves <palves@redhat.com> wrote:
[...]
> diff --git a/gdb/python/python-internal.h
> b/gdb/python/python-internal.h index 55efd75..8fc89cd 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -286,6 +286,38 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR
> *path)
>
> #define PySys_SetPath gdb_PySys_SetPath
>
> +/* Wrap PyGetSetDef to allow convenient construction with string
> + literals. Unfortunately, PyGetSetDef's 'name' and 'doc' members
> + are 'char *' instead of 'const char *', meaning that in order to
> + list-initialize PyGetSetDef arrays with string literals (and
> + without the wrapping below) would require writing explicit 'char *'
> + casts. Instead, we extend PyGetSetDef and add onstexpr
^^^^^^^^
... here
> + constructors that accept const 'name' and 'doc', hiding the ugly
> + casts here in a single place. */
> +
> +struct gdb_PyGetSetDef : PyGetSetDef
> +{
> + constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter
> set_,
> + const char *doc_, void *closure_)
> + : PyGetSetDef {const_cast<char *> (name_), get_, set_,
> + const_cast<char *> (doc_), closure_}
> + {}
> +
> + /* Alternative constructor that allows omitting the closure in list
> + initialization. */
> + constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter
> set_,
> + const char *doc_)
> + : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
> + {}
> +
> + /* Constructor for the sentinel entries. */
> + constexpr gdb_PyGetSetDef (std::nullptr_t)
> + : gdb_PyGetSetDef { NULL, NULL, NULL, NULL, NULL }
> + {}
> +};
> +
> +#define PyGetSetDef gdb_PyGetSetDef
> +
> /* In order to be able to parse symtab_and_line_to_sal_object
> function a real symtab_and_line structure is needed. */
> #include "symtab.h"