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

Skip to content

Commit 162e38c

Browse files
committed
- sys.path[0] (the directory from which the script is loaded) is now
turned into an absolute pathname, unless it is the empty string. (SF patch #664376, by Skip Montanaro.)
1 parent 80be59b commit 162e38c

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 2.3 alpha 2?
1212
Core and builtins
1313
-----------------
1414

15+
- sys.path[0] (the directory from which the script is loaded) is now
16+
turned into an absolute pathname, unless it is the empty string.
17+
(SF patch #664376.)
18+
1519
- Finally fixed the bug in compile() and exec where a string ending
1620
with an indented code block but no newline would raise SyntaxError.
1721
This would have been a four-line change in parsetok.c... Except

Python/sysmodule.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,9 @@ makeargvobject(int argc, char **argv)
993993
void
994994
PySys_SetArgv(int argc, char **argv)
995995
{
996-
#ifdef MS_WINDOWS
996+
#if defined(HAVE_REALPATH)
997+
char fullpath[MAXPATHLEN];
998+
#elif defined(MS_WINDOWS)
997999
char fullpath[MAX_PATH];
9981000
#endif
9991001
PyObject *av = makeargvobject(argc, argv);
@@ -1059,8 +1061,14 @@ PySys_SetArgv(int argc, char **argv)
10591061
}
10601062
}
10611063
#else /* All other filename syntaxes */
1062-
if (argc > 0 && argv0 != NULL)
1064+
if (argc > 0 && argv0 != NULL) {
1065+
#if defined(HAVE_REALPATH)
1066+
if (realpath(argv0, fullpath)) {
1067+
argv0 = fullpath;
1068+
}
1069+
#endif
10631070
p = strrchr(argv0, SEP);
1071+
}
10641072
if (p != NULL) {
10651073
#ifndef RISCOS
10661074
n = p + 1 - argv0;

configure

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.387 .
2+
# From configure.in Revision: 1.389 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53 for python 2.3.
55
#
@@ -12093,6 +12093,7 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
1209312093
1209412094
1209512095
12096+
1209612097
1209712098
1209812099
for ac_func in alarm chown clock confstr ctermid execv \
@@ -12101,7 +12102,7 @@ for ac_func in alarm chown clock confstr ctermid execv \
1210112102
getpriority getpwent getwd \
1210212103
hstrerror inet_aton inet_pton kill killpg lchown lstat mkfifo mknod mktime \
1210312104
mremap nice pathconf pause plock poll pthread_init \
12104-
putenv readlink \
12105+
putenv readlink realpath \
1210512106
select setegid seteuid setgid \
1210612107
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
1210712108
sigaction siginterrupt sigrelse strftime strptime \

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ AC_CHECK_FUNCS(alarm chown clock confstr ctermid execv \
18431843
getpriority getpwent getwd \
18441844
hstrerror inet_aton inet_pton kill killpg lchown lstat mkfifo mknod mktime \
18451845
mremap nice pathconf pause plock poll pthread_init \
1846-
putenv readlink \
1846+
putenv readlink realpath \
18471847
select setegid seteuid setgid \
18481848
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
18491849
sigaction siginterrupt sigrelse strftime strptime \

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@
342342
/* Define to 1 if you have the `readlink' function. */
343343
#undef HAVE_READLINK
344344

345+
/* Define to 1 if you have the `realpath' function. */
346+
#undef HAVE_REALPATH
347+
345348
/* Define if you have readline 2.2 */
346349
#undef HAVE_RL_COMPLETION_APPEND_CHARACTER
347350

0 commit comments

Comments
 (0)