- 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.)
diff --git a/Misc/NEWS b/Misc/NEWS
index 8671650..7198541 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@
 Core and builtins
 -----------------
 
+- 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.)
+
 - Finally fixed the bug in compile() and exec where a string ending
   with an indented code block but no newline would raise SyntaxError.
   This would have been a four-line change in parsetok.c...  Except
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 765621e..1f51f98 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -993,7 +993,9 @@
 void
 PySys_SetArgv(int argc, char **argv)
 {
-#ifdef MS_WINDOWS
+#if defined(HAVE_REALPATH)
+	char fullpath[MAXPATHLEN];
+#elif defined(MS_WINDOWS)
 	char fullpath[MAX_PATH];
 #endif
 	PyObject *av = makeargvobject(argc, argv);
@@ -1059,8 +1061,14 @@
 			}
 		}
 #else /* All other filename syntaxes */
-		if (argc > 0 && argv0 != NULL)
+		if (argc > 0 && argv0 != NULL) {
+#if defined(HAVE_REALPATH)
+			if (realpath(argv0, fullpath)) {
+				argv0 = fullpath;
+			}
+#endif
 			p = strrchr(argv0, SEP);
+		}
 		if (p != NULL) {
 #ifndef RISCOS
 			n = p + 1 - argv0;
diff --git a/configure b/configure
index e0837f7..1dfc8bc 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 1.387 .
+# From configure.in Revision: 1.389 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.53 for python 2.3.
 #
@@ -12095,13 +12095,14 @@
 
 
 
+
 for ac_func in alarm chown clock confstr ctermid execv \
  fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
  gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
  getpriority getpwent getwd \
  hstrerror inet_aton inet_pton kill killpg lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
- putenv readlink \
+ putenv readlink realpath \
  select setegid seteuid setgid \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime \
diff --git a/configure.in b/configure.in
index 8fce1cd..0b893a5 100644
--- a/configure.in
+++ b/configure.in
@@ -1843,7 +1843,7 @@
  getpriority getpwent getwd \
  hstrerror inet_aton inet_pton kill killpg lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
- putenv readlink \
+ putenv readlink realpath \
  select setegid seteuid setgid \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime \
diff --git a/pyconfig.h.in b/pyconfig.h.in
index c169797..e2dd4d2 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -342,6 +342,9 @@
 /* Define to 1 if you have the `readlink' function. */
 #undef HAVE_READLINK
 
+/* Define to 1 if you have the `realpath' function. */
+#undef HAVE_REALPATH
+
 /* Define if you have readline 2.2 */
 #undef HAVE_RL_COMPLETION_APPEND_CHARACTER