[Python-Dev] Importing extensions on Windows 95
M.-A. Lemburg
mal@lemburg.com
Mon, 30 Apr 2001 16:10:16 +0200
Mark Hammond wrote:
>
> > abc/
> > __init__.py
> > mxABC.pyd
> > mamba.dll
> >
> > mxABC.pyd needs mamba.dll.
> >
> > > My Win98 box uses absolute paths for all imports when using -vv
> >
> > Are you sure ? Please CD to the C:\Python21 dir and then try
>
> Right - I am with you now...
>
> > importing extensions using these relative paths. I think we could
> > solve the problem by making the pathname which is passed to
> > LoadLibraryEx() in dynload_win.c absolute.
>
> Just calling GetFullPathName() before the LoadLibEx() would seem a
> reasonable and appropriate patch. Keeps it a long way from the "*in
> general*" Guido was concerned about, and sounds low-risk to me!
>
> Ahh - Guido just OK'd it, so go for it ;-)
Here's a stab at a patch. Could you review it and test it ? I
don't have enough knowledge of win32 for this...
dynload_win.c:
...
#ifdef MS_WIN32
{
HINSTANCE hDLL;
char pathbuf[260];
LPTSTR *dummy;
if (strchr(pathname, '\\') == NULL &&
strchr(pathname, '/') == NULL)
{
/* Prefix bare filename with ".\" */
char *p = pathbuf;
*p = '\0';
_getcwd(pathbuf, sizeof pathbuf);
if (*p != '\0' && p[1] == ':')
p += 2;
sprintf(p, ".\\%-.255s", pathname);
pathname = pathbuf;
}
/* Convert to full pathname; we ignore errors to maintain
b/w compatibility here. */
if (GetFullPathName(pathname,
sizeof(pathbuf),
pathbuf,
&dummy))
pathname = pathbuf;
/* Look for dependent DLLs in directory of pathname first */
/* XXX This call doesn't exist in Windows CE */
if (pathname)
hDLL = LoadLibraryEx(pathname, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH);
if (hDLL == NULL) {
char errBuf[256];
unsigned int errorCode;
...
Thanks,
--
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/