once more into the breach...

This commit is contained in:
Peter Jones 2005-09-26 22:19:21 +00:00
parent db45b4b464
commit 6f931e7996
1 changed files with 57 additions and 23 deletions

View File

@ -1,5 +1,5 @@
--- Python-2.4.1/pyconfig.h.in.canonicalize 2004-10-13 11:30:55.000000000 -0400
+++ Python-2.4.1/pyconfig.h.in 2005-09-25 16:30:43.000000000 -0400
+++ Python-2.4.1/pyconfig.h.in 2005-09-26 16:03:35.000000000 -0400
@@ -58,6 +58,9 @@
/* Define if pthread_sigmask() does not work on your system. */
#undef HAVE_BROKEN_PTHREAD_SIGMASK
@ -11,7 +11,7 @@
#undef HAVE_CHOWN
--- Python-2.4.1/Python/sysmodule.c.canonicalize 2005-01-27 13:58:30.000000000 -0500
+++ Python-2.4.1/Python/sysmodule.c 2005-09-25 16:38:47.000000000 -0400
+++ Python-2.4.1/Python/sysmodule.c 2005-09-26 16:24:37.000000000 -0400
@@ -1168,11 +1168,13 @@
void
PySys_SetArgv(int argc, char **argv)
@ -26,41 +26,75 @@
PyObject *av = makeargvobject(argc, argv);
PyObject *path = PySys_GetObject("path");
if (av == NULL)
@@ -1184,6 +1186,33 @@
@@ -1184,6 +1186,67 @@
char *p = NULL;
int n = 0;
PyObject *a;
+#ifdef HAVE_CANONICALIZE_FILE_NAME
+ char *link = NULL, *argv0copy = NULL;
+ int errnum;
+
+ if (argc > 0 && argv0 != NULL) {
+ if (argv[0][0] == '\0')
+ /* python started with no arguments
+ copy the empty string and move on */
+ argv0 = strdup(argv[0]);
+ else {
+ argv0 = canonicalize_file_name(argv[0]);
+ errnum = errno;
+ if (argv0 == NULL) {
+ if (errnum != ENOENT)
+ Py_FatalError(strerror(errnum));
+
+ link = canonicalize_file_name(argv0);
+ errnum = errno;
+ if (link == NULL && errno == ENOENT) {
+ link = strdup(argv0);
+ if (!link)
+ Py_FatalError("no mem for sys.argv");
+ }
+ }
+
+ /* errno == ENOENT; the input file name is
+ empty, or at least one of the path
+ components does not exist */
+ /* strdup because we're going to free() it
+ later no matter what */
+ argv0 = strdup(argv[0]);
+ if (link) {
+ if (link[0] == SEP) /* Link to absolute path */
+ argv0 = link;
+ else if (strchr(link, SEP) == NULL) {
+ /* Link without path */
+ /* strdup argv0 so we can free it
+ unconditionally */
+ argv0 = strdup(argv0);
+ if (!argv0)
+ Py_FatalError("no mem for sys.argv");
+ free(link);
+ } else {
+ /* Must join(dirname(argv0), link) */
+ char *q = strrchr(argv0, SEP);
+ if (q == NULL) /* argv0 without path */
+ argv0 = link;
+ else {
+ /* Must make a copy */
+ argv0copy = calloc(
+ strlen(link) + strlen(q) +1,
+ sizeof (char));
+ if (!argv0copy)
+ Py_FatalError("no mem for sys.argv");
+ strcpy(argv0copy, argv0);
+ q = strrchr(argv0copy, SEP);
+ strcpy(argv0copy+1, link);
+ argv0 = argv0copy;
+ p = NULL;
+ free(link);
+ }
+ }
+ if (argv0 == NULL)
+ Py_FatalError("no mem for sys.argv");
+ }
+ if (argc > 0 && argv0 != NULL) {
+ char *q;
+ p = strrchr(argv0, SEP);
+ /* Test for alternate separator */
+ q = strrchr(p ? p : argv0, '/');
+ if (q != NULL)
+ p = q;
+ if (p != NULL) {
+ n = p + 1 - argv0;
+ if (n > 1 && p[-1] != ':')
+ n--; /* Drop trailing separator */
+ }
+ }
+#else /* ! HAVE_CANONICALIZE_FILE_NAME */
#ifdef HAVE_READLINK
char link[MAXPATHLEN+1];
char argv0copy[2*MAXPATHLEN+1];
@@ -1256,9 +1285,14 @@
@@ -1256,9 +1319,14 @@
#endif /* Unix */
}
#endif /* All others */
@ -76,7 +110,7 @@
Py_FatalError("sys.path.insert(0) failed");
Py_DECREF(a);
--- Python-2.4.1/configure.in.canonicalize 2005-03-28 18:23:34.000000000 -0500
+++ Python-2.4.1/configure.in 2005-09-25 16:30:43.000000000 -0400
+++ Python-2.4.1/configure.in 2005-09-26 16:03:35.000000000 -0400
@@ -2096,8 +2096,8 @@
AC_MSG_RESULT(MACHDEP_OBJS)