@@ -74,6 +74,39 @@ struct _inittab inittab[] = {
74
74
{ 0 , 0 }
75
75
};
76
76
77
+
78
+ void
79
+ freeWchar (wchar_t * strings [],
80
+ const int nstrings ) {
81
+ int i ;
82
+
83
+ for (i = 0 ; i < nstrings ; ++ i ) {
84
+ PyMem_RawFree (strings [i ]);
85
+ }
86
+ PyMem_RawFree (strings );
87
+ }
88
+
89
+
90
+ wchar_t * *
91
+ wcharFromChar (char * strings [],
92
+ const int nstrings ) {
93
+ int i ;
94
+
95
+ wchar_t * * wstrings = PyMem_RawMalloc (sizeof (wchar_t * )* nstrings );
96
+ if (!wstrings ) { return NULL ; }
97
+
98
+ for (i = 0 ; i < nstrings ; ++ i ) {
99
+ wstrings [i ] = Py_DecodeLocale (strings [i ], NULL );
100
+ if (!wstrings [i ]) {
101
+ freeWchar (wstrings , i );
102
+ return NULL ;
103
+ }
104
+ }
105
+
106
+ return wstrings ;
107
+ }
108
+
109
+
77
110
int main (int argc , char * argv [])
78
111
{
79
112
int c_status ;
@@ -106,19 +139,25 @@ int main(int argc, char* argv[])
106
139
107
140
return Py_RunMain ();
108
141
} else {
109
- PyConfig_InitIsolatedConfig (& config );
142
+ PyConfig_InitPythonConfig (& config );
110
143
111
144
py_status = PyConfig_SetBytesString (& config , & config .program_name , argv [0 ]);
112
145
if (PyStatus_Exception (py_status )) { goto exception ; }
113
146
114
- py_status = PyConfig_SetBytesArgv (& config , argc - 1 , argv + 1 );
115
- if (PyStatus_Exception (py_status )) { goto exception ; }
116
-
117
147
py_status = Py_InitializeFromConfig (& config );
118
148
if (PyStatus_Exception (py_status )) { goto exception ; }
119
149
120
150
PyConfig_Clear (& config );
121
151
152
+ /* :KLUDGE: PySys_SetArgv() is deprecated in v3.11 and is scheduled
153
+ * for removal in v3.13. Switching to Michael Aivazis' current Pyre
154
+ * should make this code obsolete and allow us to circumvent this
155
+ * deprecation.
156
+ */
157
+ wchar_t * * w_argv = wcharFromChar (argv , argc );
158
+ PySys_SetArgv (argc - 1 , w_argv + 1 );
159
+ freeWchar (w_argv , argc );
160
+
122
161
c_status = PyRun_SimpleString (COMMAND );
123
162
124
163
Py_FinalizeEx ();
0 commit comments