1717
1818#include <locale.h> // setlocale()
1919
20+ #if defined(__APPLE__ )
21+ #include <mach-o/loader.h>
22+ #endif
23+
2024#ifdef HAVE_SIGNAL_H
2125# include <signal.h> // SIG_IGN
2226#endif
3438 (PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
3539#endif
3640
37-
3841#define PUTS (fd , str ) _Py_write_noraise(fd, str, (int)strlen(str))
3942
4043
@@ -59,7 +62,30 @@ static void wait_for_thread_shutdown(PyThreadState *tstate);
5962static void call_ll_exitfuncs (_PyRuntimeState * runtime );
6063
6164int _Py_UnhandledKeyboardInterrupt = 0 ;
62- _PyRuntimeState _PyRuntime = _PyRuntimeState_INIT ;
65+
66+ /* The following places the `_PyRuntime` structure in a location that can be
67+ * found without any external information. This is meant to ease access to the
68+ * interpreter state for various runtime debugging tools, but is *not* an
69+ * officially supported feature */
70+
71+ #if defined(MS_WINDOWS )
72+
73+ #pragma section("PyRuntime", read, write)
74+ __declspec(allocate ("PyRuntime" ))
75+
76+ #elif defined(__APPLE__ )
77+
78+ __attribute__((
79+ section (SEG_DATA ",PyRuntime" )
80+ ))
81+
82+ #endif
83+
84+ _PyRuntimeState _PyRuntime
85+ #if defined(__linux__ ) && (defined(__GNUC__ ) || defined(__clang__ ))
86+ __attribute__ ((section (".PyRuntime" )))
87+ #endif
88+ = _PyRuntimeState_INIT ;
6389static int runtime_initialized = 0 ;
6490
6591PyStatus
0 commit comments