From 52cba65d1a720a7062660b0d98b04fd3212a6aff Mon Sep 17 00:00:00 2001 From: "Michael W. Hudson" Date: Thu, 7 Apr 2005 10:19:47 +0000 Subject: Backport my recent raw_input() vs no threads build vs SIGINT argh: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! --- Misc/NEWS | 3 +++ Modules/readline.c | 4 ++++ Parser/myreadline.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 6ed345e..6e48305 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.4.2a Core and builtins ----------------- +- Typing Ctrl-C whilst raw_input() was waiting in a build with threads + disabled caused a crash. + - Bug #1165306: instancemethod_new allowed the creation of a method with im_class == im_self == NULL, which caused a crash when called. diff --git a/Modules/readline.c b/Modules/readline.c index c61ded2..7494813 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -777,9 +777,13 @@ readline_until_enter_or_signal(char *prompt, int *signal) } else if (errno == EINTR) { int s; +#ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); +#endif s = PyErr_CheckSignals(); +#ifdef WITH_THREAD PyEval_SaveThread(); +#endif if (s < 0) { rl_free_line_state(); rl_cleanup_after_signal(); diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 7fc421e..a932a87 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -82,9 +82,13 @@ my_fgets(char *buf, int len, FILE *fp) #ifdef EINTR if (errno == EINTR) { int s; +#ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); +#endif s = PyErr_CheckSignals(); +#ifdef WITH_THREAD PyEval_SaveThread(); +#endif if (s < 0) { return 1; } -- cgit v0.12