bpo-31106: Fix handling of erros in posix_fallocate() and posix_fadvi… · python/cpython@d4b93e2 (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -298,6 +298,16 @@ def test_posix_fallocate(self): | ||
298 | 298 | finally: |
299 | 299 | os.close(fd) |
300 | 300 | |
301 | +# issue31106 - posix_fallocate() does not set error in errno. | |
302 | +@unittest.skipUnless(hasattr(posix, 'posix_fallocate'), | |
303 | + "test needs posix.posix_fallocate()") | |
304 | +def test_posix_fallocate_errno(self): | |
305 | +try: | |
306 | +posix.posix_fallocate(-42, 0, 10) | |
307 | +except OSError as inst: | |
308 | +if inst.errno != errno.EBADF: | |
309 | +raise | |
310 | + | |
301 | 311 | @unittest.skipUnless(hasattr(posix, 'posix_fadvise'), |
302 | 312 | "test needs posix.posix_fadvise()") |
303 | 313 | def test_posix_fadvise(self): |
@@ -307,6 +317,15 @@ def test_posix_fadvise(self): | ||
307 | 317 | finally: |
308 | 318 | os.close(fd) |
309 | 319 | |
320 | +@unittest.skipUnless(hasattr(posix, 'posix_fadvise'), | |
321 | + "test needs posix.posix_fadvise()") | |
322 | +def test_posix_fadvise_errno(self): | |
323 | +try: | |
324 | +posix.posix_fadvise(-42, 0, 0, posix.POSIX_FADV_WILLNEED) | |
325 | +except OSError as inst: | |
326 | +if inst.errno != errno.EBADF: | |
327 | +raise | |
328 | + | |
310 | 329 | @unittest.skipUnless(os.utime in os.supports_fd, "test needs fd support in os.utime") |
311 | 330 | def test_utime_with_fd(self): |
312 | 331 | now = time.time() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8917,11 +8917,16 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, | ||
8917 | 8917 | Py_BEGIN_ALLOW_THREADS |
8918 | 8918 | result = posix_fallocate(fd, offset, length); |
8919 | 8919 | Py_END_ALLOW_THREADS |
8920 | - } while (result != 0 && errno == EINTR && | |
8921 | - !(async_err = PyErr_CheckSignals())); | |
8922 | -if (result != 0) | |
8923 | -return (!async_err) ? posix_error() : NULL; | |
8924 | -Py_RETURN_NONE; | |
8920 | + } while (result == EINTR && !(async_err = PyErr_CheckSignals())); | |
8921 | + | |
8922 | +if (result == 0) | |
8923 | +Py_RETURN_NONE; | |
8924 | + | |
8925 | +if (async_err) | |
8926 | +return NULL; | |
8927 | + | |
8928 | +errno = result; | |
8929 | +return posix_error(); | |
8925 | 8930 | } |
8926 | 8931 | #endif /* HAVE_POSIX_FALLOCATE) && !POSIX_FADVISE_AIX_BUG */ |
8927 | 8932 | |
@@ -8959,11 +8964,16 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, | ||
8959 | 8964 | Py_BEGIN_ALLOW_THREADS |
8960 | 8965 | result = posix_fadvise(fd, offset, length, advice); |
8961 | 8966 | Py_END_ALLOW_THREADS |
8962 | - } while (result != 0 && errno == EINTR && | |
8963 | - !(async_err = PyErr_CheckSignals())); | |
8964 | -if (result != 0) | |
8965 | -return (!async_err) ? posix_error() : NULL; | |
8966 | -Py_RETURN_NONE; | |
8967 | + } while (result == EINTR && !(async_err = PyErr_CheckSignals())); | |
8968 | + | |
8969 | +if (result == 0) | |
8970 | +Py_RETURN_NONE; | |
8971 | + | |
8972 | +if (async_err) | |
8973 | +return NULL; | |
8974 | + | |
8975 | +errno = result; | |
8976 | +return posix_error(); | |
8967 | 8977 | } |
8968 | 8978 | #endif /* HAVE_POSIX_FADVISE && !POSIX_FADVISE_AIX_BUG */ |
8969 | 8979 |