summaryrefslogtreecommitdiffstats
path: root/Modules/readline.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-12-16 11:29:37 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-12-16 11:29:37 (GMT)
commitab0e9f7089c04df546af6cacbc8751247cf4020a (patch)
tree3494351a976a17a62146a3ddd365fe2b5936fca4 /Modules/readline.c
parente2b2bf55b30299e310b246b5b4b6f5a5f66e75b2 (diff)
parentc345ce1a69b3c4a46d87ef56d859bc70abfc74b4 (diff)
downloadcpython-ab0e9f7089c04df546af6cacbc8751247cf4020a.zip
cpython-ab0e9f7089c04df546af6cacbc8751247cf4020a.tar.gz
cpython-ab0e9f7089c04df546af6cacbc8751247cf4020a.tar.bz2
Issue #10350: Read and save errno before calling a function which might overwrite it.
Original patch by Hallvard B Furuseth.
Diffstat (limited to 'Modules/readline.c')
-rw-r--r--Modules/readline.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index a5e48ab..a710652 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -154,6 +154,7 @@ write_history_file(PyObject *self, PyObject *args)
{
PyObject *filename_obj = Py_None, *filename_bytes;
char *filename;
+ int err;
if (!PyArg_ParseTuple(args, "|O:write_history_file", &filename_obj))
return NULL;
if (filename_obj != Py_None) {
@@ -164,10 +165,11 @@ write_history_file(PyObject *self, PyObject *args)
filename_bytes = NULL;
filename = NULL;
}
- errno = write_history(filename);
- if (!errno && _history_length >= 0)
+ errno = err = write_history(filename);
+ if (!err && _history_length >= 0)
history_truncate_file(filename, _history_length);
Py_XDECREF(filename_bytes);
+ errno = err;
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
Py_RETURN_NONE;
@@ -969,7 +971,7 @@ readline_until_enter_or_signal(char *prompt, int *signal)
completed_input_string = not_done_reading;
while (completed_input_string == not_done_reading) {
- int has_input = 0;
+ int has_input = 0, err = 0;
while (!has_input)
{ struct timeval timeout = {0, 100000}; /* 0.1 seconds */
@@ -983,13 +985,14 @@ readline_until_enter_or_signal(char *prompt, int *signal)
/* select resets selectset if no input was available */
has_input = select(fileno(rl_instream) + 1, &selectset,
NULL, NULL, timeoutp);
+ err = errno;
if(PyOS_InputHook) PyOS_InputHook();
}
- if(has_input > 0) {
+ if (has_input > 0) {
rl_callback_read_char();
}
- else if (errno == EINTR) {
+ else if (err == EINTR) {
int s;
#ifdef WITH_THREAD
PyEval_RestoreThread(_PyOS_ReadlineTState);