+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.
+
2017-04-05 Pedro Alves <palves@redhat.com>
* python/python-internal.h (gdb_PyGetSetDef): New type.
static PyObject *
archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = { "start_pc", "end_pc", "count", NULL };
+ static const char *keywords[] = { "start_pc", "end_pc", "count", NULL };
CORE_ADDR start, end = 0;
CORE_ADDR pc;
gdb_py_ulongest start_temp;
ARCHPY_REQUIRE_VALID (self, gdbarch);
- if (!PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO", keywords,
- &start_temp, &end_obj, &count_obj))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO",
+ keywords, &start_temp, &end_obj,
+ &count_obj))
return NULL;
start = start_temp;
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;
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)
char *docstring = NULL;
struct cmd_list_element **cmd_list;
char *cmd_name, *pfx_name;
- static char *keywords[] = { "name", "command_class", "completer_class",
- "prefix", NULL };
+ static const char *keywords[] = { "name", "command_class", "completer_class",
+ "prefix", NULL };
PyObject *is_prefix = NULL;
int cmp;
return -1;
}
- if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
- keywords, &name, &cmdtype,
- &completetype, &is_prefix))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
+ keywords, &name, &cmdtype,
+ &completetype, &is_prefix))
return -1;
if (cmdtype != no_class && cmdtype != class_run
static int
bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
{
- static char *keywords[] = { "frame", "internal", NULL };
+ static const char *keywords[] = { "frame", "internal", NULL };
struct finish_breakpoint_object *self_bpfinish =
(struct finish_breakpoint_object *) self;
PyObject *frame_obj = NULL;
CORE_ADDR pc;
struct symbol *function;
- if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
- &frame_obj, &internal))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
+ &frame_obj, &internal))
return -1;
TRY
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
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;
{
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;
#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;
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))
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
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;
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)
{
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
PyObject *
gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = { "name", "block", NULL };
+ static const char *keywords[] = { "name", "block", NULL };
const char *type_name = NULL;
struct type *type = NULL;
PyObject *block_obj = NULL;
const struct block *block = NULL;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
- &type_name, &block_obj))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
+ &type_name, &block_obj))
return NULL;
if (block_obj)
gdb_py_longest length = -1;
struct value *value = ((value_object *) self)->value;
const char *user_encoding = NULL;
- static char *keywords[] = { "encoding", "length", NULL };
+ static const char *keywords[] = { "encoding", "length", NULL };
PyObject *str_obj = NULL;
- if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
- &user_encoding, &length))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG,
+ keywords, &user_encoding, &length))
return NULL;
if (length < -1)
const char *user_encoding = NULL;
const char *la_encoding = NULL;
struct type *char_type;
- static char *keywords[] = { "encoding", "errors", "length", NULL };
+ static const char *keywords[] = { "encoding", "errors", "length", NULL };
- if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
- &user_encoding, &errors, &length))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
+ &user_encoding, &errors, &length))
return NULL;
TRY
{}
};
+/* The 'keywords' parameter of PyArg_ParseTupleAndKeywords has type
+ 'char **'. However, string literals are const in C++, and so to
+ avoid casting at every keyword array definition, we'll need to make
+ the keywords array an array of 'const char *'. To avoid having all
+ callers add a 'const_cast<char **>' themselves when passing such an
+ array through 'char **', we define our own version of
+ PyArg_ParseTupleAndKeywords here with a corresponding 'keywords'
+ parameter type that does the cast in a single place. (This is not
+ an overload of PyArg_ParseTupleAndKeywords in order to make it
+ clearer that we're calling our own function instead of a function
+ that exists in some newer Python version.) */
+
+static inline int
+gdb_PyArg_ParseTupleAndKeywords (PyObject *args, PyObject *kw,
+ const char *format, const char **keywords, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start (ap, keywords);
+ res = PyArg_VaParseTupleAndKeywords (args, kw, format,
+ const_cast<char **> (keywords),
+ ap);
+ va_end (ap);
+
+ return res;
+}
+
/* 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"
const char *arg;
PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
int from_tty, to_string;
- static char *keywords[] = {"command", "from_tty", "to_string", NULL };
+ static const char *keywords[] = { "command", "from_tty", "to_string", NULL };
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
- &PyBool_Type, &from_tty_obj,
- &PyBool_Type, &to_string_obj))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
+ &PyBool_Type, &from_tty_obj,
+ &PyBool_Type, &to_string_obj))
return NULL;
from_tty = 0;
gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
{
const char *arg;
- static char *keywords[] = {"text", "stream", NULL };
+ static const char *keywords[] = { "text", "stream", NULL };
int stream_type = 0;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
- &stream_type))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
+ &stream_type))
return NULL;
TRY
static PyObject *
gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
{
- static char *keywords[] = {"stream", NULL };
+ static const char *keywords[] = { "stream", NULL };
int stream_type = 0;
- if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
- &stream_type))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
+ &stream_type))
return NULL;
switch (stream_type)