[Python-checkins] CVS: python/dist/src/Python dynload_shlib.c,2.13,2.14 import.c,2.194,2.195 importdl.h,2.17,2.18 thread_os2.h,2.13,2.14

Andrew I MacIntyre aimacintyre@users.sourceforge.net
2002年2月26日 03:41:36 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv29234/dist/src/Python
Modified Files:
	dynload_shlib.c import.c importdl.h thread_os2.h 
Log Message:
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
Index: dynload_shlib.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/dynload_shlib.c,v
retrieving revision 2.13
retrieving revision 2.14
diff -C2 -d -r2.13 -r2.14
*** dynload_shlib.c	28 Nov 2001 20:40:47 -0000	2.13
--- dynload_shlib.c	26 Feb 2002 11:41:34 -0000	2.14
***************
*** 19,22 ****
--- 19,26 ----
 #ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
+ #else
+ #if defined(PYOS_OS2) && defined(PYCC_GCC)
+ #include "dlfcn.h"
+ #endif
 #endif
 
***************
*** 33,39 ****
--- 37,48 ----
 	{"module.dll", "rb", C_EXTENSION},
 #else
+ #if defined(PYOS_OS2) && defined(PYCC_GCC)
+ 	{".pyd", "rb", C_EXTENSION},
+ 	{".dll", "rb", C_EXTENSION},
+ #else
 	{".so", "rb", C_EXTENSION},
 	{"module.so", "rb", C_EXTENSION},
 #endif
+ #endif
 	{0, 0}
 };
***************
*** 83,87 ****
--- 92,98 ----
 	}
 
+ #if !(defined(PYOS_OS2) && defined(PYCC_GCC))
 dlopenflags = PyThreadState_Get()->interp->dlopenflags;
+ #endif
 
 	if (Py_VerboseFlag)
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.194
retrieving revision 2.195
diff -C2 -d -r2.194 -r2.195
*** import.c	7 Feb 2002 11:33:49 -0000	2.194
--- import.c	26 Feb 2002 11:41:34 -0000	2.195
***************
*** 901,904 ****
--- 901,909 ----
 	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) {
***************
*** 1027,1031 ****
--- 1032,1067 ----
 		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)
***************
*** 1041,1045 ****
--- 1077,1095 ----
 				}
 			}
+ #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;
***************
*** 1100,1103 ****
--- 1150,1159 ----
 #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"
***************
*** 1255,1258 ****
--- 1311,1334 ----
 
 	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! */
Index: importdl.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/importdl.h,v
retrieving revision 2.17
retrieving revision 2.18
diff -C2 -d -r2.17 -r2.18
*** importdl.h	5 Nov 2001 02:45:59 -0000	2.17
--- importdl.h	26 Feb 2002 11:41:34 -0000	2.18
***************
*** 38,42 ****
 typedef FARPROC dl_funcptr;
 #else
! #ifdef PYOS_OS2
 #include <os2def.h>
 typedef int (* APIENTRY dl_funcptr)();
--- 38,42 ----
 typedef FARPROC dl_funcptr;
 #else
! #if defined(PYOS_OS2) && !defined(PYCC_GCC)
 #include <os2def.h>
 typedef int (* APIENTRY dl_funcptr)();
Index: thread_os2.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_os2.h,v
retrieving revision 2.13
retrieving revision 2.14
diff -C2 -d -r2.13 -r2.14
*** thread_os2.h	19 Jan 2002 22:02:55 -0000	2.13
--- thread_os2.h	26 Feb 2002 11:41:34 -0000	2.14
***************
*** 8,13 ****
 #include "process.h"
 
 long PyThread_get_thread_ident(void);
! 
 
 /*
--- 8,17 ----
 #include "process.h"
 
+ #if defined(PYCC_GCC)
+ #include <sys/builtin.h>
+ #include <sys/fmutex.h>
+ #else
 long PyThread_get_thread_ident(void);
! #endif
 
 /*
***************
*** 42,53 ****
--- 46,63 ----
 PyThread_get_thread_ident(void)
 {
+ #if !defined(PYCC_GCC)
 PPIB pib;
 PTIB tib;
+ #endif
 
 if (!initialized)
 PyThread_init_thread();
 
+ #if defined(PYCC_GCC)
+ return _gettid();
+ #else
 DosGetInfoBlocks(&tib,&pib);
 return tib->tib_ptib2->tib2_ultid;
+ #endif
 }
 
***************
*** 104,108 ****
 * Lock support. This is implemented with an event semaphore and critical
 * sections to make it behave more like a posix mutex than its OS/2 
! # counterparts.
 */
 
--- 114,118 ----
 * Lock support. This is implemented with an event semaphore and critical
 * sections to make it behave more like a posix mutex than its OS/2 
! * counterparts.
 */
 
***************
*** 115,118 ****
--- 125,141 ----
 PyThread_allocate_lock(void)
 {
+ #if defined(PYCC_GCC)
+ _fmutex *sem = malloc(sizeof(_fmutex));
+ if (!initialized)
+ PyThread_init_thread();
+ dprintf(("%ld: PyThread_allocate_lock() -> %lx\n",
+ PyThread_get_thread_ident(),
+ (long)sem));
+ if (_fmutex_create(sem, 0)) {
+ free(sem);
+ sem = NULL;
+ }
+ return (PyThread_type_lock) sem;
+ #else
 APIRET rc;
 type_os2_lock lock = (type_os2_lock)malloc(sizeof(struct os2_lock_t));
***************
*** 131,134 ****
--- 154,158 ----
 
 return (PyThread_type_lock) lock;
+ #endif
 }
 
***************
*** 136,144 ****
--- 160,178 ----
 PyThread_free_lock(PyThread_type_lock aLock)
 {
+ #if !defined(PYCC_GCC)
 type_os2_lock lock = (type_os2_lock)aLock;
+ #endif
+ 
 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
 
+ #if defined(PYCC_GCC)
+ if (aLock) {
+ _fmutex_close((_fmutex *)aLock);
+ free((_fmutex *)aLock);
+ }
+ #else
 DosCloseEventSem(lock->changed);
 free(aLock);
+ #endif
 }
 
***************
*** 151,154 ****
--- 185,189 ----
 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
 {
+ #if !defined(PYCC_GCC)
 int done = 0;
 ULONG count;
***************
*** 156,163 ****
--- 191,204 ----
 TID tid = 0;
 type_os2_lock lock = (type_os2_lock)aLock;
+ #endif
 
 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),
 aLock, waitflag));
 
+ #if defined(PYCC_GCC)
+ /* always successful if the lock doesn't exist */
+ if (aLock && _fmutex_request((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT))
+ return 0;
+ #else
 while (!done) {
 /* if the lock is currently set, we have to wait for the state to change */
***************
*** 183,186 ****
--- 224,228 ----
 DosExitCritSec();
 }
+ #endif
 
 return 1;
***************
*** 189,195 ****
--- 231,244 ----
 void PyThread_release_lock(PyThread_type_lock aLock)
 {
+ #if defined(PYCC_GCC)
 type_os2_lock lock = (type_os2_lock)aLock;
+ #endif
+ 
 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
 
+ #if defined(PYCC_GCC)
+ if (aLock)
+ _fmutex_release((_fmutex *)aLock);
+ #else
 if (!lock->is_set) {
 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
***************
*** 209,211 ****
--- 258,261 ----
 
 DosExitCritSec();
+ #endif
 }

AltStyle によって変換されたページ (->オリジナル) /