Skip to content

Commit a5d357c

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.15] gh-154435: Fix os.posix_fadvise() and os.posix_fallocate() on DragonFly BSD (GH-154436) (GH-154451)
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 5bf6a74 commit a5d357c

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
@@ -13475,6 +13475,10 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
1347513475
Py_BEGIN_ALLOW_THREADS
1347613476
result = posix_fallocate(fd, offset, length);
1347713477
Py_END_ALLOW_THREADS
13478+
// DragonFly BSD returns -1 and sets errno.
13479+
if (result == -1) {
13480+
result = errno;
13481+
}
1347813482
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1347913483

1348013484
if (result == 0)
@@ -13522,6 +13526,10 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
1352213526
Py_BEGIN_ALLOW_THREADS
1352313527
result = posix_fadvise(fd, offset, length, advice);
1352413528
Py_END_ALLOW_THREADS
13529+
// DragonFly BSD returns -1 and sets errno.
13530+
if (result == -1) {
13531+
result = errno;
13532+
}
1352513533
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1352613534

1352713535
if (result == 0)

0 commit comments

Comments
 (0)