Re: [patch] Fix Python 3 build error on 32-bit hosts

Paul_Koning
2015-02-04T18:39:54Z

> On Feb 4, 2015, at 12:43 PM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
>
> Hi,
>
> on Fedora Rawhide (==22) i686 using --with-python=/usr/bin/python3 one gets:
>
> gcc -g -I. -I. -I./common -I./config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber -I./gnulib/import -Ibuild-gnulib/import -DTUI=1 -pthread -I/usr/include/guile/2.0 -I/usr/include/python3.4m -I/usr/include/python3.4m -Wall -Wdeclaration-after-statement -Wpointer-arith -Wpointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wformat-nonliteral -Werror -c -o py-value.o -MT py-value.o -MMD -MP -MF .deps/py-value.Tpo -fno-strict-aliasing -DNDEBUG -fwrapv ./python/py-value.c
> ./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’)
>
> A question is whether the autoconf test isn't an overkill. One could use
> instead just:
> #if PYTHON_ABI_VERSION >= 3

I would say yes. This has been done in other cases where types or signatures changed between the two versions. Given that it’s specifically a change in definition, it seems logical to test the Python version with a #if and use the old or the new definition accordingly.

paul