[Python-checkins] CVS: python/dist/src/PC getpathp.c,1.24,1.25
Mark Hammond
mhammond@users.sourceforge.net
Fri, 07 Sep 2001 07:08:03 -0700
Update of /cvsroot/python/python/dist/src/PC
In directory usw-pr-cvs1:/tmp/cvs-serv18370
Modified Files:
getpathp.c
Log Message:
Fix bug #410274 - sys.prefix isn't always set.
If after calculating sys.path we do not have sys.prefix set, we loop over all path entries checking if one can point to our home directory.
Index: getpathp.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/getpathp.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** getpathp.c 2001/07/23 16:30:27 1.24
--- getpathp.c 2001/09/07 14:08:01 1.25
***************
*** 45,49 ****
* When Python is hosted in another exe (different directory, embedded via
COM, etc), the Python Home will not be deduced, so the core path from
! the registry is used. Other "application paths "in the registry are
always read.
--- 45,49 ----
* When Python is hosted in another exe (different directory, embedded via
COM, etc), the Python Home will not be deduced, so the core path from
! the registry is used. Other "application paths" in the registry are
always read.
***************
*** 577,580 ****
--- 577,614 ----
}
*buf = '\0';
+ /* Now to pull one last hack/trick. If sys.prefix is
+ empty, then try and find it somewhere on the paths
+ we calculated. We scan backwards, as our general policy
+ is that Python core directories are at the *end* of
+ sys.path. We assume that our "lib" directory is
+ on the path, and that our 'prefix' directory is
+ the parent of that.
+ */
+ if (*prefix=='\0') {
+ char lookBuf[MAXPATHLEN+1];
+ char *look = buf - 1; /* 'buf' is at the end of the buffer */
+ while (1) {
+ int nchars;
+ char *lookEnd = look;
+ /* 'look' will end up one character before the
+ start of the path in question - even if this
+ is one character before the start of the buffer
+ */
+ while (*look != DELIM && look >= module_search_path)
+ look--;
+ nchars = lookEnd-look;
+ strncpy(lookBuf, look+1, nchars);
+ lookBuf[nchars] = '\0';
+ /* Up one level to the parent */
+ reduce(lookBuf);
+ if (search_for_prefix(lookBuf, LANDMARK)) {
+ break;
+ }
+ /* If we are out of paths to search - give up */
+ if (look < module_search_path)
+ break;
+ look--;
+ }
+ }
}