#include "Python.h"
#include "pycore_audit.h"
#include "pycore_call.h"
#include "pycore_ceval.h"
#include "pycore_codecs.h"
#include "pycore_context.h"
#include "pycore_dict.h"
#include "pycore_exceptions.h"
#include "pycore_fileutils.h"
#include "pycore_freelist.h"
#include "pycore_floatobject.h"
#include "pycore_global_objects_fini_generated.h"
#include "pycore_import.h"
#include "pycore_initconfig.h"
#include "pycore_list.h"
#include "pycore_long.h"
#include "pycore_object.h"
#include "pycore_pathconfig.h"
#include "pycore_pyerrors.h"
#include "pycore_pylifecycle.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
#include "pycore_runtime.h"
#include "pycore_runtime_init.h"
#include "pycore_setobject.h"
#include "pycore_sliceobject.h"
#include "pycore_sysmodule.h"
#include "pycore_traceback.h"
#include "pycore_uniqueid.h"
#include "pycore_typeobject.h"
#include "pycore_typevarobject.h"
#include "pycore_unicodeobject.h"
#include "pycore_weakref.h"
#include "pycore_obmalloc.h"
#include "opcode.h"
#include <locale.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(__APPLE__)
# include <mach-o/loader.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
#ifdef HAVE_LANGINFO_H
# include <langinfo.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef MS_WINDOWS
# undef BYTE
#endif
#define PUTS(fd, str) …
static PyStatus add_main_module(PyInterpreterState *interp);
static PyStatus init_import_site(void);
static PyStatus init_set_builtins_open(void);
static PyStatus init_sys_streams(PyThreadState *tstate);
#ifdef __ANDROID__
static PyStatus init_android_streams(PyThreadState *tstate);
#endif
static void wait_for_thread_shutdown(PyThreadState *tstate);
static void finalize_subinterpreters(void);
static void call_ll_exitfuncs(_PyRuntimeState *runtime);
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
#if defined(MS_WINDOWS)
#pragma section("PyRuntime", read, write)
__declspec(allocate("PyRuntime"))
#elif defined(__APPLE__)
__attribute__((
section(SEG_DATA ",PyRuntime")
))
#endif
_PyRuntimeState _PyRuntime
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
__attribute__ ((section (".PyRuntime")))
#endif
= …;
_Py_COMP_DIAG_POP
static int runtime_initialized = …;
PyStatus
_PyRuntime_Initialize(void)
{ … }
void
_PyRuntime_Finalize(void)
{ … }
int
Py_IsFinalizing(void)
{ … }
int (*_PyOS_mystrnicmp_hack)(const char *, const char *, Py_ssize_t) = …;
int
_Py_IsCoreInitialized(void)
{ … }
int
Py_IsInitialized(void)
{ … }
int
_Py_LegacyLocaleDetected(int warn)
{ … }
#ifndef MS_WINDOWS
static const char *_C_LOCALE_WARNING = …;
static void
emit_stderr_warning_for_legacy_locale(_PyRuntimeState *runtime)
{ … }
#endif
_LocaleCoercionTarget;
static _LocaleCoercionTarget _TARGET_LOCALES[] = …;
int
_Py_IsLocaleCoercionTarget(const char *ctype_loc)
{ … }
#ifdef PY_COERCE_C_LOCALE
static const char C_LOCALE_COERCION_WARNING[] = …;
static int
_coerce_default_locale_settings(int warn, const _LocaleCoercionTarget *target)
{ … }
#endif
int
_Py_CoerceLegacyLocale(int warn)
{ … }
char *
_Py_SetLocaleFromEnv(int category)
{ … }
static int
interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
{ … }
int
_PyInterpreterState_SetConfig(const PyConfig *src_config)
{ … }
static PyStatus
pyinit_core_reconfigure(_PyRuntimeState *runtime,
PyThreadState **tstate_p,
const PyConfig *config)
{ … }
static PyStatus
pycore_init_runtime(_PyRuntimeState *runtime,
const PyConfig *config)
{ … }
static PyStatus
init_interp_settings(PyInterpreterState *interp,
const PyInterpreterConfig *config)
{ … }
static void
init_interp_create_gil(PyThreadState *tstate, int gil)
{ … }
static int
builtins_dict_watcher(PyDict_WatchEvent event, PyObject *dict, PyObject *key, PyObject *new_value)
{ … }
static PyStatus
pycore_create_interpreter(_PyRuntimeState *runtime,
const PyConfig *src_config,
PyThreadState **tstate_p)
{ … }
static PyStatus
pycore_init_global_objects(PyInterpreterState *interp)
{ … }
static PyStatus
pycore_init_types(PyInterpreterState *interp)
{ … }
static PyStatus
pycore_init_builtins(PyThreadState *tstate)
{ … }
static PyStatus
pycore_interp_init(PyThreadState *tstate)
{ … }
static PyStatus
pyinit_config(_PyRuntimeState *runtime,
PyThreadState **tstate_p,
const PyConfig *config)
{ … }
PyStatus
_Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
{ … }
PyStatus
Py_PreInitializeFromBytesArgs(const PyPreConfig *src_config, Py_ssize_t argc, char **argv)
{ … }
PyStatus
Py_PreInitializeFromArgs(const PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv)
{ … }
PyStatus
Py_PreInitialize(const PyPreConfig *src_config)
{ … }
PyStatus
_Py_PreInitializeFromConfig(const PyConfig *config,
const _PyArgv *args)
{ … }
static PyStatus
pyinit_core(_PyRuntimeState *runtime,
const PyConfig *src_config,
PyThreadState **tstate_p)
{ … }
static PyStatus
pyinit_main_reconfigure(PyThreadState *tstate)
{ … }
#ifdef Py_DEBUG
static void
run_presite(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
if (!config->run_presite) {
return;
}
PyObject *presite_modname = PyUnicode_FromWideChar(
config->run_presite,
wcslen(config->run_presite)
);
if (presite_modname == NULL) {
fprintf(stderr, "Could not convert pre-site module name to unicode\n");
}
else {
PyObject *presite = PyImport_Import(presite_modname);
if (presite == NULL) {
fprintf(stderr, "pre-site import failed:\n");
_PyErr_Print(tstate);
}
Py_XDECREF(presite);
Py_DECREF(presite_modname);
}
}
#endif
static PyStatus
init_interp_main(PyThreadState *tstate)
{ … }
static PyStatus
pyinit_main(PyThreadState *tstate)
{ … }
PyStatus
Py_InitializeFromConfig(const PyConfig *config)
{ … }
void
Py_InitializeEx(int install_sigs)
{ … }
void
Py_Initialize(void)
{ … }
PyStatus
_Py_InitializeMain(void)
{ … }
static void
finalize_modules_delete_special(PyThreadState *tstate, int verbose)
{ … }
static PyObject*
finalize_remove_modules(PyObject *modules, int verbose)
{ … }
static void
finalize_clear_modules_dict(PyObject *modules)
{ … }
static void
finalize_restore_builtins(PyThreadState *tstate)
{ … }
static void
finalize_modules_clear_weaklist(PyInterpreterState *interp,
PyObject *weaklist, int verbose)
{ … }
static void
finalize_clear_sys_builtins_dict(PyInterpreterState *interp, int verbose)
{ … }
static void
finalize_modules(PyThreadState *tstate)
{ … }
static int
file_is_closed(PyObject *fobj)
{ … }
static int
flush_std_files(void)
{ … }
static void
finalize_interp_types(PyInterpreterState *interp)
{ … }
static void
finalize_interp_clear(PyThreadState *tstate)
{ … }
static void
finalize_interp_delete(PyInterpreterState *interp)
{ … }
static PyThreadState *
resolve_final_tstate(_PyRuntimeState *runtime)
{ … }
static int
_Py_Finalize(_PyRuntimeState *runtime)
{ … }
int
Py_FinalizeEx(void)
{ … }
void
Py_Finalize(void)
{ … }
static PyStatus
new_interpreter(PyThreadState **tstate_p,
const PyInterpreterConfig *config, long whence)
{ … }
PyStatus
Py_NewInterpreterFromConfig(PyThreadState **tstate_p,
const PyInterpreterConfig *config)
{ … }
PyThreadState *
Py_NewInterpreter(void)
{ … }
void
Py_EndInterpreter(PyThreadState *tstate)
{ … }
int
_Py_IsInterpreterFinalizing(PyInterpreterState *interp)
{ … }
static void
finalize_subinterpreters(void)
{ … }
static PyStatus
add_main_module(PyInterpreterState *interp)
{ … }
static PyStatus
init_import_site(void)
{ … }
static PyObject*
create_stdio(const PyConfig *config, PyObject* io,
int fd, int write_mode, const char* name,
const wchar_t* encoding, const wchar_t* errors)
{ … }
static PyStatus
init_set_builtins_open(void)
{ … }
static PyStatus
init_sys_streams(PyThreadState *tstate)
{ … }
#ifdef __ANDROID__
#include <android/log.h>
static PyObject *
android_log_write_impl(PyObject *self, PyObject *args)
{
int prio = 0;
const char *tag = NULL;
const char *text = NULL;
if (!PyArg_ParseTuple(args, "isy", &prio, &tag, &text)) {
return NULL;
}
__android_log_write(prio, tag, text);
Py_RETURN_NONE;
}
static PyMethodDef android_log_write_method = {
"android_log_write", android_log_write_impl, METH_VARARGS
};
static PyStatus
init_android_streams(PyThreadState *tstate)
{
PyStatus status = _PyStatus_OK();
PyObject *_android_support = NULL;
PyObject *android_log_write = NULL;
PyObject *result = NULL;
_android_support = PyImport_ImportModule("_android_support");
if (_android_support == NULL) {
goto error;
}
android_log_write = PyCFunction_New(&android_log_write_method, NULL);
if (android_log_write == NULL) {
goto error;
}
result = PyObject_CallMethod(
_android_support, "init_streams", "Oii",
android_log_write, ANDROID_LOG_INFO, ANDROID_LOG_WARN);
if (result == NULL) {
goto error;
}
goto done;
error:
_PyErr_Print(tstate);
status = _PyStatus_ERR("failed to initialize Android streams");
done:
Py_XDECREF(result);
Py_XDECREF(android_log_write);
Py_XDECREF(_android_support);
return status;
}
#endif
static void
_Py_FatalError_DumpTracebacks(int fd, PyInterpreterState *interp,
PyThreadState *tstate)
{ … }
static int
_Py_FatalError_PrintExc(PyThreadState *tstate)
{ … }
#ifdef MS_WINDOWS
static void
fatal_output_debug(const char *msg)
{
WCHAR buffer[256 / sizeof(WCHAR)];
size_t buflen = Py_ARRAY_LENGTH(buffer) - 1;
size_t msglen;
OutputDebugStringW(L"Fatal Python error: ");
msglen = strlen(msg);
while (msglen) {
size_t i;
if (buflen > msglen) {
buflen = msglen;
}
for (i=0; i < buflen; ++i) {
buffer[i] = msg[i];
}
buffer[i] = L'\0';
OutputDebugStringW(buffer);
msg += buflen;
msglen -= buflen;
}
OutputDebugStringW(L"\n");
}
#endif
static void
fatal_error_dump_runtime(int fd, _PyRuntimeState *runtime)
{ … }
static inline void _Py_NO_RETURN
fatal_error_exit(int status)
{ … }
static inline int
acquire_dict_lock_for_dump(PyObject *obj)
{ … }
static inline void
release_dict_lock_for_dump(PyObject *obj)
{ … }
void
_Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
{ … }
static void _Py_NO_RETURN
fatal_error(int fd, int header, const char *prefix, const char *msg,
int status)
{ … }
#undef Py_FatalError
void _Py_NO_RETURN
Py_FatalError(const char *msg)
{ … }
void _Py_NO_RETURN
_Py_FatalErrorFunc(const char *func, const char *msg)
{ … }
void _Py_NO_RETURN
_Py_FatalErrorFormat(const char *func, const char *format, ...)
{ … }
void _Py_NO_RETURN
_Py_FatalRefcountErrorFunc(const char *func, const char *msg)
{ … }
void _Py_NO_RETURN
Py_ExitStatusException(PyStatus status)
{ … }
static void
wait_for_thread_shutdown(PyThreadState *tstate)
{ … }
int Py_AtExit(void (*func)(void))
{ … }
static void
call_ll_exitfuncs(_PyRuntimeState *runtime)
{ … }
void _Py_NO_RETURN
Py_Exit(int sts)
{ … }
int
Py_FdIsInteractive(FILE *fp, const char *filename)
{ … }
int
_Py_FdIsInteractive(FILE *fp, PyObject *filename)
{ … }
PyOS_sighandler_t
PyOS_getsig(int sig)
{ … }
PyOS_sighandler_t
PyOS_setsig(int sig, PyOS_sighandler_t handler)
{ … }