Skip to content

Commit

Permalink
bpo-31106: Fix handling of erros in posix_fallocate() and posix_fadvi…
Browse files Browse the repository at this point in the history
…se() (#3000) (#3000)
  • Loading branch information
socketpair authored and larryhastings committed Aug 14, 2017
1 parent 48d9823 commit d4b93e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
19 changes: 19 additions & 0 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ def test_posix_fallocate(self):
finally:
os.close(fd)

# issue31106 - posix_fallocate() does not set error in errno.
@unittest.skipUnless(hasattr(posix, 'posix_fallocate'),
"test needs posix.posix_fallocate()")
def test_posix_fallocate_errno(self):
try:
posix.posix_fallocate(-42, 0, 10)
except OSError as inst:
if inst.errno != errno.EBADF:
raise

@unittest.skipUnless(hasattr(posix, 'posix_fadvise'),
"test needs posix.posix_fadvise()")
def test_posix_fadvise(self):
Expand All @@ -307,6 +317,15 @@ def test_posix_fadvise(self):
finally:
os.close(fd)

@unittest.skipUnless(hasattr(posix, 'posix_fadvise'),
"test needs posix.posix_fadvise()")
def test_posix_fadvise_errno(self):
try:
posix.posix_fadvise(-42, 0, 0, posix.POSIX_FADV_WILLNEED)
except OSError as inst:
if inst.errno != errno.EBADF:
raise

@unittest.skipUnless(os.utime in os.supports_fd, "test needs fd support in os.utime")
def test_utime_with_fd(self):
now = time.time()
Expand Down
30 changes: 20 additions & 10 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8917,11 +8917,16 @@ os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Py_BEGIN_ALLOW_THREADS
result = posix_fallocate(fd, offset, length);
Py_END_ALLOW_THREADS
} while (result != 0 && errno == EINTR &&
!(async_err = PyErr_CheckSignals()));
if (result != 0)
return (!async_err) ? posix_error() : NULL;
Py_RETURN_NONE;
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));

if (result == 0)
Py_RETURN_NONE;

if (async_err)
return NULL;

errno = result;
return posix_error();
}
#endif /* HAVE_POSIX_FALLOCATE) && !POSIX_FADVISE_AIX_BUG */

Expand Down Expand Up @@ -8959,11 +8964,16 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Py_BEGIN_ALLOW_THREADS
result = posix_fadvise(fd, offset, length, advice);
Py_END_ALLOW_THREADS
} while (result != 0 && errno == EINTR &&
!(async_err = PyErr_CheckSignals()));
if (result != 0)
return (!async_err) ? posix_error() : NULL;
Py_RETURN_NONE;
} while (result == EINTR && !(async_err = PyErr_CheckSignals()));

if (result == 0)
Py_RETURN_NONE;

if (async_err)
return NULL;

errno = result;
return posix_error();
}
#endif /* HAVE_POSIX_FADVISE && !POSIX_FADVISE_AIX_BUG */

Expand Down

0 comments on commit d4b93e2

Please sign in to comment.