Skip to content

Commit ac0b2b8

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-154435: Fix os.posix_fadvise() and os.posix_fallocate() on DragonFly BSD (GH-154436) (GH-154452)
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 08a0d10) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 29739c7 commit ac0b2b8

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :func:`os.posix_fadvise` and :func:`os.posix_fallocate` on DragonFly BSD:
2+
they raised :exc:`OSError` with a meaningless error code,
3+
because these functions return -1 and set ``errno`` there.

Modules/posixmodule.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13002,6 +13002,10 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
1300213002
Py_BEGIN_ALLOW_THREADS
1300313003
result = posix_fallocate(fd, offset, length);
1300413004
Py_END_ALLOW_THREADS
13005+
// DragonFly BSD returns -1 and sets errno.
13006+
if (result == -1) {
13007+
result = errno;
13008+
}
1300513009
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1300613010

1300713011
if (result == 0)
@@ -13049,6 +13053,10 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
1304913053
Py_BEGIN_ALLOW_THREADS
1305013054
result = posix_fadvise(fd, offset, length, advice);
1305113055
Py_END_ALLOW_THREADS
13056+
// DragonFly BSD returns -1 and sets errno.
13057+
if (result == -1) {
13058+
result = errno;
13059+
}
1305213060
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1305313061

1305413062
if (result == 0)

0 commit comments

Comments
 (0)