Skip to content

Commit 6f0ddf4

Browse files
PySequence_Tuple instead of PySequence_Fast and removed INCREF, DECREF
1 parent 75d8ae9 commit 6f0ddf4

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

Lib/test/test_socket.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,7 +3577,7 @@ class SendmsgStreamTests(SendmsgTests):
35773577
"sendmsg not supported")
35783578
def test_sendmsg_reentrant_ancillary_mutation(self):
35793579
self._test_sendmsg_reentrant_ancillary_mutation()
3580-
3580+
35813581
def _test_sendmsg_reentrant_ancillary_mutation(self):
35823582
import socket
35833583

@@ -3601,8 +3601,12 @@ def __index__(self):
36013601
self.addCleanup(left.close)
36023602
self.addCleanup(right.close)
36033603

3604-
with self.assertRaises(Exception):
3605-
left.sendmsg([b'x'], seq)
3604+
self.assertRaises(
3605+
(TypeError, OSError),
3606+
left.sendmsg,
3607+
[b'x'],
3608+
seq,
3609+
)
36063610

36073611
def testSendmsgExplicitNoneAddr(self):
36083612
# Check that peer address can be specified as None.

Modules/socketmodule.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4977,11 +4977,13 @@ _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg,
49774977
if (cmsg_arg == NULL)
49784978
ncmsgs = 0;
49794979
else {
4980-
if ((cmsg_fast = PySequence_Fast(cmsg_arg,
4981-
"sendmsg() argument 2 must be an "
4982-
"iterable")) == NULL)
4980+
cmsg_fast = PySequence_Tuple(cmsg_arg);
4981+
if (cmsg_fast == NULL) {
4982+
PyErr_SetString(PyExc_TypeError,
4983+
"sendmsg() argument 2 must be an iterable");
49834984
goto finally;
4984-
ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast);
4985+
}
4986+
ncmsgs = PyTuple_GET_SIZE(cmsg_fast);
49854987
}
49864988

49874989
#ifndef CMSG_SPACE
@@ -5003,18 +5005,15 @@ _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg,
50035005
size_t bufsize, space;
50045006
PyObject *item;
50055007

5006-
item = PySequence_Fast_GET_ITEM(cmsg_fast, ncmsgbufs);
5007-
Py_INCREF(item);
5008+
item = PyTuple_GET_ITEM(cmsg_fast, ncmsgbufs);
50085009

50095010
if (!PyArg_Parse(item,
50105011
"(iiy*):[sendmsg() ancillary data items]",
50115012
&cmsgs[ncmsgbufs].level,
50125013
&cmsgs[ncmsgbufs].type,
50135014
&cmsgs[ncmsgbufs].data)){
5014-
Py_DECREF(item);
50155015
goto finally;
50165016
}
5017-
Py_DECREF(item);
50185017

50195018
bufsize = cmsgs[ncmsgbufs++].data.len;
50205019

0 commit comments

Comments
 (0)