Debian Codegraph @

pypy/module/cpyext/src/pythonrun.c

raw symbols SCIP
1
2 #include "Python.h"
3
4 #ifdef MS_WINDOWS
5 #include "malloc.h" /* for alloca */
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); /* it helps in Windows debug build */
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 /* Convert the message to wchar_t. This uses a simple one-to-one
29 conversion, assuming that the this error message actually uses ASCII
30 only. If this ceases to be true, we will have to convert. */
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 /* MS_WINDOWS */
42 abort();
43 }
44
45 /* Somewhere in the py3.10 development cycle, Py_FatalError became a macro that
46 * uses __function__ to call _Py_FatalErrorFunc. But for backwards
47 * compatiblity, export the old funcion from the shared object
48 */
49 PyAPI_FUNC(void)
50 PyPy_FatalError(const char *msg)
51 {
52 fprintf(stderr, "Fatal Python error: %s\n", msg);
53 fflush(stderr); /* it helps in Windows debug build */
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 /* Convert the message to wchar_t. This uses a simple one-to-one
64 conversion, assuming that the this error message actually uses ASCII
65 only. If this ceases to be true, we will have to convert. */
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 /* MS_WINDOWS */
77 abort();
78 }
79
80 PyInterpreterState *
81 PyThreadState_GetInterpreter(PyThreadState *tstate)
82 {
83 assert(tstate != NULL);
84 return tstate->interp;
85 }