]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 27 Jun 2019 16:30:41 +0000 (09:30 -0700)
committerGitHub <noreply@github.com>
Thu, 27 Jun 2019 16:30:41 +0000 (09:30 -0700)
(cherry picked from commit 45a30af109f69a81576b87ea775863ba12d55316)

Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Lib/test/test_posix.py
Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst [new file with mode: 0644]
Modules/posixmodule.c

index 233fea4d57bbb0810343bab4a5309f99a0dc1777..1cd9e567b36e56ff0be7245a27bb93f8dd3aa8fa 100644 (file)
@@ -1375,6 +1375,7 @@ class PosixTester(unittest.TestCase):
         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 (file)
index 0000000..dea1a29
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`os.sched_setaffinity` now correctly handles errors that arise during iteration over its ``mask`` argument.\r
+Patch by Brandt Bucher.
\ No newline at end of file
index b758e766a4d07a898957ef2b30a09f0e5f8ddf28..58cb9b0d468d2fadd2a2a8cbed1382957f14b7b9 100644 (file)
@@ -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)) {