Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
Commit Message
The attached patch wraps PyObject_GetAttrString and
PyObject_HasAttrString in internal functions which have const
qualifier for the second argument. This is required because these
functions were missing the const qualifier in Python-2.4.
ChangeLog
2014-06-09 Siva Chandra Reddy <sivachandra@google.com>
* python/python-internal.h (gdb_PyObject_GetAttrString)
(gdb_PyObject_HasAttrString): New inline function definitions.
* py-value.c (get_field_flag): Remove the now unnecessary cast to
(char *) of the second argument to PyObject_GetAttrString.
Comments
On 06/09/2014 02:42 PM, Siva Chandra wrote:
> +/* The second argument to PyObject_GetAttrString was missing the 'const'
> + qualifier. Hence, we wrap it in a function to avoid errors when compiled
> + with -Werror against Python 2.4. */
I'd suggest moving the "in Python 2.4" to the first sentence, like:
/* The second argument to PyObject_GetAttrString was missing the 'const'
qualifier in Python 2.4. Hence, we wrap it in a function to avoid errors
when compiled with -Werror. */
Otherwise looks great to me.
Thanks!
On 06/09/2014 02:42 PM, Siva Chandra wrote:
> @@ -555,7 +555,7 @@ get_field_flag (PyObject *field, const char *flag_name)
> {
> int flag_value;
> /* Python 2.4 did not have a 'const' here. */
Oh, and this comment is stale here now.
> - PyObject *flag_object = PyObject_GetAttrString (field, (char *) flag_name);
> + PyObject *flag_object = PyObject_GetAttrString (field, flag_name);
Thanks for the quick review. I have pushed the attached patch which
includes the doc fixes suggested by Pedro.
@@ -555,7 +555,7 @@ get_field_flag (PyObject *field, const char *flag_name)
{
int flag_value;
/* Python 2.4 did not have a 'const' here. */
- PyObject *flag_object = PyObject_GetAttrString (field, (char *) flag_name);
+ PyObject *flag_object = PyObject_GetAttrString (field, flag_name);
if (flag_object == NULL)
return -1;
@@ -187,6 +187,32 @@ gdb_Py_DECREF (void *op) /* ARI: editCase function */
#undef Py_DECREF
#define Py_DECREF(op) gdb_Py_DECREF (op)
+/* The second argument to PyObject_GetAttrString was missing the 'const'
+ qualifier. Hence, we wrap it in a function to avoid errors when compiled
+ with -Werror against Python 2.4. */
+
+static inline PyObject *
+gdb_PyObject_GetAttrString (PyObject *obj,
+ const char *attr) /* ARI: editCase function */
+{
+ return PyObject_GetAttrString (obj, (char *) attr);
+}
+
+#define PyObject_GetAttrString(obj, attr) gdb_PyObject_GetAttrString (obj, attr)
+
+/* The second argument to PyObject_HasAttrString was also missing the 'const'
+ qualifier. Hence, we wrap it also in a function to avoid errors when
+ compiled with -Werror against Python 2.4. */
+
+static inline int
+gdb_PyObject_HasAttrString (PyObject *obj,
+ const char *attr) /* ARI: editCase function */
+{
+ return PyObject_HasAttrString (obj, (char *) attr);
+}
+
+#define PyObject_HasAttrString(obj, attr) gdb_PyObject_HasAttrString (obj, attr)
+
/* 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"