@@ -20,74 +20,28 @@ Py_FrozenMain(int argc, char **argv)
20
20
Py_ExitStatusException (status );
21
21
}
22
22
23
- const char * p ;
24
- int i , n , sts = 1 ;
25
- int inspect = 0 ;
26
- int unbuffered = 0 ;
27
- char * oldloc = NULL ;
28
- wchar_t * * argv_copy = NULL ;
29
- /* We need a second copies, as Python might modify the first one. */
30
- wchar_t * * argv_copy2 = NULL ;
31
-
32
- if (argc > 0 ) {
33
- argv_copy = PyMem_RawMalloc (sizeof (wchar_t * ) * argc );
34
- argv_copy2 = PyMem_RawMalloc (sizeof (wchar_t * ) * argc );
35
- if (!argv_copy || !argv_copy2 ) {
36
- fprintf (stderr , "out of memory\n" );
37
- goto error ;
38
- }
39
- }
40
-
41
23
PyConfig config ;
42
24
PyConfig_InitPythonConfig (& config );
43
- config .pathconfig_warnings = 0 ; /* Suppress errors from getpath.c */
44
-
45
- if ((p = Py_GETENV ("PYTHONINSPECT" )) && * p != '\0' ) {
46
- inspect = 1 ;
47
- }
48
- if ((p = Py_GETENV ("PYTHONUNBUFFERED" )) && * p != '\0' ) {
49
- unbuffered = 1 ;
50
- }
51
-
52
- if (unbuffered ) {
53
- setbuf (stdin , (char * )NULL );
54
- setbuf (stdout , (char * )NULL );
55
- setbuf (stderr , (char * )NULL );
56
- }
25
+ // Suppress errors from getpath.c
26
+ config .pathconfig_warnings = 0 ;
27
+ // Don't parse command line options like -E
28
+ config .parse_argv = 0 ;
57
29
58
- oldloc = _PyMem_RawStrdup ( setlocale ( LC_ALL , NULL ) );
59
- if (! oldloc ) {
60
- fprintf ( stderr , "out of memory\n" );
61
- goto error ;
30
+ status = PyConfig_SetBytesArgv ( & config , argc , argv );
31
+ if (PyStatus_Exception ( status ) ) {
32
+ PyConfig_Clear ( & config );
33
+ Py_ExitStatusException ( status ) ;
62
34
}
63
35
64
- setlocale (LC_ALL , "" );
65
- for (i = 0 ; i < argc ; i ++ ) {
66
- argv_copy [i ] = Py_DecodeLocale (argv [i ], NULL );
67
- argv_copy2 [i ] = argv_copy [i ];
68
- if (!argv_copy [i ]) {
69
- fprintf (stderr ,
70
- "Unable to decode the command line argument #%i\n" ,
71
- i + 1 );
72
- argc = i ;
73
- goto error ;
74
- }
36
+ const char * p ;
37
+ int inspect = 0 ;
38
+ if ((p = Py_GETENV ("PYTHONINSPECT" )) && * p != '\0' ) {
39
+ inspect = 1 ;
75
40
}
76
- setlocale (LC_ALL , oldloc );
77
- PyMem_RawFree (oldloc );
78
- oldloc = NULL ;
79
41
80
42
#ifdef MS_WINDOWS
81
43
PyInitFrozenExtensions ();
82
44
#endif /* MS_WINDOWS */
83
- if (argc >= 1 ) {
84
- status = PyConfig_SetString (& config , & config .program_name ,
85
- argv_copy [0 ]);
86
- if (PyStatus_Exception (status )) {
87
- PyConfig_Clear (& config );
88
- Py_ExitStatusException (status );
89
- }
90
- }
91
45
92
46
status = Py_InitializeFromConfig (& config );
93
47
PyConfig_Clear (& config );
@@ -104,9 +58,8 @@ Py_FrozenMain(int argc, char **argv)
104
58
Py_GetVersion (), Py_GetCopyright ());
105
59
}
106
60
107
- PySys_SetArgv (argc , argv_copy );
108
-
109
- n = PyImport_ImportFrozenModule ("__main__" );
61
+ int sts = 1 ;
62
+ int n = PyImport_ImportFrozenModule ("__main__" );
110
63
if (n == 0 ) {
111
64
Py_FatalError ("the __main__ module is not frozen" );
112
65
}
@@ -128,14 +81,5 @@ Py_FrozenMain(int argc, char **argv)
128
81
if (Py_FinalizeEx () < 0 ) {
129
82
sts = 120 ;
130
83
}
131
-
132
- error :
133
- PyMem_RawFree (argv_copy );
134
- if (argv_copy2 ) {
135
- for (i = 0 ; i < argc ; i ++ )
136
- PyMem_RawFree (argv_copy2 [i ]);
137
- PyMem_RawFree (argv_copy2 );
138
- }
139
- PyMem_RawFree (oldloc );
140
84
return sts ;
141
85
}
0 commit comments