From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26239 invoked by alias); 22 Jan 2011 23:45:03 -0000 Received: (qmail 25833 invoked by uid 22791); 22 Jan 2011 23:44:59 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 22 Jan 2011 23:44:37 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9A0CA2BABF3; Sat, 22 Jan 2011 18:44:35 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id pz5bRwRr23ax; Sat, 22 Jan 2011 18:44:35 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 7CA3E2BAB9E; Sat, 22 Jan 2011 18:44:35 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id C9CC11459AD; Sat, 22 Jan 2011 18:44:34 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [RFA 1/2] do not use python subdir when including Python .h file Date: Sun, 23 Jan 2011 00:14:00 -0000 Message-Id: <1295739863-1006-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1295739863-1006-1-git-send-email-brobecker@adacore.com> References: <1295739863-1006-1-git-send-email-brobecker@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-01/txt/msg00455.txt.bz2 This is preparation work for being able to build GDB with Python support on MinGW. So far, the "python" subdirectory needs to be specified when including a Python header file. In order to do that, we have some special configury that tweaks the include path returned by python-config.py such that the use of the subdirectory in the include is necessary. This was done in order to protect ourselves from possible filename conflicts, since some of the filenames chosen by Python were a little generic. The problem is that this cannot work with a standard Python install on MinGW systems. On such systems, the .h files are located in /include. So, in preparation for allowing us to build GDB on MinGW with Python support enabled, this patch changes the requirement to provide the "python" subdirectory in the include directive. The positive consequence is that we no longer need to have a set of #include directives for each version of Python, since the include directive is now the same for all versions of Python. However, the downside is that we are losing the level of protection we were trying to achieve by forcing the subdirectory in the include directive. In order to reduce a bit the consequences of a possible conflict, this patch also changes the location where the -I/path/to/python switch goes, to be last in the list (suggested by Doug Evans). One last change is the fact that we are now including Python.h and all other Python include headers using angle brackets rather than double-quotes. This fixes a problem on case-insensitive systems where #include "Python.h" causes our gdb/python/python.h header to be included instead of Python's header. gdb/ChangeLog: * configure.ac: Remove fallback behavior for building against Python. Remove tweaking of Python include path. Add PYTHON_CPPFLAGS and PYTHON_LIBS substitution. (AC_TRY_LIBPYTHON): Adjust program used in linking test. If link is successful, set PYTHON_CPPFLAGS and PYTHON_LIBS. Always restore CPPFLAGS and LIBS after linking test. * configure: Regenerated. * Makefile.in (INTERNAL_CPPFLAGS): Add @PYTHON_CPPFLAGS@. (INSTALLED_LIBS, CLIBS): Add @PYTHON_LIBS@. * python/python-internal.h: Adjust includes of Python .h files. Tested on x86_64-linux. --- gdb/Makefile.in | 13 +++++-- gdb/configure | 73 ++++++++++++++++++++--------------------- gdb/configure.ac | 36 ++++++++------------ gdb/python/python-internal.h | 18 +++------- 4 files changed, 65 insertions(+), 75 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 226faf6..d8efc84 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -408,8 +408,13 @@ PROFILE_CFLAGS = @PROFILE_CFLAGS@ # when running make. I.E. "make CFLAGS=-Wmissing-prototypes". CFLAGS = @CFLAGS@ -# Set by configure, for e.g. expat. -INTERNAL_CPPFLAGS = @CPPFLAGS@ +# Set by configure, for e.g. expat. Python installations are such that +# C headers are included using their basename (for example, we #include +# rather than, say, ). Since the file names +# are sometimes a little generic, we think that the risk of collision +# with other header files is high. If that happens, we try to mitigate +# a bit the consequences by putting the Python includes last in the list. +INTERNAL_CPPFLAGS = @CPPFLAGS@ @PYTHON_CPPFLAGS@ # Need to pass this to testsuite for "make check". Probably should be # consistent with top-level Makefile.in and gdb/testsuite/Makefile.in @@ -444,10 +449,10 @@ INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CFLAGS) $(MH_LDFLAGS) $(LDFLAGS) $(CONFIG_ # If you have the Cygnus libraries installed, # you can use 'CLIBS=$(INSTALLED_LIBS)' 'CDEPS=' INSTALLED_LIBS=-lbfd -lreadline -lopcodes -liberty -ldecnumber \ - $(XM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \ + $(XM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ @PYTHON_LIBS@ \ -lintl -liberty $(LIBGNU) CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \ - $(XM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \ + $(XM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ @PYTHON_LIBS@ \ $(LIBEXPAT) \ $(LIBIBERTY) $(WIN32LIBS) $(LIBGNU) CDEPS = $(XM_CDEPS) $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) \ diff --git a/gdb/configure b/gdb/configure index 5cee400..2540f8b 100755 --- a/gdb/configure +++ b/gdb/configure @@ -659,6 +659,8 @@ TARGET_SYSTEM_ROOT CONFIG_LDFLAGS RDYNAMIC ALLOCA +PYTHON_LIBS +PYTHON_CPPFLAGS PYTHON_CFLAGS python_prog_path LTLIBEXPAT @@ -10633,26 +10635,16 @@ fi fi fi else - # Fall back to gdb 7.0/7.1 behaviour. - if test -z ${python_prefix}; then - python_includes= - python_libs= - else - python_includes="-I${python_prefix}/include" - python_libs="-L${python_prefix}/lib" - fi + # We do not have a python executable we can use to determine where + # to find the Python headers and libs. We cannot guess the include + # path from the python_prefix either, because that include path + # depends on the Python version. So, there is nothing much we can + # do except assume that the compiler will be able to find those files. + python_includes= + python_libs= have_python_config=no fi - # Having "/pythonX.Y" in the include path is awkward. - # All those python headers get bubbled up to the top inviting lots - # of random collisions. GDB originally didn't use python-config to - # find the compilation parameters and includes "pythonX.Y/" in the - # path of the, umm, include file. So strip away this part of the - # output of python-config --includes. - python_includes=`echo "${python_includes} " \ - | sed -e 's,/python[0-9]*[.][0-9]* , ,g'` - # If we have python-config, only try the configuration it provides. # Otherwise fallback on the old way of trying different versions of # python in turn. @@ -10677,7 +10669,7 @@ $as_echo_n "checking for ${version}... " >&6; } found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include "${version}/Python.h" +#include "Python.h" int main () { @@ -10689,12 +10681,13 @@ _ACEOF if ac_fn_c_try_link "$LINENO"; then : have_libpython=${version} found_usable_python=yes -else - CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS + PYTHON_CPPFLAGS=$new_CPPFLAGS + PYTHON_LIBS=$new_LIBS fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 $as_echo "${found_usable_python}" >&6; } @@ -10719,7 +10712,7 @@ $as_echo_n "checking for ${version}... " >&6; } found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include "${version}/Python.h" +#include "Python.h" int main () { @@ -10731,12 +10724,13 @@ _ACEOF if ac_fn_c_try_link "$LINENO"; then : have_libpython=${version} found_usable_python=yes -else - CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS + PYTHON_CPPFLAGS=$new_CPPFLAGS + PYTHON_LIBS=$new_LIBS fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 $as_echo "${found_usable_python}" >&6; } @@ -10756,7 +10750,7 @@ $as_echo_n "checking for ${version}... " >&6; } found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include "${version}/Python.h" +#include "Python.h" int main () { @@ -10768,12 +10762,13 @@ _ACEOF if ac_fn_c_try_link "$LINENO"; then : have_libpython=${version} found_usable_python=yes -else - CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS + PYTHON_CPPFLAGS=$new_CPPFLAGS + PYTHON_LIBS=$new_LIBS fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 $as_echo "${found_usable_python}" >&6; } @@ -10793,7 +10788,7 @@ $as_echo_n "checking for ${version}... " >&6; } found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include "${version}/Python.h" +#include "Python.h" int main () { @@ -10805,12 +10800,13 @@ _ACEOF if ac_fn_c_try_link "$LINENO"; then : have_libpython=${version} found_usable_python=yes -else - CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS + PYTHON_CPPFLAGS=$new_CPPFLAGS + PYTHON_LIBS=$new_LIBS fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 $as_echo "${found_usable_python}" >&6; } @@ -10830,7 +10826,7 @@ $as_echo_n "checking for ${version}... " >&6; } found_usable_python=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include "${version}/Python.h" +#include "Python.h" int main () { @@ -10842,12 +10838,13 @@ _ACEOF if ac_fn_c_try_link "$LINENO"; then : have_libpython=${version} found_usable_python=yes -else - CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS + PYTHON_CPPFLAGS=$new_CPPFLAGS + PYTHON_LIBS=$new_LIBS fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_python}" >&5 $as_echo "${found_usable_python}" >&6; } @@ -10988,6 +10985,8 @@ else fi + + # ------------------------- # # Checks for header files. # # ------------------------- # diff --git a/gdb/configure.ac b/gdb/configure.ac index 4be35bc..afb7314 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -610,12 +610,14 @@ AC_DEFUN([AC_TRY_LIBPYTHON], CPPFLAGS="$CPPFLAGS $new_CPPFLAGS" LIBS="$LIBS $new_LIBS" found_usable_python=no - AC_LINK_IFELSE(AC_LANG_PROGRAM([[#include "${version}/Python.h"]], + AC_LINK_IFELSE(AC_LANG_PROGRAM([[#include "Python.h"]], [[Py_Initialize ();]]), [have_libpython_var=${version} - found_usable_python=yes], - [CPPFLAGS=$save_CPPFLAGS - LIBS=$save_LIBS]) + found_usable_python=yes + PYTHON_CPPFLAGS=$new_CPPFLAGS + PYTHON_LIBS=$new_LIBS]) + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS AC_MSG_RESULT([${found_usable_python}]) ]) @@ -744,26 +746,16 @@ else fi fi else - # Fall back to gdb 7.0/7.1 behaviour. - if test -z ${python_prefix}; then - python_includes= - python_libs= - else - python_includes="-I${python_prefix}/include" - python_libs="-L${python_prefix}/lib" - fi + # We do not have a python executable we can use to determine where + # to find the Python headers and libs. We cannot guess the include + # path from the python_prefix either, because that include path + # depends on the Python version. So, there is nothing much we can + # do except assume that the compiler will be able to find those files. + python_includes= + python_libs= have_python_config=no fi - # Having "/pythonX.Y" in the include path is awkward. - # All those python headers get bubbled up to the top inviting lots - # of random collisions. GDB originally didn't use python-config to - # find the compilation parameters and includes "pythonX.Y/" in the - # path of the, umm, include file. So strip away this part of the - # output of python-config --includes. - python_includes=`echo "${python_includes} " \ - | sed -e 's,/python[[0-9]]*[[.]][[0-9]]* , ,g'` - # If we have python-config, only try the configuration it provides. # Otherwise fallback on the old way of trying different versions of # python in turn. @@ -881,6 +873,8 @@ else python/py-prettyprint.c python/py-auto-load.c" fi AC_SUBST(PYTHON_CFLAGS) +AC_SUBST(PYTHON_CPPFLAGS) +AC_SUBST(PYTHON_LIBS) # ------------------------- # # Checks for header files. # diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 80d0763..a572003 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -41,25 +41,17 @@ around technique as above. */ #undef _FILE_OFFSET_BITS +/* Include the Python header files using angle brackets rather than + double quotes. On case-insensitive filesystems, this prevents us + from including our python/python.h header file. */ +#include +#include #if HAVE_LIBPYTHON2_4 -#include "python2.4/Python.h" -#include "python2.4/frameobject.h" /* Py_ssize_t is not defined until 2.5. Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit compilation due to several apparent mistakes in python2.4 API, so we use 'int' instead. */ typedef int Py_ssize_t; -#elif HAVE_LIBPYTHON2_5 -#include "python2.5/Python.h" -#include "python2.5/frameobject.h" -#elif HAVE_LIBPYTHON2_6 -#include "python2.6/Python.h" -#include "python2.6/frameobject.h" -#elif HAVE_LIBPYTHON2_7 -#include "python2.7/Python.h" -#include "python2.7/frameobject.h" -#else -#error "Unable to find usable Python.h" #endif /* If Python.h does not define WITH_THREAD, then the various -- 1.7.1