blob: 1d20e3cbd2188d851f60e2bc98cefee1d65c46b4 [file] [log] [blame]
From f9d4cd6bdf6bc8160567e4953efa8122e4b8dfe3 Mon Sep 17 00:00:00 2001
From: Kai Yick <kingkai@google.com>
Date: Fri, 25 Sep 2020 22:21:23 -0700
Subject: [PATCH] Fix Python 3.7 Build Issue
---
gdb/ChangeLog | 8 ++++++++
gdb/python/python.c | 18 +++++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2451ba70d5..77c0b65305 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2018-06-08 Paul Koning <paul_koning@dell.com>
+
+ PR gdb/23252
+
+ * python/python.c (do_start_initialization):
+ Avoid call to internal Python API.
+ (init__gdb_module): New function.
+
2017-07-03 Simon Marchi <simon.marchi@ericsson.com>
* buffer.h (buffer_finish): Fix spelling mistakes.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index be92f36b6e..39e334eb49 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1525,6 +1525,17 @@ extern initialize_file_ftype _initialize_python;
#ifdef HAVE_PYTHON
+#ifdef IS_PY3K
+/* This is called via the PyImport_AppendInittab mechanism called
+ during initialization, to make the built-in _gdb module known to
+ Python. */
+PyMODINIT_FUNC
+init__gdb_module (void)
+{
+ return PyModule_Create (&python_GdbModuleDef);
+}
+#endif
+
static bool
do_start_initialization ()
{
@@ -1570,6 +1581,9 @@ do_start_initialization ()
remain alive for the duration of the program's execution, so
it is not freed after this call. */
Py_SetProgramName (progname_copy);
+
+ /* Define _gdb as a built-in module. */
+ PyImport_AppendInittab ("_gdb", init__gdb_module);
#else
Py_SetProgramName (progname);
#endif
@@ -1579,9 +1593,7 @@ do_start_initialization ()
PyEval_InitThreads ();
#ifdef IS_PY3K
- gdb_module = PyModule_Create (&python_GdbModuleDef);
- /* Add _gdb module to the list of known built-in modules. */
- _PyImport_FixupBuiltin (gdb_module, "_gdb");
+ gdb_module = PyImport_ImportModule ("_gdb");
#else
gdb_module = Py_InitModule ("_gdb", python_GdbMethods);
#endif
--
2.28.0.709.gb0816b6eb0-goog