|
1 |
| - |
2 | 1 | /* Return the initial module search path. */
|
3 | 2 |
|
4 | 3 | #include "Python.h"
|
@@ -371,16 +370,31 @@ calculate_path(void)
|
371 | 370 | #endif
|
372 | 371 |
|
373 | 372 | #ifdef WITH_NEXT_FRAMEWORK
|
374 |
| - /* XXX Need to check this code for buffer overflows */ |
375 | 373 | pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
|
376 | 374 | /* Use dylib functions to find out where the framework was loaded from */
|
377 | 375 | buf = NSLibraryNameForModule(pythonModule);
|
378 | 376 | if (buf != NULL) {
|
379 | 377 | /* We're in a framework. */
|
380 |
| - strcpy(progpath, buf); |
381 |
| - |
382 |
| - /* Frameworks have support for versioning */ |
383 |
| - strcpy(lib_python, "lib"); |
| 378 | + /* See if we might be in the build directory. The framework in the |
| 379 | + ** build directory is incomplete, it only has the .dylib and a few |
| 380 | + ** needed symlinks, it doesn't have the Lib directories and such. |
| 381 | + ** If we're running with the framework from the build directory we must |
| 382 | + ** be running the interpreter in the build directory, so we use the |
| 383 | + ** build-directory-specific logic to find Lib and such. |
| 384 | + */ |
| 385 | + strncpy(argv0_path, buf, MAXPATHLEN); |
| 386 | + reduce(argv0_path); |
| 387 | + joinpath(argv0_path, lib_python); |
| 388 | + joinpath(argv0_path, LANDMARK); |
| 389 | + if (!ismodule(argv0_path)) { |
| 390 | + /* We are in the build directory so use the name of the |
| 391 | + executable - we know that the absolute path is passed */ |
| 392 | + strncpy(progpath, prog, MAXPATHLEN); |
| 393 | + } |
| 394 | + else { |
| 395 | + /* Use the location of the library as the progpath */ |
| 396 | + strncpy(progpath, buf, MAXPATHLEN); |
| 397 | + } |
384 | 398 | }
|
385 | 399 | else {
|
386 | 400 | /* If we're not in a framework, fall back to the old way
|
|
0 commit comments