5
5
#include <locale.h>
6
6
7
7
void Py_InitArgcArgv (int argc , wchar_t * * argv );
8
+ char * GetPyMain ();
8
9
9
10
static const char * env_entry_point = "Y_PYTHON_ENTRY_POINT" ;
10
11
@@ -109,9 +110,26 @@ static int pymain(int argc, char** argv) {
109
110
oldloc = NULL ;
110
111
111
112
const char * entry_point = getenv (env_entry_point );
112
- if (entry_point && !strcmp (entry_point , ":main" )) {
113
+ if (entry_point ) {
114
+ entry_point_copy = strdup (entry_point );
115
+ if (!entry_point_copy ) {
116
+ fprintf (stderr , "out of memory\n" );
117
+ goto error ;
118
+ }
119
+ } else {
120
+ entry_point_copy = GetPyMain ();
121
+ }
122
+
123
+ if (entry_point_copy == NULL ) {
124
+ fprintf (stderr , "No entry point, did you forget PY_MAIN?\n" );
125
+ goto error ;
126
+ }
127
+
128
+ if (entry_point_copy && !strcmp (entry_point_copy , ":main" )) {
113
129
unsetenv (env_entry_point );
114
- return Py_Main (argc , argv_copy );
130
+ sts = Py_Main (argc , argv_copy );
131
+ free (entry_point_copy );
132
+ return sts ;
115
133
}
116
134
117
135
Py_InitArgcArgv (argc , argv_copy );
@@ -121,8 +139,6 @@ static int pymain(int argc, char** argv) {
121
139
122
140
PySys_SetArgv (argc , argv_copy );
123
141
124
- PyObject * py_main = NULL ;
125
-
126
142
{
127
143
PyObject * module = PyImport_ImportModule ("library.python.runtime_py3.entry_points" );
128
144
if (module == NULL ) {
@@ -138,37 +154,6 @@ static int pymain(int argc, char** argv) {
138
154
}
139
155
}
140
156
141
- if (entry_point == NULL ) {
142
- PyObject * res = PyImport_ImportModule ("__res" );
143
- if (res == NULL ) {
144
- PyErr_Clear ();
145
- } else {
146
- py_main = PyObject_CallMethod (res , "find" , "y" , "PY_MAIN" );
147
-
148
- if (py_main == NULL ) {
149
- PyErr_Clear ();
150
- } else {
151
- if (PyBytes_Check (py_main )) {
152
- entry_point = PyBytes_AsString (py_main );
153
- }
154
- }
155
-
156
- Py_DECREF (res );
157
- }
158
- }
159
-
160
- if (entry_point == NULL ) {
161
- fprintf (stderr , "No entry point, did you forget PY_MAIN?\n" );
162
- goto error ;
163
- }
164
-
165
- entry_point_copy = strdup (entry_point );
166
- Py_XDECREF (py_main );
167
- if (!entry_point_copy ) {
168
- fprintf (stderr , "out of memory\n" );
169
- goto error ;
170
- }
171
-
172
157
const char * module_name = entry_point_copy ;
173
158
const char * func_name = NULL ;
174
159
0 commit comments