From 2adadf517063fb1c3b9240bf99ad339968c12f15 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 5 Apr 2017 19:21:36 +0100 Subject: -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 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 * 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. --- gdb/python/py-breakpoint.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gdb/python/py-breakpoint.c') diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 34f46fb..a08501e 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -637,8 +637,8 @@ bppy_get_ignore_count (PyObject *self, void *closure) static int bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) { - static char *keywords[] = { "spec", "type", "wp_class", "internal", - "temporary", NULL }; + static const char *keywords[] = { "spec", "type", "wp_class", "internal", + "temporary", NULL }; const char *spec; int type = bp_breakpoint; int access_type = hw_write; @@ -647,9 +647,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) int internal_bp = 0; int temporary_bp = 0; - if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords, - &spec, &type, &access_type, - &internal, &temporary)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords, + &spec, &type, &access_type, + &internal, &temporary)) return -1; if (internal) -- cgit v1.1