]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374)...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 27 Aug 2025 18:05:36 +0000 (20:05 +0200)
committerGitHub <noreply@github.com>
Wed, 27 Aug 2025 18:05:36 +0000 (18:05 +0000)
(cherry picked from commit bbcb75c986c47887e6c0757e63d59cd7af544f39)

Co-authored-by: Jakub KulĂ­k <Kulikjak@gmail.com>
Misc/NEWS.d/next/Library/2020-09-23-11-54-17.bpo-41839.kU5Ywl.rst [new file with mode: 0644]
Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Library/2020-09-23-11-54-17.bpo-41839.kU5Ywl.rst b/Misc/NEWS.d/next/Library/2020-09-23-11-54-17.bpo-41839.kU5Ywl.rst
new file mode 100644 (file)
index 0000000..7606604
--- /dev/null
@@ -0,0 +1,2 @@
+Allow negative priority values from :func:`os.sched_get_priority_min` and
+:func:`os.sched_get_priority_max` functions.
index f31659808d7378a108460e9a459ba58d5745329b..90d91c28fd28a44f1903b2c3c23afcd0734f8654 100644 (file)
@@ -8101,10 +8101,10 @@ static PyObject *
 os_sched_get_priority_max_impl(PyObject *module, int policy)
 /*[clinic end generated code: output=9e465c6e43130521 input=2097b7998eca6874]*/
 {
-    int max;
-
-    max = sched_get_priority_max(policy);
-    if (max < 0)
+    /* make sure that errno is cleared before the call */
+    errno = 0;
+    int max = sched_get_priority_max(policy);
+    if (max == -1 && errno)
         return posix_error();
     return PyLong_FromLong(max);
 }
@@ -8122,8 +8122,10 @@ static PyObject *
 os_sched_get_priority_min_impl(PyObject *module, int policy)
 /*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
 {
+    /* make sure that errno is cleared before the call */
+    errno = 0;
     int min = sched_get_priority_min(policy);
-    if (min < 0)
+    if (min == -1 && errno)
         return posix_error();
     return PyLong_FromLong(min);
 }