diff options
author | Andrew MacIntyre <andymac@bullseye.apana.org.au> | 2002-02-26 11:41:34 (GMT) |
---|---|---|
committer | Andrew MacIntyre <andymac@bullseye.apana.org.au> | 2002-02-26 11:41:34 (GMT) |
commit | d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3 (patch) | |
tree | 4cb201880bdd113ccee29bc944b55cbbd1d45f10 /Python/import.c | |
parent | c487439aa79acaf6c83a65985c110d5ca1ea71da (diff) | |
download | cpython-d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3.zip cpython-d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3.tar.gz cpython-d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3.tar.bz2 |
OS/2 EMX port changes (Python part of patch #450267):
Python/
dynload_shlib.c // EMX port emulates dlopen() etc. for DL extensions
import.c // changes to support 8.3 DLL name limit (VACPP+EMX)
// and case sensitive import semantics
importdl.h
thread_os2.h
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c index e657b70..e106aad 100644 --- a/Python/import.c +++ b/Python/import.c @@ -900,6 +900,11 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen, static struct filedescr fd_builtin = {"", "", C_BUILTIN}; static struct filedescr fd_package = {"", "", PKG_DIRECTORY}; char name[MAXPATHLEN+1]; +#if defined(PYOS_OS2) + size_t saved_len; + size_t saved_namelen; + char *saved_buf = NULL; +#endif if (strlen(realname) > MAXPATHLEN) { PyErr_SetString(PyExc_OverflowError, @@ -1026,7 +1031,38 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen, fdp = PyMac_FindModuleExtension(buf, &len, name); if (fdp) { #else +#if defined(PYOS_OS2) + /* take a snapshot of the module spec for restoration + * after the 8 character DLL hackery + */ + saved_buf = strdup(buf); + saved_len = len; + saved_namelen = namelen; +#endif /* PYOS_OS2 */ for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { +#if defined(PYOS_OS2) + /* OS/2 limits DLLs to 8 character names (w/o extension) + * so if the name is longer than that and its a + * dynamically loaded module we're going to try, + * truncate the name before trying + */ + if (strlen(realname) > 8) { + /* is this an attempt to load a C extension? */ + const struct filedescr *scan = _PyImport_DynLoadFiletab; + while (scan->suffix != NULL) { + if (strcmp(scan->suffix, fdp->suffix) == 0) + break; + else + scan++; + } + if (scan->suffix != NULL) { + /* yes, so truncate the name */ + namelen = 8; + len -= strlen(realname) - namelen; + buf[len] = '\0'; + } + } +#endif /* PYOS_OS2 */ strcpy(buf+len, fdp->suffix); if (Py_VerboseFlag > 1) PySys_WriteStderr("# trying %s\n", buf); @@ -1040,7 +1076,21 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen, fp = NULL; } } +#if defined(PYOS_OS2) + /* restore the saved snapshot */ + strcpy(buf, saved_buf); + len = saved_len; + namelen = saved_namelen; +#endif + } +#if defined(PYOS_OS2) + /* don't need/want the module name snapshot anymore */ + if (saved_buf) + { + free(saved_buf); + saved_buf = NULL; } +#endif if (fp != NULL) break; } @@ -1099,6 +1149,12 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen, #include <sys/types.h> #include <dirent.h> +#elif defined(PYOS_OS2) +#define INCL_DOS +#define INCL_DOSERRORS +#define INCL_NOPMAPI +#include <os2.h> + #elif defined(RISCOS) #include "oslib/osfscontrol.h" #endif @@ -1255,6 +1311,26 @@ case_ok(char *buf, int len, int namelen, char *name) return 0; +/* OS/2 */ +#elif defined(PYOS_OS2) + HDIR hdir = 1; + ULONG srchcnt = 1; + FILEFINDBUF3 ffbuf; + APIRET rc; + + if (getenv("PYTHONCASEOK") != NULL) + return 1; + + rc = DosFindFirst(buf, + &hdir, + FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY, + &ffbuf, sizeof(ffbuf), + &srchcnt, + FIL_STANDARD); + if (rc != NO_ERROR) + return 0; + return strncmp(ffbuf.achName, name, namelen) == 0; + /* assuming it's a case-sensitive filesystem, so there's nothing to do! */ #else return 1; |