From d7de8e3ce962db7df6f4107101a87f53129e98eb Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 20 Sep 2012 20:54:11 +0000 Subject: * NEWS: Update. * python/python.c (finalize_python): New function. (_initialize_python): Make a final cleanup. testsuite * gdb.python/python.exp: Test atexit.register. --- gdb/python/python.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'gdb/python/python.c') 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 */ } -- cgit v1.1