Files
typthon/Python/frozenmain.c
copilot-swe-agent[bot] b198f511d2 Rename Py_ to Ty_ throughout C API
Massive automated renaming of all Py_/PyObject/etc. prefixes to Ty_/TyObject/etc.
This includes:
- All public API types (TyObject, TyTypeObject, etc.)
- All public API functions (Ty_Initialize, Ty_BuildValue, etc.)
- All internal API (_Ty_ prefixes)
- Reference counting macros (Ty_INCREF, Ty_DECREF, etc.)
- Type flags (Ty_TPFLAGS_*)
- Debug flags (Ty_DEBUG, Ty_TRACE_REFS, etc.)
- All object type APIs (TyList_, TyDict_, TyUnicode_, etc.)

This changes over 60,000 occurrences across 1000+ files.

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-29 17:37:49 +00:00

100 lines
2.2 KiB
C

/* Python interpreter main program for frozen scripts */
#include "Python.h"
#include "pycore_pystate.h" // _Ty_GetConfig()
#include "pycore_runtime.h" // _PyRuntime_Initialize()
#ifdef HAVE_UNISTD_H
# include <unistd.h> // isatty()
#endif
#ifdef MS_WINDOWS
extern void PyWinFreeze_ExeInit(void);
extern void PyWinFreeze_ExeTerm(void);
extern int PyInitFrozenExtensions(void);
#endif
/* Main program */
int
Ty_FrozenMain(int argc, char **argv)
{
PyStatus status = _PyRuntime_Initialize();
if (TyStatus_Exception(status)) {
Ty_ExitStatusException(status);
}
PyConfig config;
TyConfig_InitPythonConfig(&config);
// Suppress errors from getpath.c
config.pathconfig_warnings = 0;
// Don't parse command line options like -E
config.parse_argv = 0;
status = TyConfig_SetBytesArgv(&config, argc, argv);
if (TyStatus_Exception(status)) {
TyConfig_Clear(&config);
Ty_ExitStatusException(status);
}
const char *p;
int inspect = 0;
if ((p = Ty_GETENV("PYTHONINSPECT")) && *p != '\0') {
inspect = 1;
}
#ifdef MS_WINDOWS
PyInitFrozenExtensions();
#endif /* MS_WINDOWS */
status = Ty_InitializeFromConfig(&config);
TyConfig_Clear(&config);
if (TyStatus_Exception(status)) {
Ty_ExitStatusException(status);
}
PyInterpreterState *interp = TyInterpreterState_Get();
if (_TyInterpreterState_SetRunningMain(interp) < 0) {
TyErr_Print();
exit(1);
}
#ifdef MS_WINDOWS
PyWinFreeze_ExeInit();
#endif
if (_Ty_GetConfig()->verbose) {
fprintf(stderr, "Typthon %s\n%s\n",
Ty_GetVersion(), Ty_GetCopyright());
}
int sts = 1;
int n = TyImport_ImportFrozenModule("__main__");
if (n == 0) {
Ty_FatalError("the __main__ module is not frozen");
}
if (n < 0) {
TyErr_Print();
sts = 1;
}
else {
sts = 0;
}
if (inspect && isatty((int)fileno(stdin))) {
sts = TyRun_AnyFile(stdin, "<stdin>") != 0;
}
#ifdef MS_WINDOWS
PyWinFreeze_ExeTerm();
#endif
_TyInterpreterState_SetNotRunningMain(interp);
if (Ty_FinalizeEx() < 0) {
sts = 120;
}
return sts;
}