From 9a740c3f20d764b2ff5500d20168ddf1863644da Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 22 Jul 2026 10:30:08 +0300 Subject: [PATCH] gh-154435: Fix os.posix_fadvise() and os.posix_fallocate() on DragonFly BSD They return -1 and set errno instead of returning the error number, so OSError was raised with a meaningless error code. Co-Authored-By: Claude Opus 4.8 --- .../2026-07-22-10-30-08.gh-issue-154435.xCxm0T.rst | 3 +++ Modules/posixmodule.c | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-22-10-30-08.gh-issue-154435.xCxm0T.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-22-10-30-08.gh-issue-154435.xCxm0T.rst b/Misc/NEWS.d/next/Library/2026-07-22-10-30-08.gh-issue-154435.xCxm0T.rst new file mode 100644 index 000000000000000..b468e929b1ca18b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-22-10-30-08.gh-issue-154435.xCxm0T.rst @@ -0,0 +1,3 @@ +Fix :func:`os.posix_fadvise` and :func:`os.posix_fallocate` on DragonFly BSD: +they raised :exc:`OSError` with a meaningless error code, +because these functions return -1 and set ``errno`` there. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 75ee7e260ce9850..de9575781881563 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -13508,6 +13508,10 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, Py_BEGIN_ALLOW_THREADS result = posix_fallocate(fd, offset, length); Py_END_ALLOW_THREADS + // DragonFly BSD returns -1 and sets errno. + if (result == -1) { + result = errno; + } } while (result == EINTR && !(async_err = PyErr_CheckSignals())); if (result == 0) @@ -13555,6 +13559,10 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, Py_BEGIN_ALLOW_THREADS result = posix_fadvise(fd, offset, length, advice); Py_END_ALLOW_THREADS + // DragonFly BSD returns -1 and sets errno. + if (result == -1) { + result = errno; + } } while (result == EINTR && !(async_err = PyErr_CheckSignals())); if (result == 0)