Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 3806:93868c7a15c9 legacy-trunk
As a side effect of calling PySys_SetArgv (setpythonargv), the
directory containing argv[0] is inserted in front of sys.path.
If argv[0] contains no directory, an empty string is inserted.
If argv is empty, nothing happens.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 24 Jul 1996 01:31:37 +0000 |
| parents | ce74bba8a6a6 |
| children | 408e374934e5 |
line wrap: on
line diff
--- a/Python/sysmodule.c Wed Jul 24 00:55:17 1996 +0000 +++ b/Python/sysmodule.c Wed Jul 24 01:31:37 1996 +0000 @@ -364,5 +364,23 @@ fatal("no mem for sys.argv"); if (sysset("argv", av) != 0) fatal("can't assign sys.argv"); + if (argc > 0) { + object *path = sysget("path"); + if (path != NULL) { + char *p = strrchr(argv[0], SEP); + int n; + object *a; + if (p == NULL) + n = 0; + else + n = p + 1 - argv[0]; + a = newsizedstringobject(argv[0], n); + if (a == NULL) + fatal("no mem for sys.path insertion"); + if (inslistitem(path, 0, a) < 0) + fatal("sys.path.insert(0) failed"); + DECREF(a); + } + } DECREF(av); }
