-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate the use of deprecated OS X APIs in getpath.c #59703
Comments
getpath.c uses three OS X APIs that have been producing deprecation warnings since at least OS X 10.5: NSModuleForSymbol, NSLookupAndBindSymbol, and NSLibraryNameForModule. We should figure out how to live without them. |
Removing the dependency on NSLookupAndBindSymbol (and related APIs) is easier than I expected. The attached patch (bpo-15498-v1.txt) uses dladdr to get symbol information for Py_Initialize and that information includes the path for the library where that symbol is located (that is the framework). The patch has seen only light testing, in particular: I've verified that the library path has the expected value, but haven't run the full test suite set. TODO:
This patch should work on OSX 10.4 or later, and may also work on OSX 10.3, the manpage for dladdr is not entirely clear on whether or not the symbol is available in libSystem on OSX 10.3. |
Apple seems to have switched to using dlopen in their version of getpath.c (see <http://www.opensource.apple.com/source/python/python-60.3/2.7/fix/getpath.c.ed\>, this is the version in OSX 10.8.2) This causes a problem for some people, as noticed on the pythonmac mailing list. This is something we should test before applying my patch to avoid regressions. Message-Id: <[email protected]> says: I am trying to work with Apple Mountain Lion's install of Python 2.7. I bash-3.2$ /usr/bin/python2.7 -c "import sys; print sys.path; import Presumably, this C program that uses dlopen(), Py_Initialize, and /** foo.c */ int
main(int argc, char **argv)
{
// void *lptr =
dlopen("/System/Library/Frameworks/Python.framework/Python", RTLD_NOW |
RTLD_GLOBAL);
void *lptr =
dlopen("/System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib",
RTLD_NOW | RTLD_GLOBAL);
if (lptr) {
void (*pyinit)(void) = dlsym(lptr, "Py_Initialize");
if (pyinit) {
int (*runSimple)(const char *);
(*pyinit)(); /* initialize Python */
runSimple = dlsym(lptr, "PyRun_SimpleString");
if (runSimple) {
(*runSimple)("import sys ; print sys.path; import numpy");
}
}
else {
fprintf(stderr, "Unable to locate Py_Initialize: %s\n", dlerror());
}
}
else {
fprintf(stderr, "Error loading Python shared library: %s\n",
dlerror());
}
} bash-3.2$ gcc foo.c ; ./a.out
['/usr/lib/python27.zip', '/usr/lib/python2.7',
'/usr/lib/python2.7/plat-darwin', '/usr/lib/python2.7/plat-mac',
'/usr/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/Extras/lib/python', '/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload']
Traceback (most recent call last):
File "<string>", line 1, in<module>
ImportError: No module named numpy However as you see, it has a completely different sys.path. I can't seem |
The deprecation warnings are not fixed yet. They were quickly mentioned at: |
…work builds (GH-111546) Co-authored-by: Ned Deily <[email protected]>
Thanks for the PR, @aisk! Merged for release in 3.13.0a2. |
…or macOS framework builds (pythonGH-111546)" This reverts commit de2715f.
On older versions of macOS, _NSGetExecutablePath appears to only be available via macho-o/dyld so macho-o/dyld.h is still needed.
On older versions of macOS, _NSGetExecutablePath appears to only be available via macho-o/dyld so macho-o/dyld.h is still needed.
On older versions of macOS, _NSGetExecutablePath appears to only be available via macho-o/dyld so macho-o/dyld.h is still needed.
Apparently I didn't test the PR enough. It turns out that the include of
I'm not quite sure why it compiles without error on more recent versions of macOS but, looking at the Apple Open Source site it does appear that they made some significant updates to dyld in more recent releases. |
For a long time, the synopsis section of #include <stdint.h>
int main(void){
char buf[1];
uint32_t bufsize = 0;
return _NSGetExecutablePath(buf, &bufsize);
} Compiling this program with LLVM.org Clang 17.0.6 (obtained from MacPorts) emits the expected implicit function declaration error. But compiling it with recent AppleClang (e.g. from Xcode 14.2 or Command Line Tools 15.0) succeeds without warnings or errors. I do not know if this expected AppleClang behavior for |
… framework builds (pythonGH-111546) Co-authored-by: Ned Deily <[email protected]>
On older versions of macOS, _NSGetExecutablePath appears to only be available via macho-o/dyld so macho-o/dyld.h is still needed.
… framework builds (pythonGH-111546) Co-authored-by: Ned Deily <[email protected]>
On older versions of macOS, _NSGetExecutablePath appears to only be available via macho-o/dyld so macho-o/dyld.h is still needed.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: