Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Oct 2, 2019

calculate_argv0_path() must read argv0_path link, not read
program_full_path link.

https://bugs.python.org/issue38353

calculate_argv0_path() must read argv0_path link, not read
program_full_path link.
@vstinner
Copy link
Member Author

vstinner commented Oct 2, 2019

This change only affects macOS ("#ifdef WITH_NEXT_FRAMEWORK").

@vstinner
Copy link
Member Author

vstinner commented Oct 2, 2019

The bug is that on macOS, readlink() is called on program_full_path (previously known as "progpath"), instead of argv0_path.

The change likely has no effect on practice. I don't expect program_full_path nor argv0_path to be symlinks on macOS.

The bug is quite old, it was introduced by:

commit 55070f5d966f09256c603c3a82fab9b034430c6f
Author: Jack Jansen <jack.jansen@cwi.nl>
Date:   Sun Dec 2 23:56:28 2001 +0000

    Changed logic for finding python home in Mac OS X framework Pythons.
    Now sys.executable points to the executable again, in stead of to
    the shared library. The latter is used only for locating the python
    home.

Previously, at the first readlink() call, argv0_path was equal to progpath:

        strcpy(argv0_path, progpath);
        
#if HAVE_READLINK
        {
                char tmpbuffer[MAXPATHLEN+1];
                int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN);
                if (linklen != -1) {
                        /* It's not null terminated! */
                        tmpbuffer[linklen] = '\0';
                        if (tmpbuffer[0] == SEP)
                                strcpy(argv0_path, tmpbuffer);
                        else {
                                /* Interpret relative to progpath */
                                reduce(argv0_path);
                                join(argv0_path, tmpbuffer);
                        }
                }
        }
#endif /* HAVE_READLINK */

Previously = the following commit:

commit 305e5d0d4f3a24f199cfea4f9b0e53980de79847
Author: Guido van Rossum <guido@python.org>
Date:   Fri Apr 11 17:18:45 1997 +0000

    Completely revamped the way the default path is constructed.
    
    Idea and first three implementation rounds due to Barry -- after that
    I spent another day on it, hopefully it's enough for now :-)
    
    (Wait for the checkin to Setup.in.)

@vstinner
Copy link
Member Author

vstinner commented Oct 2, 2019

Since Python is working well since 2001 on macOS, I don't think that it's worth it to backport this change to Python 3.8 and older.

@vstinner vstinner merged commit 86ec5c6 into python:master Oct 3, 2019
@vstinner vstinner deleted the argv0_symlink branch October 3, 2019 21:17
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
calculate_argv0_path() must read argv0_path link, not read
program_full_path link.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants