From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45511 invoked by alias); 4 Apr 2017 17:33:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 45499 invoked by uid 89); 4 Apr 2017 17:33:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ari, Hx-languages-length:3296 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Apr 2017 17:33:08 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 310A596EF for ; Tue, 4 Apr 2017 17:26:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 310A596EF Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 310A596EF Received: from cascais.lan (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7DF57E484 for ; Tue, 4 Apr 2017 17:26:09 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 12/18] -Wwrite-strings: More fix-old-Python-API wrappers Date: Tue, 04 Apr 2017 17:33:00 -0000 Message-Id: <1491326751-16180-13-git-send-email-palves@redhat.com> In-Reply-To: <1491326751-16180-1-git-send-email-palves@redhat.com> References: <1491326751-16180-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-04/txt/msg00045.txt.bz2 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: yyyy-mm-dd Pedro Alves * 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. --- gdb/python/python-internal.h | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) 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 +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 (method), + const_cast (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 (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 (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 (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" -- 2.5.5