[Python-checkins] CVS: python/dist/src/Modules signalmodule.c,2.55,2.56

Guido van Rossum python-dev@python.org
Sat, 16 Sep 2000 09:35:31 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv32053

Modified Files:
	signalmodule.c 
Log Message:
Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
PyOS_setsig(), instead of directly calling signal() or sigaction().

This fixes the second half of bug #110611: the mysterious ignoring of
the first ^C when readline isn't used.


Index: signalmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/signalmodule.c,v
retrieving revision 2.55
retrieving revision 2.56
diff -C2 -r2.55 -r2.56
*** signalmodule.c	2000/09/01 23:29:27	2.55
--- signalmodule.c	2000/09/16 16:35:28	2.56
***************
*** 18,22 ****
  
  #ifndef SIG_ERR
! #define SIG_ERR ((void (*)(int))-1)
  #endif
  
--- 18,22 ----
  
  #ifndef SIG_ERR
! #define SIG_ERR ((PyOS_sighandler_t)(-1))
  #endif
  
***************
*** 39,43 ****
  
  
- 
  /*
     NOTES ON THE INTERACTION BETWEEN SIGNALS AND THREADS
--- 39,42 ----
***************
*** 84,91 ****
  static PyObject *IntHandler;
  
! static void (*old_siginthandler)(int) = SIG_DFL;
  
  
- 
  static PyObject *
  signal_default_int_handler(PyObject *self, PyObject *args)
--- 83,89 ----
  static PyObject *IntHandler;
  
! static PyOS_sighandler_t old_siginthandler = SIG_DFL;
  
  
  static PyObject *
  signal_default_int_handler(PyObject *self, PyObject *args)
***************
*** 101,105 ****
  It raises KeyboardInterrupt.";
  
- 
  
  static int
--- 99,102 ----
***************
*** 134,142 ****
  	siginterrupt(sig_num, 1);
  #endif
! 	signal(sig_num, signal_handler);
  }
  
  
- 
  #ifdef HAVE_ALARM
  static PyObject *
--- 131,138 ----
  	siginterrupt(sig_num, 1);
  #endif
! 	PyOS_setsig(sig_num, signal_handler);
  }
  
  
  #ifdef HAVE_ALARM
  static PyObject *
***************
*** 182,186 ****
  #endif
  
! 
  static PyObject *
  signal_signal(PyObject *self, PyObject *args)
--- 178,182 ----
  #endif
  
! 
  static PyObject *
  signal_signal(PyObject *self, PyObject *args)
***************
*** 218,222 ****
  	siginterrupt(sig_num, 1);
  #endif
! 	if (signal(sig_num, func) == SIG_ERR) {
  		PyErr_SetFromErrno(PyExc_RuntimeError);
  		return NULL;
--- 214,218 ----
  	siginterrupt(sig_num, 1);
  #endif
! 	if (PyOS_setsig(sig_num, func) == SIG_ERR) {
  		PyErr_SetFromErrno(PyExc_RuntimeError);
  		return NULL;
***************
*** 239,244 ****
  A signal handler function is called with two arguments:\n\
  the first is the signal number, the second is the interrupted stack frame.";
  
- 
  static PyObject *
  signal_getsignal(PyObject *self, PyObject *args)
--- 235,240 ----
  A signal handler function is called with two arguments:\n\
  the first is the signal number, the second is the interrupted stack frame.";
+ 
  
  static PyObject *
  signal_getsignal(PyObject *self, PyObject *args)
***************
*** 267,272 ****
  anything else -- the callable Python object used as a handler\n\
  ";
  
- 
  /* List of functions defined in the module */
  static PyMethodDef signal_methods[] = {
--- 263,268 ----
  anything else -- the callable Python object used as a handler\n\
  ";
+ 
  
  /* List of functions defined in the module */
  static PyMethodDef signal_methods[] = {
***************
*** 285,289 ****
  
  
- 
  static char module_doc[] =
  "This module provides mechanisms to use signal handlers in Python.\n\
--- 281,284 ----
***************
*** 347,358 ****
  	for (i = 1; i < NSIG; i++) {
  		void (*t)(int);
! #ifdef HAVE_SIGACTION
! 		struct sigaction act;
! 		sigaction(i,  0, &act);
! 		t = act.sa_handler;
! #else
! 		t = signal(i, SIG_IGN);
! 		signal(i, t);
! #endif
  		Handlers[i].tripped = 0;
  		if (t == SIG_DFL)
--- 342,346 ----
  	for (i = 1; i < NSIG; i++) {
  		void (*t)(int);
! 		t = PyOS_getsig(i);
  		Handlers[i].tripped = 0;
  		if (t == SIG_DFL)
***************
*** 369,373 ****
  		Py_DECREF(Handlers[SIGINT].func);
  		Handlers[SIGINT].func = IntHandler;
! 		old_siginthandler = signal(SIGINT, &signal_handler);
  	}
  
--- 357,361 ----
  		Py_DECREF(Handlers[SIGINT].func);
  		Handlers[SIGINT].func = IntHandler;
! 		old_siginthandler = PyOS_setsig(SIGINT, &signal_handler);
  	}
  
***************
*** 556,560 ****
  	PyObject *func;
  
! 	signal(SIGINT, old_siginthandler);
  	old_siginthandler = SIG_DFL;
  
--- 544,548 ----
  	PyObject *func;
  
! 	PyOS_setsig(SIGINT, old_siginthandler);
  	old_siginthandler = SIG_DFL;
  
***************
*** 565,569 ****
  		if (i != SIGINT && func != NULL && func != Py_None &&
  		    func != DefaultHandler && func != IgnoreHandler)
! 			signal(i, SIG_DFL);
  		Py_XDECREF(func);
  	}
--- 553,557 ----
  		if (i != SIGINT && func != NULL && func != Py_None &&
  		    func != DefaultHandler && func != IgnoreHandler)
! 			PyOS_setsig(i, SIG_DFL);
  		Py_XDECREF(func);
  	}
***************
*** 578,582 ****
  
  
- 
  /* Declared in pyerrors.h */
  int
--- 566,569 ----
***************
*** 615,620 ****
  	return 0;
  }
  
- 
  /* Replacements for intrcheck.c functionality
   * Declared in pyerrors.h
--- 602,607 ----
  	return 0;
  }
+ 
  
  /* Replacements for intrcheck.c functionality
   * Declared in pyerrors.h