summaryrefslogtreecommitdiff
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2016-07-16 18:27:11 -0400
committerTerry Jan Reedy <tjreedy@udel.edu>2016-07-16 18:27:11 -0400
commit61537aeaa3e0a9548a16ce3bfc9c4dd629ce7211 (patch)
treefabfded1dfc58221baa18a9a5a21aa2add31933f /Python/fileutils.c
parenta9ae1d67054fc0a8ad272082c41919044d1c1e9c (diff)
parent8f310e95a73a11c4184b7cd40bfb0d04609a171c (diff)
downloadcpython-61537aeaa3e0a9548a16ce3bfc9c4dd629ce7211.tar.gz
Issue #25507: Merge from 3.5 with ttk replacing colorchooser.
IDLE no longer runs buggy code because of its tkinter imports. Users must include the same imports required to run directly in Python.
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 23eed71321..06531d9726 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -683,6 +683,10 @@ _Py_fstat(int fd, struct _Py_stat_struct *status)
{
int res;
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
Py_BEGIN_ALLOW_THREADS
res = _Py_fstat_noraise(fd, status);
Py_END_ALLOW_THREADS
@@ -794,7 +798,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
int request;
int err;
#endif
- int flags;
+ int flags, new_flags;
int res;
#endif
@@ -885,10 +889,18 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
return -1;
}
- if (inheritable)
- flags &= ~FD_CLOEXEC;
- else
- flags |= FD_CLOEXEC;
+ if (inheritable) {
+ new_flags = flags & ~FD_CLOEXEC;
+ }
+ else {
+ new_flags = flags | FD_CLOEXEC;
+ }
+
+ if (new_flags == flags) {
+ /* FD_CLOEXEC flag already set/cleared: nothing to do */
+ return 0;
+ }
+
res = fcntl(fd, F_SETFD, flags);
if (res < 0) {
if (raise)
@@ -1169,6 +1181,10 @@ _Py_read(int fd, void *buf, size_t count)
int err;
int async_err = 0;
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
/* _Py_read() must not be called with an exception set, otherwise the
* caller may think that read() was interrupted by a signal and the signal
* handler raised an exception. */
@@ -1324,6 +1340,10 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
Py_ssize_t
_Py_write(int fd, const void *buf, size_t count)
{
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
/* _Py_write() must not be called with an exception set, otherwise the
* caller may think that write() was interrupted by a signal and the signal
* handler raised an exception. */
@@ -1473,6 +1493,10 @@ _Py_dup(int fd)
DWORD ftype;
#endif
+#ifdef WITH_THREAD
+ assert(PyGILState_Check());
+#endif
+
if (!_PyVerify_fd(fd)) {
PyErr_SetFromErrno(PyExc_OSError);
return -1;