Skip to content

Commit a7ed0c9

Browse files
authored
gh-149879: Fix test_socket on Cygwin (#149913)
Disable SCM_RIGHTS, recvmsg(), sendmsg() and sethostname() on Cygwin.
1 parent 436a6f2 commit a7ed0c9

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

Lib/test/test_socket.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ def testIPv6toString(self):
14541454
assertInvalid('1:2:3:4:5:6:')
14551455
assertInvalid('1:2:3:4:5:6:7:8:0')
14561456
# bpo-29972: inet_pton() doesn't fail on AIX
1457-
if not AIX:
1457+
if not AIX and sys.platform != 'cygwin':
14581458
assertInvalid('1:2:3:4:5:6:7:8:')
14591459

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

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

20372038
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test.')
2038-
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
2039+
@unittest.skipIf(sys.platform in ('win32', 'cygwin'), 'does not work on Windows')
20392040
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
20402041
@unittest.skipUnless(hasattr(socket, 'if_nameindex'), "test needs socket.if_nameindex()")
20412042
@support.skip_android_selinux('if_nameindex')

Modules/socketmodule.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,6 @@ class _socket.socket "PySocketSockObject *" "clinic_state()->sock_type"
654654
[clinic start generated code]*/
655655
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2db2489bd2219fd8]*/
656656

657-
#define clinic_state() (find_module_state_by_def(type))
658-
#include "clinic/socketmodule.c.h"
659-
#undef clinic_state
660-
661657
/* XXX There's a problem here: *static* functions are not supposed to have
662658
a Py prefix (or use CapitalizedWords). Later... */
663659

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

687+
// SCM_RIGHTS, sendmsg(), recvmsg() and sethostname() don't work properly on
688+
// Cygwin: disable these features.
689+
#ifdef __CYGWIN__
690+
# undef CMSG_LEN
691+
# undef SCM_RIGHTS
692+
# undef HAVE_SETHOSTNAME
693+
#endif
694+
695+
#define clinic_state() (find_module_state_by_def(type))
696+
#include "clinic/socketmodule.c.h"
697+
#undef clinic_state
698+
691699
static PyObject*
692700
select_error(void)
693701
{

0 commit comments

Comments
 (0)