diff options
author | Pedro Alves <palves@redhat.com> | 2017-04-05 19:21:36 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-04-05 19:21:36 +0100 |
commit | 2adadf517063fb1c3b9240bf99ad339968c12f15 (patch) | |
tree | 1241341dc4b5e2b42e4cd3d58726f72d5a570c16 /gdb/python/py-inferior.c | |
parent | 0d1f4ceb3904c4c82231adf98f0e84f37bc8d4ea (diff) | |
download | gdb-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-inferior.c')
-rw-r--r-- | gdb/python/py-inferior.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 77fc543..4b43c54 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -435,10 +435,10 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) CORE_ADDR addr, length; gdb_byte *buffer = NULL; PyObject *addr_obj, *length_obj, *result; - static char *keywords[] = { "address", "length", NULL }; + static const char *keywords[] = { "address", "length", NULL }; - if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords, - &addr_obj, &length_obj)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords, + &addr_obj, &length_obj)) return NULL; if (get_addr_from_python (addr_obj, &addr) < 0 @@ -494,21 +494,20 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) const gdb_byte *buffer; CORE_ADDR addr, length; PyObject *addr_obj, *length_obj = NULL; - static char *keywords[] = { "address", "buffer", "length", NULL }; + static const char *keywords[] = { "address", "buffer", "length", NULL }; #ifdef IS_PY3K Py_buffer pybuf; - if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords, - &addr_obj, &pybuf, - &length_obj)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords, + &addr_obj, &pybuf, &length_obj)) return NULL; buffer = (const gdb_byte *) pybuf.buf; buf_len = pybuf.len; #else - if (! PyArg_ParseTupleAndKeywords (args, kw, "Os#|O", keywords, - &addr_obj, &buffer, &buf_len, - &length_obj)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "Os#|O", keywords, + &addr_obj, &buffer, &buf_len, + &length_obj)) return NULL; buffer = (const gdb_byte *) buffer; @@ -643,7 +642,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) { struct gdb_exception except = exception_none; CORE_ADDR start_addr, length; - static char *keywords[] = { "address", "length", "pattern", NULL }; + static const char *keywords[] = { "address", "length", "pattern", NULL }; PyObject *start_addr_obj, *length_obj; Py_ssize_t pattern_size; const gdb_byte *buffer; @@ -652,9 +651,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) #ifdef IS_PY3K Py_buffer pybuf; - if (! PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords, - &start_addr_obj, &length_obj, - &pybuf)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords, + &start_addr_obj, &length_obj, + &pybuf)) return NULL; buffer = (const gdb_byte *) pybuf.buf; @@ -663,9 +662,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) PyObject *pattern; const void *vbuffer; - if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO", keywords, - &start_addr_obj, &length_obj, - &pattern)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OOO", keywords, + &start_addr_obj, &length_obj, + &pattern)) return NULL; if (!PyObject_CheckReadBuffer (pattern)) |