]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix Python 3 build error on 32-bit hosts
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 4 Feb 2015 19:31:17 +0000 (20:31 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 4 Feb 2015 19:31:17 +0000 (20:31 +0100)
on Fedora Rawhide (==22) i686 using --with-python=/usr/bin/python3 one gets:

./python/py-value.c:1696:3: error: initialization from incompatible pointer type [-Werror]
   valpy_hash,            /*tp_hash*/
   ^
./python/py-value.c:1696:3: error: (near initialization for ‘value_object_type.tp_hash’) [-Werror]
cc1: all warnings being treated as errors
Makefile:2628: recipe for target 'py-value.o' failed

This is because in Python 2 tp_hash was:
typedef long (*hashfunc)(PyObject *);
while in Python 3 tp_hash is:
typedef Py_hash_t (*hashfunc)(PyObject *);

Py_hash_t is int for 32-bit hosts and long for 64-bit hosts.  While on 32-bit
hosts sizeof(long)==sizeof(int) still the hashfunc type is formally
incompatible.  As this patch should have no compiled code change it is not
really necessary for gdb-7.9, it would fix there just this non-fatal
compilation warning:
./python/py-value.c:1696:3: warning: initialization from incompatible pointer type
   valpy_hash,            /*tp_hash*/
   ^
./python/py-value.c:1696:3: warning: (near initialization for ‘value_object_type.tp_hash’)

gdb/ChangeLog
2015-02-04  Jan Kratochvil  <jan.kratochvil@redhat.com>

* python/python-internal.h (Py_hash_t): Define it for Python <3.2.
* python/py-value.c (valpy_fetch_lazy): Use it.  Remove cast to the
return type.

gdb/ChangeLog
gdb/python/py-value.c
gdb/python/python-internal.h

index aae6a7c65fba49a5b0af360b7523de33e11c8c81..cd1c9d7c0a7582e0baea7ddf991e922c8a0d7986 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * python/python-internal.h (Py_hash_t): Define it for Python <3.2.
+       * python/py-value.c (valpy_fetch_lazy): Use it.  Remove cast to the
+       return type.
+
 2015-02-04  Pedro Alves  <palves@redhat.com>
 
        * linux-nat.c (handle_extended_wait): Don't resume LWPs here.
index 4c4d36ec4b47df54a8c218d448d3f1c2211faf60..5a1377756a1080736700298354730e982cc1da15 100644 (file)
@@ -895,10 +895,10 @@ valpy_fetch_lazy (PyObject *self, PyObject *args)
 
 /* Calculate and return the address of the PyObject as the value of
    the builtin __hash__ call.  */
-static long
+static Py_hash_t
 valpy_hash (PyObject *self)
 {
-  return (long) (intptr_t) self;
+  return (intptr_t) self;
 }
 
 enum valpy_opcode
index 0ee85440fb436de496424ccdc7c7eee472bd6c1f..a77f5a662671c32afce921ed5d18a9c9c421c935 100644 (file)
@@ -169,6 +169,10 @@ typedef unsigned long gdb_py_ulongest;
 
 #endif /* HAVE_LONG_LONG */
 
+#if PY_VERSION_HEX < 0x03020000
+typedef long Py_hash_t;
+#endif
+
 /* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
    to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
    Wrap it ourselves, so that callers don't need to care.  */