bpo-31106: Fix handling of erros in posix_fallocate() and posix_fadvi… · python/cpython@3a04c52 (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -235,6 +235,16 @@ def test_posix_fallocate(self): | ||
235 | 235 | finally: |
236 | 236 | os.close(fd) |
237 | 237 | |
238 | +# issue31106 - posix_fallocate() does not set error in errno. | |
239 | +@unittest.skipUnless(hasattr(posix, 'posix_fallocate'), | |
240 | + "test needs posix.posix_fallocate()") | |
241 | +def test_posix_fallocate_errno(self): | |
242 | +try: | |
243 | +posix.posix_fallocate(-42, 0, 10) | |
244 | +except OSError as inst: | |
245 | +if inst.errno != errno.EBADF: | |
246 | +raise | |
247 | + | |
238 | 248 | @unittest.skipUnless(hasattr(posix, 'posix_fadvise'), |
239 | 249 | "test needs posix.posix_fadvise()") |
240 | 250 | def test_posix_fadvise(self): |
@@ -244,6 +254,15 @@ def test_posix_fadvise(self): | ||
244 | 254 | finally: |
245 | 255 | os.close(fd) |
246 | 256 | |
257 | +@unittest.skipUnless(hasattr(posix, 'posix_fadvise'), | |
258 | + "test needs posix.posix_fadvise()") | |
259 | +def test_posix_fadvise_errno(self): | |
260 | +try: | |
261 | +posix.posix_fadvise(-42, 0, 0, posix.POSIX_FADV_WILLNEED) | |
262 | +except OSError as inst: | |
263 | +if inst.errno != errno.EBADF: | |
264 | +raise | |
265 | + | |
247 | 266 | @unittest.skipUnless(os.utime in os.supports_fd, "test needs fd support in os.utime") |
248 | 267 | def test_utime_with_fd(self): |
249 | 268 | now = time.time() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8792,11 +8792,16 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, | ||
8792 | 8792 | Py_BEGIN_ALLOW_THREADS |
8793 | 8793 | result = posix_fallocate(fd, offset, length); |
8794 | 8794 | Py_END_ALLOW_THREADS |
8795 | - } while (result != 0 && errno == EINTR && | |
8796 | - !(async_err = PyErr_CheckSignals())); | |
8797 | -if (result != 0) | |
8798 | -return (!async_err) ? posix_error() : NULL; | |
8799 | -Py_RETURN_NONE; | |
8795 | + } while (result == EINTR && !(async_err = PyErr_CheckSignals())); | |
8796 | + | |
8797 | +if (result == 0) | |
8798 | +Py_RETURN_NONE; | |
8799 | + | |
8800 | +if (async_err) | |
8801 | +return NULL; | |
8802 | + | |
8803 | +errno = result; | |
8804 | +return posix_error(); | |
8800 | 8805 | } |
8801 | 8806 | #endif /* HAVE_POSIX_FALLOCATE) && !POSIX_FADVISE_AIX_BUG */ |
8802 | 8807 | |
@@ -8834,11 +8839,16 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, | ||
8834 | 8839 | Py_BEGIN_ALLOW_THREADS |
8835 | 8840 | result = posix_fadvise(fd, offset, length, advice); |
8836 | 8841 | Py_END_ALLOW_THREADS |
8837 | - } while (result != 0 && errno == EINTR && | |
8838 | - !(async_err = PyErr_CheckSignals())); | |
8839 | -if (result != 0) | |
8840 | -return (!async_err) ? posix_error() : NULL; | |
8841 | -Py_RETURN_NONE; | |
8842 | + } while (result == EINTR && !(async_err = PyErr_CheckSignals())); | |
8843 | + | |
8844 | +if (result == 0) | |
8845 | +Py_RETURN_NONE; | |
8846 | + | |
8847 | +if (async_err) | |
8848 | +return NULL; | |
8849 | + | |
8850 | +errno = result; | |
8851 | +return posix_error(); | |
8842 | 8852 | } |
8843 | 8853 | #endif /* HAVE_POSIX_FADVISE && !POSIX_FADVISE_AIX_BUG */ |
8844 | 8854 |