From dbfcad8e6bf3db9eba076906fed141b3f91476f0 Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Wed, 23 Sep 2020 11:45:05 +0200 Subject: [PATCH 1/6] bpo-41839: Fix error checking in sched_get_priority_ functions --- Modules/posixmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 45debb9845e6c2..d15578090371d4 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7795,7 +7795,7 @@ os_sched_get_priority_max_impl(PyObject *module, int policy) int max; max = sched_get_priority_max(policy); - if (max < 0) + if (max == -1) return posix_error(); return PyLong_FromLong(max); } @@ -7814,7 +7814,7 @@ 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) + if (max == -1) return posix_error(); return PyLong_FromLong(min); } From 50bf6d7206ca2d5aa2eb971574483575f696c94b Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Wed, 23 Sep 2020 11:54:42 +0200 Subject: [PATCH 2/6] Added NEWS entry --- .../next/Library/2020-09-23-11-54-17.bpo-41839.kU5Ywl.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-09-23-11-54-17.bpo-41839.kU5Ywl.rst 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 index 00000000000000..760660408100d5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-09-23-11-54-17.bpo-41839.kU5Ywl.rst @@ -0,0 +1,2 @@ +Allow negative priority values from :func:`os.sched_get_priority_min` and +:func:`os.sched_get_priority_max` functions. From 489388dc21f424db8b56196cc298a23d2125a93c Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Wed, 23 Sep 2020 12:01:27 +0200 Subject: [PATCH 3/6] Fix typo --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d15578090371d4..944ae891774cc0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7814,7 +7814,7 @@ 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 (max == -1) + if (min == -1) return posix_error(); return PyLong_FromLong(min); } From f55a5328b5feda6daae9f439005713a5f434dc40 Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Fri, 6 Nov 2020 14:58:33 +0100 Subject: [PATCH 4/6] Make the error checking more robust --- Modules/posixmodule.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 944ae891774cc0..b24d02f841b25c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7794,8 +7794,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 == -1) + if (max == -1 && errno) return posix_error(); return PyLong_FromLong(max); } @@ -7813,8 +7815,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 == -1) + 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); } From 12475f61128d61d003a24b9501e5c4f7e331ce4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Mon, 14 Jul 2025 13:11:43 +0200 Subject: [PATCH 5/6] remove forward declaration Co-authored-by: Serhiy Storchaka --- Modules/posixmodule.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b9b98c521f7b48..c4a2a174de78be 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8200,11 +8200,9 @@ static PyObject * os_sched_get_priority_max_impl(PyObject *module, int policy) /*[clinic end generated code: output=9e465c6e43130521 input=2097b7998eca6874]*/ { - int max; - /* make sure that errno is cleared before the call */ errno = 0; - max = sched_get_priority_max(policy); + int max = sched_get_priority_max(policy); if (max == -1 && errno) return posix_error(); return PyLong_FromLong(max); From 51c1f1051d5100bacbf19a5d429c790e5322c0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Mon, 14 Jul 2025 13:11:56 +0200 Subject: [PATCH 6/6] remove another forward declaration Co-authored-by: Serhiy Storchaka --- Modules/posixmodule.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c4a2a174de78be..1c89bfa1ae6de6 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8221,11 +8221,9 @@ static PyObject * os_sched_get_priority_min_impl(PyObject *module, int policy) /*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/ { - int min; - /* make sure that errno is cleared before the call */ errno = 0; - min = sched_get_priority_min(policy); + int min = sched_get_priority_min(policy); if (min == -1 && errno) return posix_error(); return PyLong_FromLong(min);