From: Matthieu Longo <matthieu.longo@arm.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v3 2/7] gdb: fail configure if Python version is too old for limited API
Date: Tue, 7 Apr 2026 14:36:13 +0100 [thread overview]
Message-ID: <55120329-8df7-412e-8233-94040bca934a@arm.com> (raw)
In-Reply-To: <7437a144-6d93-414f-a7c3-f67babc0a901@arm.com>
On 31/03/2026 11:16, Matthieu Longo wrote:
> On 24/03/2026 18:53, Tom Tromey wrote:
>>>>>>> Matthieu Longo <matthieu.longo@arm.com> writes:
>>
>>> GDB can be built against the Python limited API using the configure
>>> flag '--enable-py-limited-api=yes'. This flag is currently experimental,
>>> and the build is not yet fully successful. Today, the minimum required
>>> Python version for this option is 3.11. This requirement is not final
>>> and will be raised to a later version as the migration progresses.
>>
>>> However, the configure script does not currently report an error if an
>>> older version of Python is used. Instead, the build fails later with
>>> numerous errors that are difficult to relate to Python limited API
>>> compatiblity.
>>
>>> This patch adds a version check when '--enable-py-limited-api=yes' is
>>> specified, ensuring that the provided Python version meets the minimum
>>> requirements for the limited API support. If it does not, configure will
>>> now fail with a clear error message.
>>
>> Sorry about the delay on this.
>>
>> I'm a bit worried about adding a bunch of new python-related configury.
>> Like are we sure it will agree with what's already in there? As in,
>> picking up the same version from the same place, etc? For instance does
>> this new code respect --with-python-libdir?
>>
>> I wonder if instead there could just be a new compile test that is run
>> when --enable-py-limited-api is used. This test could just check
>> PY_VERSION_HEX and #error on failure.
>>
>> Wouldn't that have the same effect but without adding a ton of new code?
>>
>> TBH I'd even be happy with not doing this check in configure at all and
>> saying that if you specify --enable-py-limited-api then you should know
>> what you're doing and if you mess up you'll just get compile-time
>> errors. That is, stick the check in python-internal.h.
>>
>> Tom
>
> So I followed your advice and added a compile test checking PY_VERSION_HEX and #erroring on failure.
> Here below is the new patch that I posted here to avoid a new revision.
>
> Matthieu
>
>
> diff --git a/gdb/configure b/gdb/configure
> index 12c54521682..16580e4af7d 100755
> --- a/gdb/configure
> +++ b/gdb/configure
> @@ -28507,6 +28507,7 @@ fi
> # do except assume that the compiler will be able to find those files.
> python_includes=
> python_libs=
> + python_prefix=
> have_python_config=no
> fi
>
> @@ -28743,6 +28744,7 @@ else
> fi
>
>
> +
> # Check whether to build GDB against Python limited C API.
> # Check whether --enable-py-limited-api was given.
> if test "${enable_py_limited_api+set}" = set; then :
> @@ -28763,11 +28765,46 @@ fi
> if test "$enable_py_limited_api" = yes; then
> # The minimal Python limited API version is currently set to 3.11 for the
> # support of PyBuffer_FillInfo and PyBuffer_Release.
> - # The choice of the minimal version for the Python limited API won't be frozen
> - # until the end of the migration.
> + # The choice of the minimal version for the Python limited API won't be
> + # frozen until the end of the migration.
> + old_CFLAGS="$CFLAGS"
> + CFLAGS="$CFLAGS $PYTHON_CFLAGS"
> + old_CPPFLAGS="$CPPFLAGS"
> + CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
> + old_LIBS="$LIBS"
> + LIBS="$LIBS $PYTHON_LIBS"
> + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h. */
> +#include <Python.h>
> +#ifndef PY_VERSION_HEX
> +#error "PY_VERSION_HEX is not defined"
> +#endif
> +#if PY_VERSION_HEX < 0x030b0000
> +#error "Python limited API support requires at least Python version 3.11"
> +#endif
> +
> +int
> +main ()
> +{
> +
> + ;
> + return 0;
> +}
> +_ACEOF
> +if ac_fn_c_try_compile "$LINENO"; then :
>
> $as_echo "#define Py_LIMITED_API 0x030b0000" >>confdefs.h
>
> +
> +else
> +
> + as_fn_error $? "Python limited API support requires at least Python version 3.11" "$LINENO" 5
> +
> +fi
> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> + CFLAGS="$old_CFLAGS"
> + CPPFLAGS="$old_CPPFLAGS"
> + LIBS="$old_LIBS"
> fi
>
> # -------------------- #
> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index cf8078e1d89..c6b0653e3b0 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -933,6 +933,7 @@ else
> # do except assume that the compiler will be able to find those files.
> python_includes=
> python_libs=
> + python_prefix=
> have_python_config=no
> fi
>
> @@ -1062,6 +1063,13 @@ AC_SUBST(PYTHON_CPPFLAGS)
> AC_SUBST(PYTHON_LIBS)
> AM_CONDITIONAL(HAVE_PYTHON, test "${have_libpython}" != no)
>
> +dnl Use --enable-py-limited-api to enable the build of GDB against the Python
> +dnl limited API.
> +dnl
> +dnl no - Disable the Python limited API.
> +dnl yes - Use the Python limited API to build GDB, error if the selected
> +dnl version of Python is not compatible with the Python limited API.
> +
> # Check whether to build GDB against Python limited C API.
> AC_ARG_ENABLE([py-limited-api],
> [AS_HELP_STRING([--enable-py-limited-api],
> @@ -1072,10 +1080,31 @@ AC_ARG_ENABLE([py-limited-api],
> if test "$enable_py_limited_api" = yes; then
> # The minimal Python limited API version is currently set to 3.11 for the
> # support of PyBuffer_FillInfo and PyBuffer_Release.
> - # The choice of the minimal version for the Python limited API won't be frozen
> - # until the end of the migration.
> - AC_DEFINE(Py_LIMITED_API, 0x030b0000,
> - [Define if GDB should be built against the Python limited C API.])
> + # The choice of the minimal version for the Python limited API won't be
> + # frozen until the end of the migration.
> + old_CFLAGS="$CFLAGS"
> + CFLAGS="$CFLAGS $PYTHON_CFLAGS"
> + old_CPPFLAGS="$CPPFLAGS"
> + CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
> + old_LIBS="$LIBS"
> + LIBS="$LIBS $PYTHON_LIBS"
> + AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
> + [[#include <Python.h>
> +#ifndef PY_VERSION_HEX
> +#error "PY_VERSION_HEX is not defined"
> +#endif
> +#if PY_VERSION_HEX < 0x030b0000
> +#error "Python limited API support requires at least Python version 3.11"
> +#endif
> + ]],[[]])],
> + [AC_DEFINE(Py_LIMITED_API, 0x030b0000,
> + [Define if GDB should be built against the Python limited C API.])
> + ],[
> + AC_MSG_ERROR([Python limited API support requires at least Python version 3.11])
> + ])
> + CFLAGS="$old_CFLAGS"
> + CPPFLAGS="$old_CPPFLAGS"
> + LIBS="$old_LIBS"
> fi
>
> # -------------------- #
Ping ?
next prev parent reply other threads:[~2026-04-07 13:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 17:56 [PATCH v3 0/7] gdb: more fixes for Python limited C API support Matthieu Longo
2026-03-09 17:56 ` [PATCH v3 1/7] gdb: introduce rgb_color type to simplify existing code Matthieu Longo
2026-03-09 19:22 ` Tom Tromey
2026-03-11 15:03 ` Simon Marchi
2026-03-11 17:55 ` Matthieu Longo
2026-03-11 18:04 ` Simon Marchi
2026-03-11 18:16 ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 2/7] gdb: fail configure if Python version is too old for limited API Matthieu Longo
2026-03-24 18:53 ` Tom Tromey
2026-03-31 10:16 ` Matthieu Longo
2026-04-07 13:36 ` Matthieu Longo [this message]
2026-04-07 20:39 ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 3/7] gdb: add new helpers for retrieving a type's fully qualified name Matthieu Longo
2026-03-24 18:44 ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 4/7] gdb/python: allow ref_ptr<T, Policy>::new_reference to accept subclasses of T Matthieu Longo
2026-03-09 19:40 ` Tom Tromey
2026-03-10 12:26 ` Matthieu Longo
2026-03-09 17:56 ` [PATCH v3 5/7] gdb/python: flatten functions calling PyObject_New and use gdbpy_ref Matthieu Longo
2026-03-09 20:07 ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 6/7] gdb/python: add gdbpy_dict_wrapper:allocate_dict helper Matthieu Longo
2026-03-09 20:09 ` Tom Tromey
2026-03-10 12:26 ` Matthieu Longo
2026-03-09 17:56 ` [PATCH v3 7/7] gdb/python: add accessor helpers for __dict__ in Python extension objects Matthieu Longo
2026-03-13 18:09 ` Tom Tromey
2026-03-23 10:28 ` [PATCH v3 0/7] gdb: more fixes for Python limited C API support Matthieu Longo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55120329-8df7-412e-8233-94040bca934a@arm.com \
--to=matthieu.longo@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox