Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Modules/getpath.c

    r383 r391  
    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)
     
    239239    }
    240240    else {
    241         getcwd(path, MAXPATHLEN);
     241        if (!getcwd(path, MAXPATHLEN)) {
     242            /* unable to get the current directory */
     243            strcpy(path, p);
     244            return;
     245        }
    242246        if (p[0] == '.' && IS_SEP(p[1]))
    243247            p += 2;
     
    343347    }
    344348
    345     /* Check to see if argv[0] is in the build directory */
     349    /* Check to see if argv[0] is in the build directory. "pybuilddir.txt"
     350       is written by setup.py and contains the relative path to the location
     351       of shared library modules. */
    346352    strcpy(exec_prefix, argv0_path);
    347     joinpath(exec_prefix, "Modules/Setup");
     353    joinpath(exec_prefix, "pybuilddir.txt");
    348354    if (isfile(exec_prefix)) {
    349         reduce(exec_prefix);
    350         return -1;
     355      FILE *f = fopen(exec_prefix, "r");
     356      if (f == NULL)
     357        errno = 0;
     358      else {
     359        char rel_builddir_path[MAXPATHLEN+1];
     360        size_t n;
     361        n = fread(rel_builddir_path, 1, MAXPATHLEN, f);
     362        rel_builddir_path[n] = '\0';
     363        fclose(f);
     364        if (n >= 0) {
     365          strcpy(exec_prefix, argv0_path);
     366          joinpath(exec_prefix, rel_builddir_path);
     367          return -1;
     368        }
     369      }
    351370    }
    352371
     
    405424#endif
    406425
    407         /* If there is no slash in the argv0 path, then we have to
    408         * assume python is on the user's $PATH, since there's no
    409         * other way to find a directory to start the search from.  If
    410         * $PATH isn't exported, you lose.
    411         */
    412         if (HAS_ANYSEP(prog))
    413                 strncpy(progpath, prog, MAXPATHLEN);
     426        /* If there is no slash in the argv0 path, then we have to
     427        * assume python is on the user's $PATH, since there's no
     428        * other way to find a directory to start the search from.  If
     429        * $PATH isn't exported, you lose.
     430        */
     431        if (HAS_ANYSEP(prog))
     432                strncpy(progpath, prog, MAXPATHLEN);
    414433#ifdef __APPLE__
    415434     /* On Mac OS X, if a script uses an interpreter of the form
     
    426445       ;
    427446#endif /* __APPLE__ */
    428         else if (path) {
    429                 while (1) {
    430                         char *delim = strchr(path, DELIM);
    431 
    432                         if (delim) {
    433                                 size_t len = delim - path;
    434                                 if (len > MAXPATHLEN)
    435                                         len = MAXPATHLEN;
    436                                 strncpy(progpath, path, len);
    437                                 *(progpath + len) = '\0';
    438                         }
    439                         else
    440                                 strncpy(progpath, path, MAXPATHLEN);
    441 
    442                         joinpath(progpath, prog);
    443                         if (isxfile(progpath))
    444                                 break;
    445 
    446                         if (!delim) {
    447                                 progpath[0] = '\0';
    448                                 break;
    449                         }
    450                         path = delim + 1;
    451                 }
    452         }
    453         else
    454                 progpath[0] = '\0';
     447        else if (path) {
     448                while (1) {
     449                        char *delim = strchr(path, DELIM);
     450
     451                        if (delim) {
     452                                size_t len = delim - path;
     453                                if (len > MAXPATHLEN)
     454                                        len = MAXPATHLEN;
     455                                strncpy(progpath, path, len);
     456                                *(progpath + len) = '\0';
     457                        }
     458                        else
     459                                strncpy(progpath, path, MAXPATHLEN);
     460
     461                        joinpath(progpath, prog);
     462                        if (isxfile(progpath))
     463                                break;
     464
     465                        if (!delim) {
     466                                progpath[0] = '\0';
     467                                break;
     468                        }
     469                        path = delim + 1;
     470                }
     471        }
     472        else
     473                progpath[0] = '\0';
    455474#ifndef ALTSEP
    456         if (!IS_ABSPATH(progpath))
    457 #endif
    458                 absolutize(progpath);
    459         strncpy(argv0_path, progpath, MAXPATHLEN);
    460         argv0_path[MAXPATHLEN] = '\0';
     475        if (!IS_ABSPATH(progpath) && progpath[0] != '\0')
     476#endif
     477                absolutize(progpath);
     478        strncpy(argv0_path, progpath, MAXPATHLEN);
     479        argv0_path[MAXPATHLEN] = '\0';
    461480
    462481#ifdef WITH_NEXT_FRAMEWORK
    463         /* On Mac OS X we have a special case if we're running from a framework.
    464         ** This is because the python home should be set relative to the library,
    465         ** which is in the framework, not relative to the executable, which may
    466         ** be outside of the framework. Except when we're in the build directory...
    467         */
     482        /* On Mac OS X we have a special case if we're running from a framework.
     483        ** This is because the python home should be set relative to the library,
     484        ** which is in the framework, not relative to the executable, which may
     485        ** be outside of the framework. Except when we're in the build directory...
     486        */
    468487    pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
    469488    /* Use dylib functions to find out where the framework was loaded from */
     
    485504                /* We are in the build directory so use the name of the
    486505                   executable - we know that the absolute path is passed */
    487                 strncpy(argv0_path, prog, MAXPATHLEN);
     506                strncpy(argv0_path, progpath, MAXPATHLEN);
    488507        }
    489508        else {
     
    539558        strncpy(zip_path, PREFIX, MAXPATHLEN);
    540559    joinpath(zip_path, "lib/python00.zip");
    541     bufsz = strlen(zip_path);   /* Replace "00" with version */
     560    bufsz = strlen(zip_path);   /* Replace "00" with version */
    542561    zip_path[bufsz - 6] = VERSION[0];
    543562    zip_path[bufsz - 5] = VERSION[2];
     
    648667        reduce(prefix);
    649668        reduce(prefix);
    650         /* The prefix is the root directory, but reduce() chopped
    651         * off the "/". */
    652         if (!prefix[0])
    653                 strcpy(prefix, separator);
     669        /* The prefix is the root directory, but reduce() chopped
     670        * off the "/". */
     671        if (!prefix[0])
     672                strcpy(prefix, separator);
    654673    }
    655674    else
     
    660679        reduce(exec_prefix);
    661680        reduce(exec_prefix);
    662         if (!exec_prefix[0])
    663                 strcpy(exec_prefix, separator);
     681        if (!exec_prefix[0])
     682                strcpy(exec_prefix, separator);
    664683    }
    665684    else
Note: See TracChangeset for help on using the changeset viewer.