Skip to content

Commit 082e6b7

Browse files
Corrected Indentation and moved test to seperate class
1 parent 5f0a05a commit 082e6b7

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

Lib/test/test_socket.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,41 +3573,6 @@ class SendmsgStreamTests(SendmsgTests):
35733573
# Tests for sendmsg() which require a stream socket and do not
35743574
# involve recvmsg() or recvmsg_into().
35753575

3576-
@unittest.skipUnless(hasattr(socket.socket, "sendmsg"),
3577-
"sendmsg not supported")
3578-
def test_sendmsg_reentrant_ancillary_mutation(self):
3579-
self._test_sendmsg_reentrant_ancillary_mutation()
3580-
3581-
def _test_sendmsg_reentrant_ancillary_mutation(self):
3582-
import socket
3583-
3584-
seq = []
3585-
3586-
class Mut:
3587-
def __init__(self):
3588-
self.tripped = False
3589-
def __index__(self):
3590-
if not self.tripped:
3591-
self.tripped = True
3592-
seq.clear()
3593-
return 0
3594-
3595-
seq[:] = [
3596-
(socket.SOL_SOCKET, Mut(), b'x'),
3597-
(socket.SOL_SOCKET, 0, b'x'),
3598-
]
3599-
3600-
left, right = socket.socketpair()
3601-
self.addCleanup(left.close)
3602-
self.addCleanup(right.close)
3603-
3604-
self.assertRaises(
3605-
(TypeError, OSError),
3606-
left.sendmsg,
3607-
[b'x'],
3608-
seq,
3609-
)
3610-
36113576
def testSendmsgExplicitNoneAddr(self):
36123577
# Check that peer address can be specified as None.
36133578
self.assertEqual(self.serv_sock.recv(len(MSG)), MSG)
@@ -7526,6 +7491,32 @@ def detach():
75267491
pass
75277492

75287493

7494+
class SendmsgReentrancyTests(unittest.TestCase):
7495+
7496+
@unittest.skipUnless(hasattr(socket.socket, "sendmsg"),
7497+
"sendmsg not supported")
7498+
def test_sendmsg_reentrant_ancillary_mutation(self):
7499+
7500+
class Mut:
7501+
def __index__(self):
7502+
seq.clear()
7503+
return 0
7504+
7505+
seq = [
7506+
(socket.SOL_SOCKET, Mut(), b'x'),
7507+
(socket.SOL_SOCKET, 0, b'x'),
7508+
]
7509+
7510+
left, right = socket.socketpair()
7511+
self.addCleanup(left.close)
7512+
self.addCleanup(right.close)
7513+
self.assertRaises(
7514+
(TypeError, OSError),
7515+
left.sendmsg,
7516+
[b'x'],
7517+
seq,
7518+
)
7519+
75297520
def setUpModule():
75307521
thread_info = threading_helper.threading_setup()
75317522
unittest.addModuleCleanup(threading_helper.threading_cleanup, *thread_info)

Modules/socketmodule.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4982,8 +4982,8 @@ _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg,
49824982
PyErr_SetString(PyExc_TypeError,
49834983
"sendmsg() argument 2 must be an iterable");
49844984
goto finally;
4985-
}
4986-
ncmsgs = PyTuple_GET_SIZE(cmsg_fast);
4985+
}
4986+
ncmsgs = PyTuple_GET_SIZE(cmsg_fast);
49874987
}
49884988

49894989
#ifndef CMSG_SPACE
@@ -5008,13 +5008,11 @@ _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg,
50085008
item = PyTuple_GET_ITEM(cmsg_fast, ncmsgbufs);
50095009

50105010
if (!PyArg_Parse(item,
5011-
"(iiy*):[sendmsg() ancillary data items]",
5012-
&cmsgs[ncmsgbufs].level,
5013-
&cmsgs[ncmsgbufs].type,
5014-
&cmsgs[ncmsgbufs].data)){
5011+
"(iiy*):[sendmsg() ancillary data items]",
5012+
&cmsgs[ncmsgbufs].level,
5013+
&cmsgs[ncmsgbufs].type,
5014+
&cmsgs[ncmsgbufs].data))
50155015
goto finally;
5016-
}
5017-
50185016
bufsize = cmsgs[ncmsgbufs++].data.len;
50195017

50205018
#ifdef CMSG_SPACE

0 commit comments

Comments
 (0)