[Python-checkins] closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414)
Miss Islington (bot)
webhook-mailer at python.org
Thu Jun 27 12:30:53 EDT 2019
https://github.com/python/cpython/commit/65e187239a6feb09840ed9c2ebee51ed151e690d
commit: 65e187239a6feb09840ed9c2ebee51ed151e690d
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-27T09:30:41-07:00
summary:
closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414)
(cherry picked from commit 45a30af109f69a81576b87ea775863ba12d55316)
Co-authored-by: Brandt Bucher <brandtbucher at gmail.com>
files:
A Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst
M Lib/test/test_posix.py
M Modules/posixmodule.c
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 233fea4d57bb..1cd9e567b36e 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -1375,6 +1375,7 @@ def test_sched_setaffinity(self):
self.assertEqual(posix.sched_getaffinity(0), mask)
self.assertRaises(OSError, posix.sched_setaffinity, 0, [])
self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10])
+ self.assertRaises(ValueError, posix.sched_setaffinity, 0, map(int, "0X"))
self.assertRaises(OverflowError, posix.sched_setaffinity, 0, [1<<128])
self.assertRaises(OSError, posix.sched_setaffinity, -1, mask)
diff --git a/Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst b/Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst
new file mode 100644
index 000000000000..dea1a2925014
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst
@@ -0,0 +1,2 @@
+:func:`os.sched_setaffinity` now correctly handles errors that arise during iteration over its ``mask`` argument.
+Patch by Brandt Bucher.
\ No newline at end of file
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index b758e766a4d0..58cb9b0d468d 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5809,6 +5809,9 @@ os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask)
}
CPU_SET_S(cpu, setsize, cpu_set);
}
+ if (PyErr_Occurred()) {
+ goto error;
+ }
Py_CLEAR(iterator);
if (sched_setaffinity(pid, setsize, cpu_set)) {
More information about the Python-checkins
mailing list