[Python-checkins] python/dist/src/Modules readline.c,2.57,2.58

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 07 Jan 2003 12:31:25 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv21547

Modified Files:
	readline.c 
Log Message:
Fix from Michael Stone for SF bug #660476 and #513033 (bogus thread
state swaps in readline).


Index: readline.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v
retrieving revision 2.57
retrieving revision 2.58
diff -C2 -d -r2.57 -r2.58
*** readline.c	7 Jan 2003 20:04:12 -0000	2.57
--- readline.c	7 Jan 2003 20:31:20 -0000	2.58
***************
*** 482,495 ****
  
  static int
! on_hook(PyObject *func, PyThreadState *tstate)
  {
  	int result = 0;
  	if (func != NULL) {
  		PyObject *r;
- 		PyThreadState *save_tstate;
  		/* Note that readline is called with the interpreter
  		   lock released! */
! 		save_tstate = PyThreadState_Swap(NULL);
! 		PyEval_RestoreThread(tstate);
  		r = PyObject_CallFunction(func, NULL);
  		if (r == NULL)
--- 482,493 ----
  
  static int
! on_hook(PyObject *func, PyThreadState **tstate)
  {
  	int result = 0;
  	if (func != NULL) {
  		PyObject *r;
  		/* Note that readline is called with the interpreter
  		   lock released! */
! 		PyEval_RestoreThread(*tstate);
  		r = PyObject_CallFunction(func, NULL);
  		if (r == NULL)
***************
*** 505,510 ****
  		Py_XDECREF(r);
  	  done:
! 		PyEval_SaveThread();
! 		PyThreadState_Swap(save_tstate);
  	}
  	return result;
--- 503,507 ----
  		Py_XDECREF(r);
  	  done:
! 		*tstate = PyEval_SaveThread();
  	}
  	return result;
***************
*** 514,518 ****
  on_startup_hook(void)
  {
! 	return on_hook(startup_hook, startup_hook_tstate);
  }
  
--- 511,515 ----
  on_startup_hook(void)
  {
! 	return on_hook(startup_hook, &startup_hook_tstate);
  }
  
***************
*** 521,525 ****
  on_pre_input_hook(void)
  {
! 	return on_hook(pre_input_hook, pre_input_hook_tstate);
  }
  #endif
--- 518,522 ----
  on_pre_input_hook(void)
  {
! 	return on_hook(pre_input_hook, &pre_input_hook_tstate);
  }
  #endif
***************
*** 534,541 ****
  	if (completer != NULL) {
  		PyObject *r;
- 		PyThreadState *save_tstate;
  		/* Note that readline is called with the interpreter
  		   lock released! */
- 		save_tstate = PyThreadState_Swap(NULL);
  		PyEval_RestoreThread(completer_tstate);
  		/* Don't use the default filename completion if we
--- 531,536 ----
***************
*** 560,565 ****
  		Py_XDECREF(r);
  	  done:
! 		PyEval_SaveThread();
! 		PyThreadState_Swap(save_tstate);
  	}
  	return result;
--- 555,559 ----
  		Py_XDECREF(r);
  	  done:
! 		completer_tstate = PyEval_SaveThread();
  	}
  	return result;
***************
*** 567,571 ****
  
  
! /* a more flexible constructor that saves the "begidx" and "endidx"
   * before calling the normal completer */
  
--- 561,565 ----
  
  
! /* A more flexible constructor that saves the "begidx" and "endidx"
   * before calling the normal completer */