Skip to content

Build failure on 32-bit OS: incompatible type in tp_hash in PyTypeObject #149

@hosiet

Description

@hosiet

Current mod_python v3.5.0.6 fails to build on 32-bit OS (e.g., armhf, i386, ...):

Building mod_python.so.

/usr/bin/apxs2 -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13 -Wc,-ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=.  -c mod_python.c _apachemodule.c requestobject.c tableobject.c util.c serverobject.c connobject.c filterobject.c hlist.c hlistobject.c finfoobject.c version.c include/_apachemodule.h  include/filterobject.h  include/hlist.h include/mod_python.h  include/psp_flex.h include/psp_parser.h include/requestobject.h include/tableobject.h include/connobject.h include/finfoobject.h include/hlistobject.h include/mp_version.h include/_pspmodule.h  include/psp_string.h  include/serverobject.h include/util.h -L/usr/lib/python3.13/config-3.13-i386-linux-gnu -L/usr/lib/i386-linux-gnu -lpython3.13 -ldl  -lm   
/usr/share/apr-1.0/build/libtool  --mode=compile --tag=disable-static i686-linux-gnu-gcc -prefer-pic -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security  -Wdate-time -D_FORTIFY_SOURCE=2   -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE   -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13  -c -o mod_python.lo mod_python.c && touch mod_python.slo
libtool: compile:  i686-linux-gnu-gcc -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13 -c mod_python.c  -fPIC -DPIC -o .libs/mod_python.o
/usr/share/apr-1.0/build/libtool  --mode=compile --tag=disable-static i686-linux-gnu-gcc -prefer-pic -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security  -Wdate-time -D_FORTIFY_SOURCE=2   -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE   -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13  -c -o _apachemodule.lo _apachemodule.c && touch _apachemodule.slo
libtool: compile:  i686-linux-gnu-gcc -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13 -c _apachemodule.c  -fPIC -DPIC -o .libs/_apachemodule.o
/usr/share/apr-1.0/build/libtool  --mode=compile --tag=disable-static i686-linux-gnu-gcc -prefer-pic -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security  -Wdate-time -D_FORTIFY_SOURCE=2   -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE   -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13  -c -o requestobject.lo requestobject.c && touch requestobject.slo
libtool: compile:  i686-linux-gnu-gcc -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13 -c requestobject.c  -fPIC -DPIC -o .libs/requestobject.o
/usr/share/apr-1.0/build/libtool  --mode=compile --tag=disable-static i686-linux-gnu-gcc -prefer-pic -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security  -Wdate-time -D_FORTIFY_SOURCE=2   -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE   -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13  -c -o tableobject.lo tableobject.c && touch tableobject.slo
libtool: compile:  i686-linux-gnu-gcc -pipe -g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -ffile-prefix-map=/build/reproducible-path/libapache2-mod-python-3.5.0.6=. -I/build/reproducible-path/libapache2-mod-python-3.5.0.6/src/include -I/usr/include/python3.13 -I/usr/include/python3.13 -c tableobject.c  -fPIC -DPIC -o .libs/tableobject.o
tableobject.c:1203:5: error: initialization of 'Py_hash_t (*)(PyObject *)' {aka 'int (*)(struct _object *)'} from incompatible pointer type 'long int (*)(PyObject *)' {aka 'long int (*)(struct _object *)'} [-Wincompatible-pointer-types]
 1203 |     table_nohash,                       /* tp_hash */
      |     ^~~~~~~~~~~~
tableobject.c:1203:5: note: (near initialization for 'MpTable_Type.tp_hash')
tableobject.c:1161:13: note: 'table_nohash' declared here
 1161 | static long table_nohash(PyObject *self)
      |             ^~~~~~~~~~~~
apxs:Error: Command failed with rc=65536
.
make[3]: *** [Makefile:57: mod_python.so] Error 1

The reason is that *hashfunc as defined in https://docs.python.org/3/c-api/typeobj.html#c.hashfunc has type Py_hash_t, which is of type signed integer as defined at https://docs.python.org/3/c-api/hash.html#c.Py_hash_t . However, in

static long table_nohash(PyObject *self)
you are using long instead. On 32-bit OS, long may not equal to int and thus the build error happens.

The solution could be directly using Py_hash_t, instead of hardcoding int or long for function return.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions