comparison Python/pythonrun.c @ 83624:6f4627a65c0a

Fix crash caused by 8c1385205a35 (thanks Arfrever for reporting).
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 05 May 2013 08:14:53 +0200
parents 97b7bd87c44c 7de9852cdc0e
children f0833e6ff2d2
comparison
equal deleted inserted replaced
83622:bf325cd5cc94 83624:6f4627a65c0a
574 #endif 574 #endif
575 575
576 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ 576 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
577 _PyImport_Fini(); 577 _PyImport_Fini();
578 578
579 /* Cleanup typeobject.c's internal caches. */
580 _PyType_Fini();
581
579 /* unload faulthandler module */ 582 /* unload faulthandler module */
580 _PyFaulthandler_Fini(); 583 _PyFaulthandler_Fini();
581 584
582 /* Debugging stuff */ 585 /* Debugging stuff */
583 #ifdef COUNT_ALLOCS 586 #ifdef COUNT_ALLOCS
594 */ 597 */
595 if (Py_GETENV("PYTHONDUMPREFS")) 598 if (Py_GETENV("PYTHONDUMPREFS"))
596 _Py_PrintReferences(stderr); 599 _Py_PrintReferences(stderr);
597 #endif /* Py_TRACE_REFS */ 600 #endif /* Py_TRACE_REFS */
598 601
599 /* Clear interpreter state */ 602 /* Clear interpreter state and all thread states. */
600 PyInterpreterState_Clear(interp); 603 PyInterpreterState_Clear(interp);
601 604
602 /* Now we decref the exception classes. After this point nothing 605 /* Now we decref the exception classes. After this point nothing
603 can raise an exception. That's okay, because each Fini() method 606 can raise an exception. That's okay, because each Fini() method
604 below has been checked to make sure no exceptions are ever 607 below has been checked to make sure no exceptions are ever
609 612
610 /* Cleanup auto-thread-state */ 613 /* Cleanup auto-thread-state */
611 #ifdef WITH_THREAD 614 #ifdef WITH_THREAD
612 _PyGILState_Fini(); 615 _PyGILState_Fini();
613 #endif /* WITH_THREAD */ 616 #endif /* WITH_THREAD */
614
615 /* Delete current thread */
616 PyThreadState_Swap(NULL);
617 PyInterpreterState_Delete(interp);
618 617
619 /* Sundry finalizers */ 618 /* Sundry finalizers */
620 PyMethod_Fini(); 619 PyMethod_Fini();
621 PyFrame_Fini(); 620 PyFrame_Fini();
622 PyCFunction_Fini(); 621 PyCFunction_Fini();
627 PyByteArray_Fini(); 626 PyByteArray_Fini();
628 PyLong_Fini(); 627 PyLong_Fini();
629 PyFloat_Fini(); 628 PyFloat_Fini();
630 PyDict_Fini(); 629 PyDict_Fini();
631 PySlice_Fini(); 630 PySlice_Fini();
632 _PyType_Fini();
633 631
634 /* Cleanup Unicode implementation */ 632 /* Cleanup Unicode implementation */
635 _PyUnicode_Fini(); 633 _PyUnicode_Fini();
634
635 /* Delete current thread. After this, many C API calls become crashy. */
636 PyThreadState_Swap(NULL);
637 PyInterpreterState_Delete(interp);
636 638
637 /* reset file system default encoding */ 639 /* reset file system default encoding */
638 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) { 640 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
639 free((char*)Py_FileSystemDefaultEncoding); 641 free((char*)Py_FileSystemDefaultEncoding);
640 Py_FileSystemDefaultEncoding = NULL; 642 Py_FileSystemDefaultEncoding = NULL;