Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94a9667

Browse files
committed
Always insert script directory in front of sys.path -- if there's no
sys.argv, insert "". Note that "." is removed as a default component of the path (see changes to getpath.c and Setup.in).
1 parent 9afdabf commit 94a9667

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

Python/sysmodule.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,27 +360,27 @@ setpythonargv(argc, argv)
360360
char **argv;
361361
{
362362
object *av = makeargvobject(argc, argv);
363+
object *path = sysget("path");
363364
if (av == NULL)
364365
fatal("no mem for sys.argv");
365366
if (sysset("argv", av) != 0)
366367
fatal("can't assign sys.argv");
367-
if (argc > 0) {
368-
object *path = sysget("path");
369-
if (path != NULL) {
370-
char *p = strrchr(argv[0], SEP);
371-
int n;
372-
object *a;
373-
if (p == NULL)
374-
n = 0;
375-
else
376-
n = p + 1 - argv[0];
377-
a = newsizedstringobject(argv[0], n);
378-
if (a == NULL)
379-
fatal("no mem for sys.path insertion");
380-
if (inslistitem(path, 0, a) < 0)
381-
fatal("sys.path.insert(0) failed");
382-
DECREF(a);
383-
}
368+
if (path != NULL) {
369+
char *p = NULL;
370+
int n;
371+
object *a;
372+
if (argc > 0 && argv[0] != NULL)
373+
p = strrchr(argv[0], SEP);
374+
if (p == NULL)
375+
n = 0;
376+
else
377+
n = p + 1 - argv[0];
378+
a = newsizedstringobject(argv[0], n);
379+
if (a == NULL)
380+
fatal("no mem for sys.path insertion");
381+
if (inslistitem(path, 0, a) < 0)
382+
fatal("sys.path.insert(0) failed");
383+
DECREF(a);
384384
}
385385
DECREF(av);
386386
}

0 commit comments

Comments
 (0)