aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-09-20 20:54:11 +0000
committerTom Tromey <tromey@redhat.com>2012-09-20 20:54:11 +0000
commitd7de8e3ce962db7df6f4107101a87f53129e98eb (patch)
treeef282d5c25697b0975283b61cae01f4013798332 /gdb/python
parent05eade73e1f590a99d2c6ac2359e62c0765f9ca4 (diff)
downloadgdb-d7de8e3ce962db7df6f4107101a87f53129e98eb.zip
gdb-d7de8e3ce962db7df6f4107101a87f53129e98eb.tar.gz
gdb-d7de8e3ce962db7df6f4107101a87f53129e98eb.tar.bz2
* NEWS: Update.
* python/python.c (finalize_python): New function. (_initialize_python): Make a final cleanup. testsuite * gdb.python/python.exp: Test atexit.register.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 3cfb284..c66dc60 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1266,6 +1266,24 @@ user_show_python (char *args, int from_tty)
/* Initialize the Python code. */
+/* This is installed as a final cleanup and cleans up the
+ interpreter. This lets Python's 'atexit' work. */
+
+static void
+finalize_python (void *ignore)
+{
+ /* We don't use ensure_python_env here because if we ever ran the
+ cleanup, gdb would crash -- because the cleanup calls into the
+ Python interpreter, which we are about to destroy. It seems
+ clearer to make the needed calls explicitly here than to create a
+ cleanup and then mysteriously discard it. */
+ PyGILState_Ensure ();
+ python_gdbarch = target_gdbarch;
+ python_language = current_language;
+
+ Py_Finalize ();
+}
+
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_python;
@@ -1427,6 +1445,7 @@ message == an error message without a stack will be printed."),
PyThreadState_Swap (NULL);
PyEval_ReleaseLock ();
+ make_final_cleanup (finalize_python, NULL);
#endif /* HAVE_PYTHON */
}