Commit 45a30af1 authored by Brandt Bucher's avatar Brandt Bucher Committed by Benjamin Peterson

closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414)

parent 97d15b1e
...@@ -1368,6 +1368,7 @@ class PosixTester(unittest.TestCase): ...@@ -1368,6 +1368,7 @@ class PosixTester(unittest.TestCase):
self.assertEqual(posix.sched_getaffinity(0), mask) self.assertEqual(posix.sched_getaffinity(0), mask)
self.assertRaises(OSError, posix.sched_setaffinity, 0, []) self.assertRaises(OSError, posix.sched_setaffinity, 0, [])
self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10]) 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(OverflowError, posix.sched_setaffinity, 0, [1<<128])
self.assertRaises(OSError, posix.sched_setaffinity, -1, mask) self.assertRaises(OSError, posix.sched_setaffinity, -1, mask)
......
: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
...@@ -6413,6 +6413,9 @@ os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask) ...@@ -6413,6 +6413,9 @@ os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask)
} }
CPU_SET_S(cpu, setsize, cpu_set); CPU_SET_S(cpu, setsize, cpu_set);
} }
if (PyErr_Occurred()) {
goto error;
}
Py_CLEAR(iterator); Py_CLEAR(iterator);
if (sched_setaffinity(pid, setsize, cpu_set)) { if (sched_setaffinity(pid, setsize, cpu_set)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment