| 78 | static int pymain(int argc, wchar_t** argv) |
| 79 | #else |
| 80 | static int pymain(int argc, char** argv) |
| 81 | #endif |
| 82 | { |
| 83 | PyStatus status; |
| 84 | |
| 85 | if (IsYaIdeVenv()) { |
| 86 | #ifdef MS_WINDOWS |
| 87 | return Py_Main(argc, argv); |
| 88 | #else |
| 89 | return Py_BytesMain(argc, argv); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | status = _PyRuntime_Initialize(); |
| 94 | if (PyStatus_Exception(status)) { |
| 95 | Py_ExitStatusException(status); |
| 96 | } |
| 97 | |
| 98 | PyPreConfig preconfig; |
| 99 | PyPreConfig_InitPythonConfig(&preconfig); |
| 100 | // Enable UTF-8 mode for all (DEVTOOLSSUPPORT-46624) |
| 101 | preconfig.utf8_mode = 1; |
| 102 | #ifdef MS_WINDOWS |
| 103 | preconfig.legacy_windows_fs_encoding = 0; |
| 104 | #endif |
| 105 | |
| 106 | status = Py_PreInitialize(&preconfig); |
| 107 | if (PyStatus_Exception(status)) { |
| 108 | Py_ExitStatusException(status); |
| 109 | } |
| 110 | |
| 111 | int sts = 1; |
| 112 | char* entry_point_copy = NULL; |
| 113 | |
| 114 | PyConfig config; |
| 115 | PyConfig_InitPythonConfig(&config); |
| 116 | // Suppress errors from getpath.c |
| 117 | config.pathconfig_warnings = 0; |
| 118 | // Disable parsing command line arguments |
| 119 | config.parse_argv = 0; |
| 120 | |
| 121 | const char* bytes_warning = getenv(env_bytes_warning); |
| 122 | if (bytes_warning) { |
| 123 | config.bytes_warning = atoi(bytes_warning); |
| 124 | } |
| 125 | |
| 126 | if (argc > 0 && argv) { |
| 127 | #ifdef MS_WINDOWS |
| 128 | status = PyConfig_SetString(&config, &config.program_name, argv[0]); |
| 129 | #else |
| 130 | status = PyConfig_SetBytesString(&config, &config.program_name, argv[0]); |
| 131 | #endif |
| 132 | if (PyStatus_Exception(status)) { |
| 133 | goto error; |
| 134 | } |
| 135 | |
| 136 | #ifdef MS_WINDOWS |
| 137 | status = PyConfig_SetArgv(&config, argc, argv); |