Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Lib/test/test_os/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,9 @@ def test_walk_bad_dir2(self):

walk_it = self.walk(self.tmp1_path, follow_symlinks=True)
if self.is_fwalk:
self.assertRaises(NotADirectoryError, next, walk_it)
with self.assertRaises(OSError) as cm:
next(walk_it)
self.assertIn(cm.exception.errno, (errno.ENOTDIR, errno.EINVAL))
self.assertRaises(StopIteration, next, walk_it)

@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
Expand Down Expand Up @@ -2269,6 +2271,8 @@ def test_chown_with_root(self):

@requires_non_root_user
@unittest.skipUnless(len(all_users) > 1, "test needs and more than one user")
@unittest.skipIf(sys.platform == 'cygwin',
'chown() can set any uid on Cygwin')
def test_chown_without_permission(self):
uid_1, uid_2 = all_users[:2]
gid = os.stat(os_helper.TESTFN).st_gid
Expand Down Expand Up @@ -4051,10 +4055,11 @@ def test_timerfd_non_blocking(self):
initial_expiration = 0.1
os.timerfd_settime(fd, initial=initial_expiration, interval=0)

# read() raises OSError with errno is EAGAIN for non-blocking timer.
with self.assertRaises(OSError) as ctx:
self.read_count_signaled(fd)
self.assertEqual(ctx.exception.errno, errno.EAGAIN)
if sys.platform != 'cygwin':
# read() raises OSError with errno is EAGAIN for non-blocking timer.
with self.assertRaises(OSError) as ctx:
self.read_count_signaled(fd)
self.assertEqual(ctx.exception.errno, errno.EAGAIN)

# Wait more than 0.1 seconds
time.sleep(initial_expiration + 0.1)
Expand Down Expand Up @@ -4235,12 +4240,19 @@ def test_timerfd_ns_initval(self):

# 2nd call
next_expiration_ns, interval_ns2 = os.timerfd_settime_ns(fd, initial=initial_expiration_ns, interval=interval_ns)
self.assertEqual(interval_ns2, interval_ns)
CYGWIN = (sys.platform == 'cygwin')
if not CYGWIN:
self.assertEqual(interval_ns2, interval_ns)
else:
self.assertEqual(interval_ns2, 0)
self.assertEqual(next_expiration_ns, initial_expiration_ns)

# timerfd_gettime
next_expiration_ns, interval_ns2 = os.timerfd_gettime_ns(fd)
self.assertEqual(interval_ns2, interval_ns)
if not CYGWIN:
self.assertEqual(interval_ns2, interval_ns)
else:
self.assertEqual(interval_ns2, 0)
self.assertLessEqual(next_expiration_ns, initial_expiration_ns)

self.assertAlmostEqual(next_expiration_ns, initial_expiration_ns, delta=limit_error)
Expand Down
16 changes: 13 additions & 3 deletions Lib/test/test_os/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def test_initgroups(self):
self.assertRaises(TypeError, posix.initgroups, "foo", 3, object())

# If a non-privileged user invokes it, it should fail with OSError
# EPERM.
if os.getuid() != 0:
# EPERM. On Cygwin, initgroups(name, 13) does not fail.
if os.getuid() != 0 and sys.platform != 'cygwin':
try:
name = pwd.getpwuid(posix.getuid()).pw_name
except KeyError:
Expand Down Expand Up @@ -597,7 +597,9 @@ def test_sysconf(self):
posix.sysconf(1.23)

arg_max = posix.sysconf("SC_ARG_MAX")
self.assertGreater(arg_max, 0)
# SC_ARG_MAX is -1 on Cygwin
if sys.platform != 'cygwin':
self.assertGreater(arg_max, 0)
self.assertEqual(
posix.sysconf(posix.sysconf_names["SC_ARG_MAX"]), arg_max)

Expand Down Expand Up @@ -1943,6 +1945,14 @@ def test_no_such_executable(self):
# directories in the $PATH that are not accessible.
except (FileNotFoundError, PermissionError) as exc:
self.assertEqual(exc.filename, no_such_executable)

