getpath.c.ed   [plain text]

#include <dlfcn.h>
/NSModule pythonModule/c
    Dl_info addrinfo;
    int first_pass = 1;
	/* dladdr() now returns the real path of the dylib, instead of the
	** path of the symlink.  This breaks virtualenv.  To fix this, we
	** skip using dladdr() during a first pass, and if that fails, then
	** we go back and do the dladdr().  It turns out that since we moved
	** to inside the Python.framework bundle, the call to
	** search_for_prefix() will now succeed without needing dladdr().
	** However, virtualenv copies the wrong binary when the prefix is
	** /usr, so if progpath begins with /usr/bin/, we skip the first pass.
    if (strncmp(progpath, "/usr/bin/", 9) == 0) first_pass = 0;
    buf = first_pass ? NULL : (dladdr("_Py_Initialize", &addrinfo) ? (char *)addrinfo.dli_fname : NULL);
	if (first_pass) {
	    first_pass = 0;
	    goto return_here_for_second_pass;