summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-05-05 06:12:42 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-05-05 06:12:42 (GMT)
commitfd417cc54bc71fb294c4f9889441929d3e8b3dcc (patch)
treef16690527e605bc53f9ca09d6bed75473496189e /Python
parentdea2ec4b1df1c9f5567591bfea427fa3d2d694e8 (diff)
downloadcpython-fd417cc54bc71fb294c4f9889441929d3e8b3dcc.zip
cpython-fd417cc54bc71fb294c4f9889441929d3e8b3dcc.tar.gz
cpython-fd417cc54bc71fb294c4f9889441929d3e8b3dcc.tar.bz2
Fix crash caused by 8c1385205a35
(thanks Arfrever for reporting).
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index ddda4a4..9ef653b 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -558,6 +558,9 @@ Py_Finalize(void)
/* Destroy the database used by _PyImport_{Fixup,Find}Extension */
_PyImport_Fini();
+ /* Cleanup typeobject.c's internal caches. */
+ _PyType_Fini();
+
/* unload faulthandler module */
_PyFaulthandler_Fini();
@@ -578,7 +581,7 @@ Py_Finalize(void)
_Py_PrintReferences(stderr);
#endif /* Py_TRACE_REFS */
- /* Clear interpreter state */
+ /* Clear interpreter state and all thread states. */
PyInterpreterState_Clear(interp);
/* Now we decref the exception classes. After this point nothing
@@ -594,10 +597,6 @@ Py_Finalize(void)
_PyGILState_Fini();
#endif /* WITH_THREAD */
- /* Delete current thread */
- PyThreadState_Swap(NULL);
- PyInterpreterState_Delete(interp);
-
/* Sundry finalizers */
PyMethod_Fini();
PyFrame_Fini();
@@ -611,11 +610,14 @@ Py_Finalize(void)
PyFloat_Fini();
PyDict_Fini();
PySlice_Fini();
- _PyType_Fini();
/* Cleanup Unicode implementation */
_PyUnicode_Fini();
+ /* Delete current thread. After this, many C API calls become crashy. */
+ PyThreadState_Swap(NULL);
+ PyInterpreterState_Delete(interp);
+
/* reset file system default encoding */
if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
free((char*)Py_FileSystemDefaultEncoding);