]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-154435: Fix os.posix_fadvise() and os.posix_fallocate() on DragonFly BSD...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 24 Jul 2026 11:45:34 +0000 (13:45 +0200)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2026 11:45:34 +0000 (11:45 +0000)
They return -1 and set errno instead of returning the error number, so
OSError was raised with a meaningless error code.
(cherry picked from commit 08a0d10709f04cf03260e5e852381cecb1c531e1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Misc/NEWS.d/next/Library/2026-07-22-10-30-08.gh-issue-154435.xCxm0T.rst [new file with mode: 0644]
Modules/posixmodule.c

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 (file)
index 0000000..b468e92
--- /dev/null
@@ -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.
index 06928025490ac8aaa39b6592c6b8cd00c5f18db4..26e62a1a7c50dc89f0d79b822ffc731d1afe6f28 100644 (file)
@@ -13002,6 +13002,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)
@@ -13049,6 +13053,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)