# On Cygwin, os.posix_spawn() creates a child process even if the
# executable doesn't exist. We have to reap this process.
if sys.platform == 'cygwin':
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
pid, status = os.waitpid(-1, os.WNOHANG)
if pid != 0:
break
else:
pid2, status = os.waitpid(pid, 0)
self.assertEqual(pid2, pid)
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ def testIPv6toString(self):
assertInvalid('1:2:3:4:5:6:')
assertInvalid('1:2:3:4:5:6:7:8:0')
# bpo-29972: inet_pton() doesn't fail on AIX
if not AIX:
if not AIX and sys.platform != 'cygwin':
assertInvalid('1:2:3:4:5:6:7:8:')

self.assertEqual(b'\x00' * 12 + b'\xfe\x2a\x17\x40',
Expand Down Expand Up @@ -2001,7 +2001,8 @@ def test_getfqdn_filter_localhost(self):
self.assertEqual(socket.getfqdn(), socket.getfqdn("::"))

@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test.')
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
@unittest.skipIf(sys.platform in ('win32', 'cygwin'),
'does not work on Windows')
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
@unittest.skipUnless(hasattr(socket, 'if_nameindex'), "test needs socket.if_nameindex()")
@support.skip_android_selinux('if_nameindex')
Expand Down Expand Up @@ -2035,7 +2036,7 @@ def test_getaddrinfo_ipv6_scopeid_numeric(self):
self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, ifindex))

@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test.')
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
@unittest.skipIf(sys.platform in ('win32', 'cygwin'), 'does not work on Windows')
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
@unittest.skipUnless(hasattr(socket, 'if_nameindex'), "test needs socket.if_nameindex()")
@support.skip_android_selinux('if_nameindex')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a race condition in ``_PyBytes_FromList`` in free-threading mode.
16 changes: 12 additions & 4 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,6 @@ class _socket.socket "PySocketSockObject *" "clinic_state()->sock_type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2db2489bd2219fd8]*/

#define clinic_state() (find_module_state_by_def(type))
#include "clinic/socketmodule.c.h"
#undef clinic_state

/* XXX There's a problem here: *static* functions are not supposed to have
a Py prefix (or use CapitalizedWords). Later... */

Expand Down Expand Up @@ -688,6 +684,18 @@ class _socket.socket "PySocketSockObject *" "clinic_state()->sock_type"
#define IS_SELECTABLE(s) (_PyIsSelectable_fd((s)->sock_fd) || (s)->sock_timeout <= 0)
#endif

// SCM_RIGHTS, sendmsg(), recvmsg() and sethostname() don't work properly on
// Cygwin: disable these features.
#ifdef __CYGWIN__
# undef CMSG_LEN
# undef SCM_RIGHTS
# undef HAVE_SETHOSTNAME
#endif

#define clinic_state() (find_module_state_by_def(type))
#include "clinic/socketmodule.c.h"
#undef clinic_state

static PyObject*
select_error(void)
{
Expand Down
7 changes: 5 additions & 2 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "pycore_global_objects.h"// _Py_GET_GLOBAL_OBJECT()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_long.h" // _PyLong_DigitValue
#include "pycore_list.h" // _PyList_GetItemRef
#include "pycore_object.h" // _PyObject_GC_TRACK
#include "pycore_pymem.h" // PYMEM_CLEANBYTE
#include "pycore_strhex.h" // _Py_strhex_with_sep()
Expand Down Expand Up @@ -2991,8 +2992,10 @@ _PyBytes_FromList(PyObject *x)
size = _PyBytesWriter_GetAllocated(writer);

for (Py_ssize_t i = 0; i < PyList_GET_SIZE(x); i++) {
PyObject *item = PyList_GET_ITEM(x, i);
Py_INCREF(item);
PyObject *item = _PyList_GetItemRef((PyListObject *)x, i);
if (item == NULL) {
goto error;
}
Py_ssize_t value = PyNumber_AsSsize_t(item, NULL);
Py_DECREF(item);
if (value == -1 && PyErr_Occurred())
Expand Down
Loading