aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-04-05 19:21:35 +0100
committerPedro Alves <palves@redhat.com>2017-04-05 19:21:35 +0100
commit4d75997912d77497fd395fde222513436a7df046 (patch)
tree1e4d20c61eb87f144dbee57e83f677b2b43e09ce /gdb/python
parent21c8a587ab81a58d3e067551d5503a765f00ec6e (diff)
downloadgdb-4d75997912d77497fd395fde222513436a7df046.zip
gdb-4d75997912d77497fd395fde222513436a7df046.tar.gz
gdb-4d75997912d77497fd395fde222513436a7df046.tar.bz2
-Wwrite-strings: More fix-old-Python-API wrappers
When building against Python 2.7, -Wwrite-strings flags several cases of passing a string literal to Python functions that expect a "char *". This commit addresses the issue like we already handle several other similar cases -- wrap the Python API with our own fixed version that adds the necessary constification. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * python/python-internal.h (gdb_PyObject_CallMethod) (gdb_PyErr_NewException, gdb_PySys_GetObject, gdb_PySys_SetPath): New functions. (GDB_PYSYS_SETPATH_CHAR, PyObject_CallMethod, PyErr_NewException) (PySys_GetObject, PySys_SetPath): New macros.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python-internal.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 4dd413d..55efd75 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -223,6 +223,69 @@ gdb_PyObject_HasAttrString (PyObject *obj,
#define PyObject_HasAttrString(obj, attr) gdb_PyObject_HasAttrString (obj, attr)
+/* PyObject_CallMethod's 'method' and 'format' parameters were missing
+ the 'const' qualifier before Python 3.4. Hence, we wrap the
+ function in our own version to avoid errors with string literals.
+ Note, this is a variadic template because PyObject_CallMethod is a
+ varargs function and Python doesn't have a "PyObject_VaCallMethod"
+ variant taking a va_list that we could defer to instead. */
+
+template<typename... Args>
+static inline PyObject *
+gdb_PyObject_CallMethod (PyObject *o, const char *method, const char *format,
+ Args... args) /* ARI: editCase function */
+{
+ return PyObject_CallMethod (o,
+ const_cast<char *> (method),
+ const_cast<char *> (format),
+ args...);
+}
+
+#undef PyObject_CallMethod
+#define PyObject_CallMethod gdb_PyObject_CallMethod
+
+/* The 'name' parameter of PyErr_NewException was missing the 'const'
+ qualifier in Python <= 3.4. Hence, we wrap it in a function to
+ avoid errors when compiled with -Werror. */
+
+static inline PyObject*
+gdb_PyErr_NewException (const char *name, PyObject *base, PyObject *dict)
+{
+ return PyErr_NewException (const_cast<char *> (name), base, dict);
+}
+
+#define PyErr_NewException gdb_PyErr_NewException
+
+/* PySys_GetObject's 'name' parameter was missing the 'const'
+ qualifier before Python 3.4. Hence, we wrap it in a function to
+ avoid errors when compiled with -Werror. */
+
+static inline PyObject *
+gdb_PySys_GetObject (const char *name)
+{
+ return PySys_GetObject (const_cast<char *> (name));
+}
+
+#define PySys_GetObject gdb_PySys_GetObject
+
+/* PySys_SetPath's 'path' parameter was missing the 'const' qualifier
+ before Python 3.6. Hence, we wrap it in a function to avoid errors
+ when compiled with -Werror. */
+
+#ifdef IS_PY3K
+# define GDB_PYSYS_SETPATH_CHAR wchar_t
+#else
+# define GDB_PYSYS_SETPATH_CHAR char
+#endif
+
+static inline void
+gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path)
+{
+ PySys_SetPath (const_cast<GDB_PYSYS_SETPATH_CHAR *> (path));
+}
+
+#define PySys_SetPath gdb_PySys_SetPath
+
/* 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"