Files
typthon/Python/frozenmain.c
copilot-swe-agent[bot] 71cf7bf14f Fix more missed Py_ patterns - opcode, thread, exception
Fixed additional patterns:
- _PyOpcode_* → _TyOpcode_* (all opcode metadata)
- _PyUOpName → _TyUOpName
- _PyFunction_* → _TyFunction_*
- _PyListIterObject → _TyListIterObject
- _Py_T_OBJECT → _Ty_T_OBJECT
- Py_BEGIN_ALLOW_THREADS, Py_END_ALLOW_THREADS → Ty_*
- PyDoc_STRVAR, PyDoc_STR → TyDoc_*
- PyInterpreterState, PyThread_*, PyTime_t → Ty*
- PyStructSequence_* → TyStructSequence_*
- PyLockStatus → TyLockStatus
- PyVarObject_HEAD_INIT → TyVarObject_HEAD_INIT
- PyBaseExceptionObject → TyBaseExceptionObject
- Fixed _PyExc_ → _TyExc_ in exception macros

Build is progressing further.

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-29 18:27:36 +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)
{
TyStatus 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);
}
TyInterpreterState *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;
}