Fix build issue with Python 3.7
authorPaul Koning <paul_koning@dell.com>
Fri, 8 Jun 2018 17:26:36 +0000 (13:26 -0400)
committerPaul Koning <paul_koning@dell.com>
Fri, 8 Jun 2018 17:32:03 +0000 (13:32 -0400)
Originally reported in
https://bugzilla.redhat.com/show_bug.cgi?id=1577396 -- gdb build fails
with Python 3.7 due to references to a Python internal function whose
declaration changed in 3.7.

gdb/ChangeLog
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.

gdb/ChangeLog
gdb/python/python.c

index dbee2a3..12157bb 100644 (file)
@@ -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.
+
 2018-06-08  Gary Benson <gbenson@redhat.com>
 
        * linux-thread-db.c (valprint.h): New include.
index 1805c90..20fc674 100644 (file)
@@ -1667,6 +1667,17 @@ finalize_python (void *ignore)
   restore_active_ext_lang (previous_active);
 }
 
+#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 ()
 {
@@ -1707,6 +1718,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.release ());
 #endif
@@ -1716,9 +1730,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