Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/getpath.c

    r2 r388  
    217217    }
    218218    if (n > MAXPATHLEN)
    219         Py_FatalError("buffer overflow in getpath.c's joinpath()");
     219        Py_FatalError("buffer overflow in getpath.c's joinpath()");
    220220    k = strlen(stuff);
    221221    if (n + k > MAXPATHLEN)
     
    233233        strcpy(path, p);
    234234    else {
    235         getcwd(path, MAXPATHLEN);
     235        if (!getcwd(path, MAXPATHLEN)) {
     236            /* unable to get the current directory */
     237            strcpy(path, p);
     238            return;
     239        }
    236240        if (p[0] == '.' && p[1] == SEP)
    237241            p += 2;
     
    332336    }
    333337
    334     /* Check to see if argv[0] is in the build directory */
     338    /* Check to see if argv[0] is in the build directory. "pybuilddir.txt"
     339       is written by setup.py and contains the relative path to the location
     340       of shared library modules. */
    335341    strcpy(exec_prefix, argv0_path);
    336     joinpath(exec_prefix, "Modules/Setup");
     342    joinpath(exec_prefix, "pybuilddir.txt");
    337343    if (isfile(exec_prefix)) {
    338         reduce(exec_prefix);
    339         return -1;
     344      FILE *f = fopen(exec_prefix, "r");
     345      if (f == NULL)
     346        errno = 0;
     347      else {
     348        char rel_builddir_path[MAXPATHLEN+1];
     349        size_t n;
     350        n = fread(rel_builddir_path, 1, MAXPATHLEN, f);
     351        rel_builddir_path[n] = '\0';
     352        fclose(f);
     353        if (n >= 0) {
     354          strcpy(exec_prefix, argv0_path);
     355          joinpath(exec_prefix, rel_builddir_path);
     356          return -1;
     357        }
     358      }
    340359    }
    341360
     
    394413#endif
    395414
    396         /* If there is no slash in the argv0 path, then we have to
    397         * assume python is on the user's $PATH, since there's no
    398         * other way to find a directory to start the search from.  If
    399         * $PATH isn't exported, you lose.
    400         */
    401         if (strchr(prog, SEP))
    402                 strncpy(progpath, prog, MAXPATHLEN);
     415        /* If there is no slash in the argv0 path, then we have to
     416        * assume python is on the user's $PATH, since there's no
     417        * other way to find a directory to start the search from.  If
     418        * $PATH isn't exported, you lose.
     419        */
     420        if (strchr(prog, SEP))
     421                strncpy(progpath, prog, MAXPATHLEN);
    403422#ifdef __APPLE__
    404423     /* On Mac OS X, if a script uses an interpreter of the form
     
    415434       ;
    416435#endif /* __APPLE__ */
    417         else if (path) {
    418                 while (1) {
    419                         char *delim = strchr(path, DELIM);
    420 
    421                         if (delim) {
    422                                 size_t len = delim - path;
    423                                 if (len > MAXPATHLEN)
    424                                         len = MAXPATHLEN;
    425                                 strncpy(progpath, path, len);
    426                                 *(progpath + len) = '\0';
    427                         }
    428                         else
    429                                 strncpy(progpath, path, MAXPATHLEN);
    430 
    431                         joinpath(progpath, prog);
    432                         if (isxfile(progpath))
    433                                 break;
    434 
    435                         if (!delim) {
    436                                 progpath[0] = '\0';
    437                                 break;
    438                         }
    439                         path = delim + 1;
    440                 }
    441         }
    442         else
    443                 progpath[0] = '\0';
    444         if (progpath[0] != SEP)
    445                 absolutize(progpath);
    446         strncpy(argv0_path, progpath, MAXPATHLEN);
    447         argv0_path[MAXPATHLEN] = '\0';
     436        else if (path) {
     437                while (1) {
     438                        char *delim = strchr(path, DELIM);
     439
     440                        if (delim) {
     441                                size_t len = delim - path;
     442                                if (len > MAXPATHLEN)
     443                                        len = MAXPATHLEN;
     444                                strncpy(progpath, path, len);
     445                                *(progpath + len) = '\0';
     446                        }
     447                        else
     448                                strncpy(progpath, path, MAXPATHLEN);
     449
     450                        joinpath(progpath, prog);
     451                        if (isxfile(progpath))
     452                                break;
     453
     454                        if (!delim) {
     455                                progpath[0] = '\0';
     456                                break;
     457                        }
     458                        path = delim + 1;
     459                }
     460        }
     461        else
     462                progpath[0] = '\0';
     463        if (progpath[0] != SEP && progpath[0] != '\0')
     464                absolutize(progpath);
     465        strncpy(argv0_path, progpath, MAXPATHLEN);
     466        argv0_path[MAXPATHLEN] = '\0';
    448467
    449468#ifdef WITH_NEXT_FRAMEWORK
    450         /* On Mac OS X we have a special case if we're running from a framework.
    451         ** This is because the python home should be set relative to the library,
    452         ** which is in the framework, not relative to the executable, which may
    453         ** be outside of the framework. Except when we're in the build directory...
    454         */
     469        /* On Mac OS X we have a special case if we're running from a framework.
     470        ** This is because the python home should be set relative to the library,
     471        ** which is in the framework, not relative to the executable, which may
     472        ** be outside of the framework. Except when we're in the build directory...
     473        */
    455474    pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
    456475    /* Use dylib functions to find out where the framework was loaded from */
     
    472491                /* We are in the build directory so use the name of the
    473492                   executable - we know that the absolute path is passed */
    474                 strncpy(argv0_path, prog, MAXPATHLEN);
     493                strncpy(argv0_path, progpath, MAXPATHLEN);
    475494        }
    476495        else {
     
    526545        strncpy(zip_path, PREFIX, MAXPATHLEN);
    527546    joinpath(zip_path, "lib/python00.zip");
    528     bufsz = strlen(zip_path);   /* Replace "00" with version */
     547    bufsz = strlen(zip_path);   /* Replace "00" with version */
    529548    zip_path[bufsz - 6] = VERSION[0];
    530549    zip_path[bufsz - 5] = VERSION[2];
     
    634653        reduce(prefix);
    635654        reduce(prefix);
    636         /* The prefix is the root directory, but reduce() chopped
    637         * off the "/". */
    638         if (!prefix[0])
    639                 strcpy(prefix, separator);
     655        /* The prefix is the root directory, but reduce() chopped
     656        * off the "/". */
     657        if (!prefix[0])
     658                strcpy(prefix, separator);
    640659    }
    641660    else
     
    646665        reduce(exec_prefix);
    647666        reduce(exec_prefix);
    648         if (!exec_prefix[0])
    649                 strcpy(exec_prefix, separator);
     667        if (!exec_prefix[0])
     668                strcpy(exec_prefix, separator);
    650669    }
    651670    else
Note: See TracChangeset for help on using the changeset viewer.