File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1?
1010Core and Builtins
1111-----------------
1212
13+ - Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
14+
1315- Issue #29337: Fixed possible BytesWarning when compare the code objects.
1416 Warnings could be emitted at compile time.
1517
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ static int RunModule(wchar_t *modname, int set_argv0)
228228static int
229229RunMainFromImporter (wchar_t * filename )
230230{
231- PyObject * argv0 = NULL , * importer , * sys_path ;
231+ PyObject * argv0 = NULL , * importer , * sys_path , * sys_path0 ;
232232 int sts ;
233233
234234 argv0 = PyUnicode_FromWideChar (filename , wcslen (filename ));
@@ -253,7 +253,17 @@ RunMainFromImporter(wchar_t *filename)
253253 PyErr_SetString (PyExc_RuntimeError , "unable to get sys.path" );
254254 goto error ;
255255 }
256- if (PyList_SetItem (sys_path , 0 , argv0 )) {
256+ sys_path0 = PyList_GetItem (sys_path , 0 );
257+ sts = 0 ;
258+ if (!sys_path0 ) {
259+ PyErr_Clear ();
260+ sts = PyList_Append (sys_path , argv0 );
261+ } else if (PyObject_IsTrue (sys_path0 )) {
262+ sts = PyList_Insert (sys_path , 0 , argv0 );
263+ } else {
264+ sts = PyList_SetItem (sys_path , 0 , argv0 );
265+ }
266+ if (sts ) {
257267 argv0 = NULL ;
258268 goto error ;
259269 }
You can’t perform that action at this time.
0 commit comments