]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport my recent raw_input() vs no threads build vs SIGINT argh:
authorMichael W. Hudson <mwh@python.net>
Thu, 7 Apr 2005 10:19:47 +0000 (10:19 +0000)
committerMichael W. Hudson <mwh@python.net>
Thu, 7 Apr 2005 10:19:47 +0000 (10:19 +0000)
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
Modules/readline.c
Parser/myreadline.c

index 6ed345ed585db4ec31ad274dab4aea07e036470f..6e483052c869e71b45db78ba5a9f9ef26be6bef8 100644 (file)
--- 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.
 
index c61ded299126ddc41a75b8e621acbeee52b45cd4..74948136a2c4124dd1b4697e7c93139480c7c61d 100644 (file)
@@ -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();
index 7fc421e9d10a0f6ea991281d815b7477393f01d1..a932a8793aa1d395bd0968fba8564624829f3da1 100644 (file)
@@ -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;
                        }