comparison Python/pythonrun.c @ 69070:b0680b5a5215

Issue #11393: Add the new faulthandler module
author Victor Stinner <victor.stinner@haypocalc.com>
date Thu, 31 Mar 2011 01:31:06 +0200
parents 929aafef5b05
children a4fa79b0d478
comparison
equal deleted inserted replaced
69069:9d658f000419 69070:b0680b5a5215
68 static void call_ll_exitfuncs(void); 68 static void call_ll_exitfuncs(void);
69 extern void _PyUnicode_Init(void); 69 extern void _PyUnicode_Init(void);
70 extern void _PyUnicode_Fini(void); 70 extern void _PyUnicode_Fini(void);
71 extern int _PyLong_Init(void); 71 extern int _PyLong_Init(void);
72 extern void PyLong_Fini(void); 72 extern void PyLong_Fini(void);
73 extern int _PyFaulthandler_Init(void);
74 extern void _PyFaulthandler_Fini(void);
73 75
74 #ifdef WITH_THREAD 76 #ifdef WITH_THREAD
75 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *); 77 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
76 extern void _PyGILState_Fini(void); 78 extern void _PyGILState_Fini(void);
77 #endif /* WITH_THREAD */ 79 #endif /* WITH_THREAD */
283 Py_DECREF(pstderr); 285 Py_DECREF(pstderr);
284 286
285 _PyImport_Init(); 287 _PyImport_Init();
286 288
287 _PyImportHooks_Init(); 289 _PyImportHooks_Init();
290
291 /* initialize the faulthandler module */
292 if (_PyFaulthandler_Init())
293 Py_FatalError("Py_Initialize: can't initialize faulthandler");
288 294
289 /* Initialize _warnings. */ 295 /* Initialize _warnings. */
290 _PyWarnings_Init(); 296 _PyWarnings_Init();
291 297
292 _PyTime_Init(); 298 _PyTime_Init();
451 PyGC_Collect(); 457 PyGC_Collect();
452 #endif 458 #endif
453 459
454 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ 460 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
455 _PyImport_Fini(); 461 _PyImport_Fini();
462
463 /* unload faulthandler module */
464 _PyFaulthandler_Fini();
456 465
457 /* Debugging stuff */ 466 /* Debugging stuff */
458 #ifdef COUNT_ALLOCS 467 #ifdef COUNT_ALLOCS
459 dump_counts(stdout); 468 dump_counts(stdout);
460 #endif 469 #endif
2098 /* Print fatal error message and abort */ 2107 /* Print fatal error message and abort */
2099 2108
2100 void 2109 void
2101 Py_FatalError(const char *msg) 2110 Py_FatalError(const char *msg)
2102 { 2111 {
2112 const int fd = fileno(stderr);
2113 PyThreadState *tstate;
2114
2103 fprintf(stderr, "Fatal Python error: %s\n", msg); 2115 fprintf(stderr, "Fatal Python error: %s\n", msg);
2104 fflush(stderr); /* it helps in Windows debug build */ 2116 fflush(stderr); /* it helps in Windows debug build */
2105 if (PyErr_Occurred()) { 2117 if (PyErr_Occurred()) {
2106 PyErr_PrintEx(0); 2118 PyErr_PrintEx(0);
2107 } 2119 }
2120 else {
2121 tstate = _Py_atomic_load_relaxed(&_PyThreadState_Current);
2122 if (tstate != NULL) {
2123 fputc('\n', stderr);
2124 fflush(stderr);
2125 _Py_DumpTraceback(fd, tstate);
2126 }
2127 }
2128
2108 #ifdef MS_WINDOWS 2129 #ifdef MS_WINDOWS
2109 { 2130 {
2110 size_t len = strlen(msg); 2131 size_t len = strlen(msg);
2111 WCHAR* buffer; 2132 WCHAR* buffer;
2112 size_t i; 2133 size_t i;