* [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
@ 2014-06-09 13:42 Siva Chandra
2014-06-09 13:49 ` Pedro Alves
2014-06-09 13:52 ` Pedro Alves
0 siblings, 2 replies; 6+ messages in thread
From: Siva Chandra @ 2014-06-09 13:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves, Ulrich Weigand
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]
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.
[-- Attachment #2: fix_xmethod_for_2_4_v2.txt --]
[-- Type: text/plain, Size: 1881 bytes --]
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 54da67a..9821990 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -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;
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 9c06621..7cf03b5 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -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"
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
2014-06-09 13:42 [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier Siva Chandra
@ 2014-06-09 13:49 ` Pedro Alves
2014-06-09 13:52 ` Pedro Alves
1 sibling, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2014-06-09 13:49 UTC (permalink / raw)
To: Siva Chandra, gdb-patches; +Cc: Ulrich Weigand
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!
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
2014-06-09 13:42 [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier Siva Chandra
2014-06-09 13:49 ` Pedro Alves
@ 2014-06-09 13:52 ` Pedro Alves
2014-06-10 18:56 ` Siva Chandra
1 sibling, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2014-06-09 13:52 UTC (permalink / raw)
To: Siva Chandra, gdb-patches; +Cc: Ulrich Weigand
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);
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
2014-06-09 13:52 ` Pedro Alves
@ 2014-06-10 18:56 ` Siva Chandra
2014-06-10 18:56 ` Siva Chandra
0 siblings, 1 reply; 6+ messages in thread
From: Siva Chandra @ 2014-06-10 18:56 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, Ulrich Weigand
Thanks for the quick review. I have pushed the attached patch which
includes the doc fixes suggested by Pedro.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
2014-06-10 18:56 ` Siva Chandra
@ 2014-06-10 18:56 ` Siva Chandra
2014-06-11 14:13 ` Ulrich Weigand
0 siblings, 1 reply; 6+ messages in thread
From: Siva Chandra @ 2014-06-10 18:56 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, Ulrich Weigand
[-- Attachment #1: Type: text/plain, Size: 226 bytes --]
On Tue, Jun 10, 2014 at 11:56 AM, Siva Chandra <sivachandra@google.com> wrote:
> Thanks for the quick review. I have pushed the attached patch which
> includes the doc fixes suggested by Pedro.
Ah! The patch is attached now!
[-- Attachment #2: fix_xmethod_for_2_4_final.txt --]
[-- Type: text/plain, Size: 1883 bytes --]
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 54da67a..8532da6 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -554,8 +554,7 @@ static int
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;
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 9c06621..0198e9d 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -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 in Python-2.4. Hence, we wrap it in a function to avoid errors
+ when compiled with -Werror. */
+
+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 in Python-2.4. Hence, we wrap it also in a function to avoid
+ errors when compiled with -Werror. */
+
+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"
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier.
2014-06-10 18:56 ` Siva Chandra
@ 2014-06-11 14:13 ` Ulrich Weigand
0 siblings, 0 replies; 6+ messages in thread
From: Ulrich Weigand @ 2014-06-11 14:13 UTC (permalink / raw)
To: Siva Chandra; +Cc: Pedro Alves, gdb-patches
Siva Chandra wrote:
> On Tue, Jun 10, 2014 at 11:56 AM, Siva Chandra <sivachandra@google.com> wrote:
> > Thanks for the quick review. I have pushed the attached patch which
> > includes the doc fixes suggested by Pedro.
>
> Ah! The patch is attached now!
GDB now builds again on my Python-2.4 system. Thanks for taking care of this!
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-06-11 14:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 13:42 [PATCH] Wrap PyObject_Get/HasAttrString in a function with second arg having const qualifier Siva Chandra
2014-06-09 13:49 ` Pedro Alves
2014-06-09 13:52 ` Pedro Alves
2014-06-10 18:56 ` Siva Chandra
2014-06-10 18:56 ` Siva Chandra
2014-06-11 14:13 ` Ulrich Weigand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox