[Python-checkins] python/dist/src/Parser myreadline.c,2.30,2.31

mwh at users.sourceforge.net mwh at users.sourceforge.net
Wed Jul 7 19:44:13 CEST 2004


Update of /cvsroot/python/python/dist/src/Parser
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18275/Parser
Modified Files:
	myreadline.c 
Log Message:
This closes patch:
[ 960406 ] unblock signals in threads
although the changes do not correspond exactly to any patch attached to
that report.
Non-main threads no longer have all signals masked.
A different interface to readline is used.
The handling of signals inside calls to PyOS_Readline is now rather 
different.
These changes are all a bit scary! Review and cross-platform testing
much appreciated.
Index: myreadline.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v
retrieving revision 2.30
retrieving revision 2.31
diff -C2 -d -r2.30 -r2.31
*** myreadline.c	19 Nov 2003 15:24:46 -0000	2.30
--- myreadline.c	7 Jul 2004 17:44:10 -0000	2.31
***************
*** 20,23 ****
--- 20,31 ----
 #endif
 
+ 
+ PyThreadState* _PyOS_ReadlineTState;
+ 
+ #if WITH_THREAD
+ #include "pythread.h"
+ static PyThread_type_lock _PyOS_ReadlineLock = NULL;
+ #endif
+ 
 int (*PyOS_InputHook)(void) = NULL;
 
***************
*** 74,81 ****
 #ifdef EINTR
 		if (errno == EINTR) {
! 			if (PyOS_InterruptOccurred()) {
! 				return 1; /* Interrupt */
 			}
- 			continue;
 		}
 #endif
--- 82,92 ----
 #ifdef EINTR
 		if (errno == EINTR) {
! 			int s;
! 			PyEval_RestoreThread(_PyOS_ReadlineTState);
! 			s = PyErr_CheckSignals();
! 			PyThreadState_Swap(NULL);
! 			if (s < 0) {
! 				return 1;
 			}
 		}
 #endif
***************
*** 156,159 ****
--- 167,177 ----
 	char *rv;
 
+ 	if (_PyOS_ReadlineTState == PyThreadState_GET()) {
+ 		PyErr_SetString(PyExc_RuntimeError,
+ 				"can't re-enter readline");
+ 		return NULL;
+ 	}
+ 	
+ 
 	if (PyOS_ReadlineFunctionPointer == NULL) {
 #ifdef __VMS
***************
*** 163,168 ****
--- 181,196 ----
 #endif
 	}
+ 	
+ #if WITH_THREAD
+ 	if (_PyOS_ReadlineLock == NULL) {
+ 		_PyOS_ReadlineLock = PyThread_allocate_lock();		
+ 	}
+ #endif
 
+ 	_PyOS_ReadlineTState = PyThreadState_GET();
 	Py_BEGIN_ALLOW_THREADS
+ #if WITH_THREAD
+ 	PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
+ #endif
 
 /* This is needed to handle the unlikely case that the
***************
*** 177,180 ****
--- 205,215 ----
 prompt);
 	Py_END_ALLOW_THREADS
+ 
+ #if WITH_THREAD
+ 	PyThread_release_lock(_PyOS_ReadlineLock);
+ #endif
+ 
+ 	_PyOS_ReadlineTState = NULL;
+ 
 	return rv;
 }


More information about the Python-checkins mailing list

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