This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] -Wwrite-strings: More fix-old-Python-API wrappers


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4d75997912d77497fd395fde222513436a7df046

commit 4d75997912d77497fd395fde222513436a7df046
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Apr 5 19:21:35 2017 +0100

    -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.

Diff:
---
 gdb/ChangeLog                |  8 ++++++
 gdb/python/python-internal.h | 63 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fe1243b..9430d3a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 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.
+
+2017-04-05  Pedro Alves  <palves@redhat.com>
+
 	* mi/mi-cmd-info.c (mi_cmd_info_os): Call info_osdata instead of
 	info_osdata_command.
 	* osdata.c (info_osdata_command): Rename to ...
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"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]