| 1 |
|
| 2 |
#include "Python.h" |
| 3 |
|
| 4 |
#ifdef MS_WINDOWS |
| 5 |
#include "malloc.h" |
| 6 |
#include "windows.h" |
| 7 |
#endif |
| 8 |
|
| 9 |
void |
| 10 |
_Py_FatalErrorFunc(const char * func, const char *msg) |
| 11 |
{ |
| 12 |
if (func) { |
| 13 |
fprintf(stderr, "Fatal Python error: %s: %s\n", func, msg); |
| 14 |
} |
| 15 |
else { |
| 16 |
fprintf(stderr, "Fatal Python error: %s\n", msg); |
| 17 |
} |
| 18 |
fflush(stderr); |
| 19 |
if (PyErr_Occurred()) { |
| 20 |
PyErr_PrintEx(0); |
| 21 |
} |
| 22 |
#ifdef MS_WINDOWS |
| 23 |
{ |
| 24 |
size_t len = strlen(msg); |
| 25 |
WCHAR* buffer; |
| 26 |
size_t i; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
buffer = alloca( (len+1) * (sizeof *buffer)); |
| 32 |
for( i=0; i<=len; ++i) |
| 33 |
buffer[i] = msg[i]; |
| 34 |
OutputDebugStringW(L"Fatal Python error: "); |
| 35 |
OutputDebugStringW(buffer); |
| 36 |
OutputDebugStringW(L"\n"); |
| 37 |
} |
| 38 |
#ifdef _DEBUG |
| 39 |
DebugBreak(); |
| 40 |
#endif |
| 41 |
#endif |
| 42 |
abort(); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
PyAPI_FUNC(void) |
| 50 |
PyPy_FatalError(const char *msg) |
| 51 |
{ |
| 52 |
fprintf(stderr, "Fatal Python error: %s\n", msg); |
| 53 |
fflush(stderr); |
| 54 |
if (PyErr_Occurred()) { |
| 55 |
PyErr_PrintEx(0); |
| 56 |
} |
| 57 |
#ifdef MS_WINDOWS |
| 58 |
{ |
| 59 |
size_t len = strlen(msg); |
| 60 |
WCHAR* buffer; |
| 61 |
size_t i; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
buffer = alloca( (len+1) * (sizeof *buffer)); |
| 67 |
for( i=0; i<=len; ++i) |
| 68 |
buffer[i] = msg[i]; |
| 69 |
OutputDebugStringW(L"Fatal Python error: "); |
| 70 |
OutputDebugStringW(buffer); |
| 71 |
OutputDebugStringW(L"\n"); |
| 72 |
} |
| 73 |
#ifdef _DEBUG |
| 74 |
DebugBreak(); |
| 75 |
#endif |
| 76 |
#endif |
| 77 |
abort(); |
| 78 |
} |
| 79 |
|
| 80 |
PyInterpreterState * |
| 81 |
PyThreadState_GetInterpreter(PyThreadState *tstate) |
| 82 |
{ |
| 83 |
assert(tstate != NULL); |
| 84 |
return tstate->interp; |
| 85 |
} |