Skip to content

Commit 502ca0d

Browse files
[3.13] bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374) (GH-138202)
(cherry picked from commit bbcb75c) Co-authored-by: Jakub Kulík <[email protected]>
1 parent d6a3460 commit 502ca0d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow negative priority values from :func:`os.sched_get_priority_min` and
2+
:func:`os.sched_get_priority_max` functions.

Modules/posixmodule.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8101,10 +8101,10 @@ static PyObject *
81018101
os_sched_get_priority_max_impl(PyObject *module, int policy)
81028102
/*[clinic end generated code: output=9e465c6e43130521 input=2097b7998eca6874]*/
81038103
{
8104-
int max;
8105-
8106-
max = sched_get_priority_max(policy);
8107-
if (max < 0)
8104+
/* make sure that errno is cleared before the call */
8105+
errno = 0;
8106+
int max = sched_get_priority_max(policy);
8107+
if (max == -1 && errno)
81088108
return posix_error();
81098109
return PyLong_FromLong(max);
81108110
}
@@ -8122,8 +8122,10 @@ static PyObject *
81228122
os_sched_get_priority_min_impl(PyObject *module, int policy)
81238123
/*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
81248124
{
8125+
/* make sure that errno is cleared before the call */
8126+
errno = 0;
81258127
int min = sched_get_priority_min(policy);
8126-
if (min < 0)
8128+
if (min == -1 && errno)
81278129
return posix_error();
81288130
return PyLong_FromLong(min);
81298131
}

0 commit comments

Comments
 (0)