Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Matthieu Longo <matthieu.longo@arm.com>
To: <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>, Andrew Burgess <aburgess@redhat.com>,
	Matthieu Longo <matthieu.longo@arm.com>
Subject: [PATCH v2 1/2] gdb: make Python conftest compatible with Python limited C API
Date: Tue, 14 Oct 2025 17:44:57 +0100	[thread overview]
Message-ID: <20251014164458.2000229-2-matthieu.longo@arm.com> (raw)
In-Reply-To: <20251014164458.2000229-1-matthieu.longo@arm.com>

The current test to check the support of '--dynamic-list' linker flag
uses PyRun_SimpleString (), which is part of the unstable API. As it is
now, the test will systematically fail due to the undefined symbol
rather than testing the import of ctypes.
This patch replaces PyRun_SimpleString () by an equivalent code relying
on the limited C API, and compatible with Python 3.4.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830
---
 gdb/configure    | 13 ++++++++++---
 gdb/configure.ac | 13 ++++++++++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index db63481b1c6..b7a2079d206 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -31034,11 +31034,18 @@ else
 int
 main ()
 {
-int err;
+
+          const char *code = "import ctypes\n";
           Py_Initialize ();
-          err = PyRun_SimpleString ("import ctypes\n");
+          PyObject *main_module = PyImport_AddModule ("__main__");
+          PyObject *global_dict = PyModule_GetDict (main_module);
+          PyObject *local_dict = PyDict_New ();
+          PyObject *py_code = Py_CompileString (code, "test", Py_single_input);
+          if (py_code == NULL)
+            return 1;
+          PyObject *res = PyEval_EvalCode (py_code, global_dict, local_dict);
           Py_Finalize ();
-          return err == 0 ? 0 : 1;
+          return res ? 0 : 1;
   ;
   return 0;
 }
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 52924106bca..a88b6ebffe5 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1761,11 +1761,18 @@ if test "${gdb_native}" = yes; then
      AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
          [#include "Python.h"],
-         [int err;
+         [
+          const char *code = "import ctypes\n";
           Py_Initialize ();
-          err = PyRun_SimpleString ("import ctypes\n");
+          PyObject *main_module = PyImport_AddModule ("__main__");
+          PyObject *global_dict = PyModule_GetDict (main_module);
+          PyObject *local_dict = PyDict_New ();
+          PyObject *py_code = Py_CompileString (code, "test", Py_single_input);
+          if (py_code == NULL)
+            return 1;
+          PyObject *res = PyEval_EvalCode (py_code, global_dict, local_dict);
           Py_Finalize ();
-          return err == 0 ? 0 : 1;])],
+          return res ? 0 : 1;])],
        [dynamic_list=true], [], [true])
      LIBS="$old_LIBS"
      CFLAGS="$old_CFLAGS"
-- 
2.51.0


  reply	other threads:[~2025-10-14 16:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 16:44 [PATCH v2 0/2] Add experimental option --enable-py-limited-api Matthieu Longo
2025-10-14 16:44 ` Matthieu Longo [this message]
2025-10-14 16:44 ` [PATCH v2 2/2] gdb: add " Matthieu Longo
2025-10-20 15:23   ` [PATCH] Drop bashism from configure script Kévin Le Gouguec
2025-10-20 15:31     ` Tom Tromey
2025-10-20 15:46       ` Kévin Le Gouguec
2025-10-14 17:22 ` [PATCH v2 0/2] Add experimental option --enable-py-limited-api Eli Zaretskii
2025-10-15  9:03   ` Matthieu Longo
2025-10-15 14:01 ` Tom Tromey

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=20251014164458.2000229-2-matthieu.longo@arm.com \
    --to=matthieu.longo@arm.com \
    --cc=aburgess@redhat.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