aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-symbol.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-04-05 19:21:36 +0100
committerPedro Alves <palves@redhat.com>2017-04-05 19:21:36 +0100
commit2adadf517063fb1c3b9240bf99ad339968c12f15 (patch)
tree1241341dc4b5e2b42e4cd3d58726f72d5a570c16 /gdb/python/py-symbol.c
parent0d1f4ceb3904c4c82231adf98f0e84f37bc8d4ea (diff)
downloadgdb-2adadf517063fb1c3b9240bf99ad339968c12f15.zip
gdb-2adadf517063fb1c3b9240bf99ad339968c12f15.tar.gz
gdb-2adadf517063fb1c3b9240bf99ad339968c12f15.tar.bz2
-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.
Diffstat (limited to 'gdb/python/py-symbol.c')
-rw-r--r--gdb/python/py-symbol.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 05b002f..c9f83a3 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -373,13 +373,14 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
int domain = VAR_DOMAIN;
struct field_of_this_result is_a_field_of_this;
const char *name;
- static char *keywords[] = { "name", "block", "domain", NULL };
+ static const char *keywords[] = { "name", "block", "domain", NULL };
struct symbol *symbol = NULL;
PyObject *block_obj = NULL, *sym_obj, *bool_obj;
const struct block *block = NULL;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
- &block_object_type, &block_obj, &domain))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
+ &block_object_type, &block_obj,
+ &domain))
return NULL;
if (block_obj)
@@ -443,12 +444,12 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
{
int domain = VAR_DOMAIN;
const char *name;
- static char *keywords[] = { "name", "domain", NULL };
+ static const char *keywords[] = { "name", "domain", NULL };
struct symbol *symbol = NULL;
PyObject *sym_obj;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
- &domain))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
+ &domain))
return NULL;
TRY