[Python-checkins] cpython: Issue #23707: On UNIX, os.urandom() now calls the Python signal handler when
victor.stinner
python-checkins at python.org
Thu Mar 19 23:43:57 CET 2015
https://hg.python.org/cpython/rev/e57b4d464d1c
changeset: 95073:e57b4d464d1c
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Mar 19 23:36:33 2015 +0100
summary:
Issue #23707: On UNIX, os.urandom() now calls the Python signal handler when
read() is interrupted by a signal.
dev_urandom_python() now calls _Py_read() helper instead of calling directly
read().
files:
Python/random.c | 30 +++++++++++-------------------
1 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/Python/random.c b/Python/random.c
--- a/Python/random.c
+++ b/Python/random.c
@@ -262,29 +262,21 @@
}
}
- Py_BEGIN_ALLOW_THREADS
do {
- do {
- n = read(fd, buffer, (size_t)size);
- } while (n < 0 && errno == EINTR);
- if (n <= 0)
- break;
+ n = _Py_read(fd, buffer, (size_t)size);
+ if (n == -1)
+ return -1;
+ if (n == 0) {
+ PyErr_Format(PyExc_RuntimeError,
+ "Failed to read %zi bytes from /dev/urandom",
+ size);
+ return -1;
+ }
+
buffer += n;
- size -= (Py_ssize_t)n;
+ size -= n;
} while (0 < size);
- Py_END_ALLOW_THREADS
- if (n <= 0)
- {
- /* stop on error or if read(size) returned 0 */
- if (n < 0)
- PyErr_SetFromErrno(PyExc_OSError);
- else
- PyErr_Format(PyExc_RuntimeError,
- "Failed to read %zi bytes from /dev/urandom",
- size);
- return -1;
- }
return 0;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list