mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-07 08:03:07 +00:00
-Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload
-Wwrite-strings flags code like:
static char *keywords[] = {"command", "from_tty", "to_string", NULL };
as needing "(char *)" casts, because string literals are "const char []".
We can get rid of the casts by changing the array type like this:
- static char *keywords[] = {"command", "from_tty", "to_string", NULL };
+ static const char *keywords[] = {"command", "from_tty", "to_string", NULL };
However, passing the such array to PyArg_ParseTupleAndKeywords no longer
works OOTB, because PyArg_ParseTupleAndKeywords expects a "char **":
PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw,
const char *format,
char *keywords[], ...);
and "const char **" is not implicitly convertible to "char **". C++
is more tolerant that C here WRT aliasing, and a const_cast<char **>
is fine. However, to avoid having all callers do the cast themselves,
this commit defines a gdb_PyArg_ParseTupleAndKeywords function here
with a corresponding 'keywords' parameter type that does the cast in a
single place.
gdb/ChangeLog:
2017-04-05 Pedro Alves <palves@redhat.com>
* python/python-internal.h (gdb_PyArg_ParseTupleAndKeywords): New
static inline function.
* python/py-arch.c (archpy_disassemble): Constify 'keywords'
array and use gdb_PyArg_ParseTupleAndKeywords.
* python/py-cmd.c (cmdpy_init): Likewise.
* python/py-finishbreakpoint.c (bpfinishpy_init): Likewise.
* python/py-inferior.c (infpy_read_memory, infpy_write_memory)
(infpy_search_memory): Likewise.
* python/py-objfile.c (objfpy_add_separate_debug_file)
(gdbpy_lookup_objfile): Likewise.
* python/py-symbol.c (gdbpy_lookup_symbol)
(gdbpy_lookup_global_symbol): Likewise.
* python/py-type.c (gdbpy_lookup_type): Likewise.
* python/py-value.c (valpy_lazy_string, valpy_string): Likewise.
* python/python.c (execute_gdb_command, gdbpy_write, gdbpy_flush):
Likewise.
This commit is contained in:
@@ -432,13 +432,13 @@ objfpy_is_valid (PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
static char *keywords[] = { "file_name", NULL };
|
||||
static const char *keywords[] = { "file_name", NULL };
|
||||
objfile_object *obj = (objfile_object *) self;
|
||||
const char *file_name;
|
||||
|
||||
OBJFPY_REQUIRE_VALID (obj);
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
|
||||
if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
|
||||
return NULL;
|
||||
|
||||
TRY
|
||||
@@ -559,14 +559,14 @@ objfpy_lookup_objfile_by_build_id (const char *build_id)
|
||||
PyObject *
|
||||
gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
static char *keywords[] = { "name", "by_build_id", NULL };
|
||||
static const char *keywords[] = { "name", "by_build_id", NULL };
|
||||
const char *name;
|
||||
PyObject *by_build_id_obj = NULL;
|
||||
int by_build_id;
|
||||
struct objfile *objfile;
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
|
||||
&name, &PyBool_Type, &by_build_id_obj))
|
||||
if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
|
||||
&name, &PyBool_Type, &by_build_id_obj))
|
||||
return NULL;
|
||||
|
||||
by_build_id = 0;
|
||||
|
||||
Reference in New Issue
Block a user