[Python-checkins] python/dist/src/Modules getpath.c,1.46,1.46.14.1

jackjansen at users.sourceforge.net jackjansen at users.sourceforge.net
Thu Jun 3 10:38:41 EDT 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16081
Modified Files:
 Tag: release23-maint
	getpath.c 
Log Message:
Backport of 1.47:
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
#!-scripts, only the filename part, and this can lead to incorrect
initialization of sys.path and sys.executable if there is another python
on $PATH before the one used in #!.
The fix was picked up from the darwinports crowd, thanks!
Index: getpath.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/getpath.c,v
retrieving revision 1.46
retrieving revision 1.46.14.1
diff -C2 -d -r1.46 -r1.46.14.1
*** getpath.c	31 Dec 2002 12:45:12 -0000	1.46
--- getpath.c	3 Jun 2004 14:38:38 -0000	1.46.14.1
***************
*** 375,378 ****
--- 375,381 ----
 NSModule pythonModule;
 #endif
+ #ifdef __APPLE__
+ unsigned long nsexeclength = MAXPATHLEN;
+ #endif
 
 	/* If there is no slash in the argv0 path, then we have to
***************
*** 383,386 ****
--- 386,403 ----
 	if (strchr(prog, SEP))
 		strncpy(progpath, prog, MAXPATHLEN);
+ #ifdef __APPLE__
+ /* On Mac OS X, if a script uses an interpreter of the form
+ * "#!/opt/python2.3/bin/python", the kernel only passes "python"
+ * as argv[0], which falls through to the $PATH search below.
+ * If /opt/python2.3/bin isn't in your path, or is near the end,
+ * this algorithm may incorrectly find /usr/bin/python. To work
+ * around this, we can use _NSGetExecutablePath to get a better
+ * hint of what the intended interpreter was, although this
+ * will fail if a relative path was used. but in that case,
+ * absolutize() should help us out below
+ */
+ else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP)
+ ;
+ #endif // __APPLE__
 	else if (path) {
 		while (1) {


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /