Skip to content

Commit 08a0d10

Browse files
gh-154435: Fix os.posix_fadvise() and os.posix_fallocate() on DragonFly BSD (GH-154436)
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 <noreply@anthropic.com>
1 parent 2cf8e59 commit 08a0d10

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
@@ -13508,6 +13508,10 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
1350813508
Py_BEGIN_ALLOW_THREADS
1350913509
result = posix_fallocate(fd, offset, length);
1351013510
Py_END_ALLOW_THREADS
13511+
// DragonFly BSD returns -1 and sets errno.
13512+
if (result == -1) {
13513+
result = errno;
13514+
}
1351113515
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1351213516

1351313517
if (result == 0)
@@ -13555,6 +13559,10 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
1355513559
Py_BEGIN_ALLOW_THREADS
1355613560
result = posix_fadvise(fd, offset, length, advice);
1355713561
Py_END_ALLOW_THREADS
13562+
// DragonFly BSD returns -1 and sets errno.
13563+
if (result == -1) {
13564+
result = errno;
13565+
}
1355813566
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1355913567

1356013568
if (result == 0)

0 commit comments

Comments
 (0)