Skip to content

Commit 67cdf27

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.13] gh-154435: Fix os.posix_fadvise() and os.posix_fallocate() on DragonFly BSD (GH-154436) (GH-154453)
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 f6eadb5 commit 67cdf27

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
@@ -12879,6 +12879,10 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
1287912879
Py_BEGIN_ALLOW_THREADS
1288012880
result = posix_fallocate(fd, offset, length);
1288112881
Py_END_ALLOW_THREADS
12882+
// DragonFly BSD returns -1 and sets errno.
12883+
if (result == -1) {
12884+
result = errno;
12885+
}
1288212886
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1288312887

1288412888
if (result == 0)
@@ -12926,6 +12930,10 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
1292612930
Py_BEGIN_ALLOW_THREADS
1292712931
result = posix_fadvise(fd, offset, length, advice);
1292812932
Py_END_ALLOW_THREADS
12933+
// DragonFly BSD returns -1 and sets errno.
12934+
if (result == -1) {
12935+
result = errno;
12936+
}
1292912937
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));
1293012938

1293112939
if (result == 0)

0 commit comments

Comments
 (0)