Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Unified Diff: Modules/faulthandler.c

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Modules/_cursesmodule.c ('k') | Modules/_io/fileio.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/faulthandler.c Tue Jul 26 09:37:46 2011 +0300
+++ b/Modules/faulthandler.c Mon Jul 25 09:47:18 2011 -0400
@@ -4,9 +4,6 @@
#include <object.h>
#include <frameobject.h>
#include <signal.h>
-#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)
-#include <pthread.h>
-#endif
/* Allocate at maximum 100 MB of the stack to raise the stack overflow */
#define STACK_OVERFLOW_MAX_SIZE (100*1024*1024)
@@ -71,7 +68,6 @@
PyObject *file;
int fd;
int all_threads;
- int chain;
_Py_sighandler_t previous;
PyInterpreterState *interp;
} user_signal_t;
@@ -94,7 +90,6 @@
# endif
#endif
-static void faulthandler_user(int signum);
#endif /* FAULTHANDLER_USER */
@@ -260,9 +255,9 @@
/* restore the previous handler */
#ifdef HAVE_SIGACTION
- (void)sigaction(signum, &handler->previous, NULL);
+ (void)sigaction(handler->signum, &handler->previous, NULL);
#else
- (void)signal(signum, handler->previous);
+ (void)signal(handler->signum, handler->previous);
#endif
handler->enabled = 0;
@@ -588,39 +583,6 @@
#endif /* FAULTHANDLER_LATER */
#ifdef FAULTHANDLER_USER
-static int
-faulthandler_register(int signum, int chain, _Py_sighandler_t *p_previous)
-{
-#ifdef HAVE_SIGACTION
- struct sigaction action;
- action.sa_handler = faulthandler_user;
- sigemptyset(&action.sa_mask);
- /* if the signal is received while the kernel is executing a system
- call, try to restart the system call instead of interrupting it and
- return EINTR. */
- action.sa_flags = SA_RESTART;
- if (chain) {
- /* do not prevent the signal from being received from within its
- own signal handler */
- action.sa_flags = SA_NODEFER;
- }
-#ifdef HAVE_SIGALTSTACK
- if (stack.ss_sp != NULL) {
- /* Call the signal handler on an alternate signal stack
- provided by sigaltstack() */
- action.sa_flags |= SA_ONSTACK;
- }
-#endif
- return sigaction(signum, &action, p_previous);
-#else
- _Py_sighandler_t previous;
- previous = signal(signum, faulthandler_user);
- if (p_previous != NULL)
- *p_previous = previous;
- return (previous == SIG_ERR);
-#endif
-}
-
/* Handler of user signals (e.g. SIGUSR1).
Dump the traceback of the current thread, or of all threads if
@@ -655,19 +617,6 @@
return;
_Py_DumpTraceback(user->fd, tstate);
}
-#ifdef HAVE_SIGACTION
- if (user->chain) {
- (void)sigaction(signum, &user->previous, NULL);
- /* call the previous signal handler */
- raise(signum);
- (void)faulthandler_register(signum, user->chain, NULL);
- }
-#else
- if (user->chain) {
- /* call the previous signal handler */
- user->previous(signum);
- }
-#endif
errno = save_errno;
}
@@ -693,23 +642,25 @@
}
static PyObject*
-faulthandler_register_py(PyObject *self,
- PyObject *args, PyObject *kwargs)
+faulthandler_register(PyObject *self,
+ PyObject *args, PyObject *kwargs)
{
- static char *kwlist[] = {"signum", "file", "all_threads", "chain", NULL};
+ static char *kwlist[] = {"signum", "file", "all_threads", NULL};
int signum;
PyObject *file = NULL;
int all_threads = 1;
- int chain = 0;
int fd;
user_signal_t *user;
_Py_sighandler_t previous;
+#ifdef HAVE_SIGACTION
+ struct sigaction action;
+#endif
PyThreadState *tstate;
int err;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "i|Oii:register", kwlist,
- &signum, &file, &all_threads, &chain))
+ "i|Oi:register", kwlist,
+ &signum, &file, &all_threads))
return NULL;
if (!check_signum(signum))
@@ -731,7 +682,25 @@
user = &user_signals[signum];
if (!user->enabled) {
- err = faulthandler_register(signum, chain, &previous);
+#ifdef HAVE_SIGACTION
+ action.sa_handler = faulthandler_user;
+ sigemptyset(&action.sa_mask);
+ /* if the signal is received while the kernel is executing a system
+ call, try to restart the system call instead of interrupting it and
+ return EINTR */
+ action.sa_flags = SA_RESTART;
+#ifdef HAVE_SIGALTSTACK
+ if (stack.ss_sp != NULL) {
+ /* Call the signal handler on an alternate signal stack
+ provided by sigaltstack() */
+ action.sa_flags |= SA_ONSTACK;
+ }
+#endif
+ err = sigaction(signum, &action, &previous);
+#else
+ previous = signal(signum, faulthandler_user);
+ err = (previous == SIG_ERR);
+#endif
if (err) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
@@ -743,7 +712,6 @@
user->file = file;
user->fd = fd;
user->all_threads = all_threads;
- user->chain = chain;
user->previous = previous;
user->interp = tstate->interp;
user->enabled = 1;
@@ -975,8 +943,8 @@
#ifdef FAULTHANDLER_USER
{"register",
- (PyCFunction)faulthandler_register_py, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("register(signum, file=sys.stderr, all_threads=True, chain=False): "
+ (PyCFunction)faulthandler_register, METH_VARARGS|METH_KEYWORDS,
+ PyDoc_STR("register(signum, file=sys.stderr, all_threads=True): "
"register an handler for the signal 'signum': dump the "
"traceback of the current thread, or of all threads if "
"all_threads is True, into file")},
« no previous file with comments | « Modules/_cursesmodule.c ('k') | Modules/_io/fileio.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+