Skip to content

Commit d424344

Browse files
[3.14] bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374) (GH-138201)
(cherry picked from commit bbcb75c) Co-authored-by: Jakub Kulík <[email protected]>
1 parent 669253f commit d424344

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
@@ -8186,10 +8186,10 @@ static PyObject *
81868186
os_sched_get_priority_max_impl(PyObject *module, int policy)
81878187
/*[clinic end generated code: output=9e465c6e43130521 input=2097b7998eca6874]*/
81888188
{
8189-
int max;
8190-
8191-
max = sched_get_priority_max(policy);
8192-
if (max < 0)
8189+
/* make sure that errno is cleared before the call */
8190+
errno = 0;
8191+
int max = sched_get_priority_max(policy);
8192+
if (max == -1 && errno)
81938193
return posix_error();
81948194
return PyLong_FromLong(max);
81958195
}
@@ -8207,8 +8207,10 @@ static PyObject *
82078207
os_sched_get_priority_min_impl(PyObject *module, int policy)
82088208
/*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
82098209
{
8210+
/* make sure that errno is cleared before the call */
8211+
errno = 0;
82108212
int min = sched_get_priority_min(policy);
8211-
if (min < 0)
8213+
if (min == -1 && errno)
82128214
return posix_error();
82138215
return PyLong_FromLong(min);
82148216
}

0 commit comments

Comments
 (0)