From patchwork Wed Feb 4 17:43:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 4914 Received: (qmail 14148 invoked by alias); 4 Feb 2015 17:43:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 14129 invoked by uid 89); 4 Feb 2015 17:43:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 04 Feb 2015 17:43:17 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t14HhFOu029225 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 4 Feb 2015 12:43:15 -0500 Received: from host1.jankratochvil.net (ovpn-116-113.ams2.redhat.com [10.36.116.113]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t14HhB5b032570 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Wed, 4 Feb 2015 12:43:14 -0500 Date: Wed, 4 Feb 2015 18:43:11 +0100 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Fix Python 3 build error on 32-bit hosts Message-ID: <20150204174311.GA24375@host1.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes 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 Also one could use that #if either just at the valpy_hash() definition or one could provide Py_hash_t in gdb/defs.h or one could provide some GDB_Py_hash_t in gdb/defs.h. Tested compilation with: python-devel-2.7.9-4.fc22.x86_64 python-devel-2.7.9-4.fc22.i686 python3-devel-3.4.2-4.fc22.x86_64 python3-devel-3.4.2-4.fc22.i686 Jan gdb/ 2015-02-04 Jan Kratochvil * configure.ac <"${have_libpython}" != no>: Define Py_hash_t. * python/py-value.c (valpy_fetch_lazy): Use it. Remove cast to the return type. * config.in: Regenerate. * configure: Regenerate. diff --git a/gdb/configure.ac b/gdb/configure.ac index dfc6947..f335b7b 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -1016,6 +1016,25 @@ if test "${have_libpython}" != no; then ]]), [python_has_threads=no], [python_has_threads=yes]) AC_MSG_RESULT(${python_has_threads}) CPPFLAGS="${saved_CPPFLAGS}" + + AC_CACHE_CHECK([for Py_hash_t], gdb_cv_Py_hash_t, + old_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PYTHON_CFLAGS" + old_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS" + AC_TRY_COMPILE( + [#include ], + [Py_hash_t var;], + gdb_cv_Py_hash_t=yes, + gdb_cv_Py_hash_t=no + ) + CPPFLAGS="$old_CPPFLAGS" + CFLAGS="$old_CFLAGS" + ) + if test "x$gdb_cv_Py_hash_t" = "xno"; then + AC_DEFINE(Py_hash_t, long, + [Provide Python 3 Py_hash_t for Python 2.]) + fi else # Even if Python support is not compiled in, we need to have this file # included so that the "python" command, et.al., still exists. diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 4c4d36e..5a13777 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -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