comparison Python/pythonrun.c @ 84489:213d6d7f5979

Issue #18203: Fix Py_Finalize(): destroy the GIL after the last call to PyMem_Malloc() or PyObject_Malloc(). For example, PyCFunction_Fini() calls PyObject_GC_Del() which calls PyObject_FREE().
author Victor Stinner <victor.stinner@gmail.com>
date Sun, 07 Jul 2013 15:50:49 +0200
parents f0833e6ff2d2
children 65f2c92ed079
comparison
equal deleted inserted replaced
84488:744dd749e25b 84489:213d6d7f5979
604 raised. 604 raised.
605 */ 605 */
606 606
607 _PyExc_Fini(); 607 _PyExc_Fini();
608 608
609 /* Cleanup auto-thread-state */
610 #ifdef WITH_THREAD
611 _PyGILState_Fini();
612 #endif /* WITH_THREAD */
613
614 /* Sundry finalizers */ 609 /* Sundry finalizers */
615 PyMethod_Fini(); 610 PyMethod_Fini();
616 PyFrame_Fini(); 611 PyFrame_Fini();
617 PyCFunction_Fini(); 612 PyCFunction_Fini();
618 PyTuple_Fini(); 613 PyTuple_Fini();
627 _PyGC_Fini(); 622 _PyGC_Fini();
628 623
629 /* Cleanup Unicode implementation */ 624 /* Cleanup Unicode implementation */
630 _PyUnicode_Fini(); 625 _PyUnicode_Fini();
631 626
632 /* Delete current thread. After this, many C API calls become crashy. */
633 PyThreadState_Swap(NULL);
634 PyInterpreterState_Delete(interp);
635
636 /* reset file system default encoding */ 627 /* reset file system default encoding */
637 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) { 628 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
638 free((char*)Py_FileSystemDefaultEncoding); 629 free((char*)Py_FileSystemDefaultEncoding);
639 Py_FileSystemDefaultEncoding = NULL; 630 Py_FileSystemDefaultEncoding = NULL;
640 } 631 }
644 - int and float free list blocks 635 - int and float free list blocks
645 - whatever various modules and libraries allocate 636 - whatever various modules and libraries allocate
646 */ 637 */
647 638
648 PyGrammar_RemoveAccelerators(&_PyParser_Grammar); 639 PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
640
641 /* Cleanup auto-thread-state */
642 #ifdef WITH_THREAD
643 _PyGILState_Fini();
644 #endif /* WITH_THREAD */
645
646 /* Delete current thread. After this, many C API calls become crashy. */
647 PyThreadState_Swap(NULL);
648 PyInterpreterState_Delete(interp);
649 649
650 #ifdef Py_TRACE_REFS 650 #ifdef Py_TRACE_REFS
651 /* Display addresses (& refcnts) of all objects still alive. 651 /* Display addresses (& refcnts) of all objects still alive.
652 * An address can be used to find the repr of the object, printed 652 * An address can be used to find the repr of the object, printed
653 * above by _Py_PrintReferences. 653 * above by _Py_PrintReferences.