Skip to content

bpo-41839: Fix error checking in sched_get_priority_ functions #22374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow negative priority values from :func:`os.sched_get_priority_min` and
:func:`os.sched_get_priority_max` functions.
12 changes: 9 additions & 3 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8187,8 +8187,10 @@ os_sched_get_priority_max_impl(PyObject *module, int policy)
{
int max;

/* make sure that errno is cleared before the call */
errno = 0;
max = sched_get_priority_max(policy);
if (max < 0)
if (max == -1 && errno)
return posix_error();
return PyLong_FromLong(max);
}
Expand All @@ -8206,8 +8208,12 @@ static PyObject *
os_sched_get_priority_min_impl(PyObject *module, int policy)
/*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
{
int min = sched_get_priority_min(policy);
if (min < 0)
int min;

/* make sure that errno is cleared before the call */
errno = 0;
min = sched_get_priority_min(policy);
if (min == -1 && errno)
return posix_error();
return PyLong_FromLong(min);
}
Expand Down
Loading