Skip to content

Commit

Permalink
closes bpo-37405: Make socket.getsockname() always return a tuple for…
Browse files Browse the repository at this point in the history
… AF_CAN. (pythonGH-14392)

This fixes a regression from 3.5. In recent releases, `getsockname()` in the AF_CAN case has returned a string.
  • Loading branch information
bggardner authored and benjaminp committed Sep 12, 2019
1 parent 64535fc commit 954900a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,9 @@ def testCreateBCMSocket(self):

def testBindAny(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
s.bind(('', ))
address = ('', )
s.bind(address)
self.assertEqual(s.getsockname(), address)

def testTooLongInterfaceName(self):
# most systems limit IFNAMSIZ to 16, take 1024 to be sure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed regression bug for socket.getsockname() for non-CAN_ISOTP AF_CAN
address family sockets by returning a 1-tuple instead of string.
2 changes: 1 addition & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
#endif /* CAN_ISOTP */
default:
{
return Py_BuildValue("O&", PyUnicode_DecodeFSDefault,
return Py_BuildValue("(O&)", PyUnicode_DecodeFSDefault,
ifname);
}
}
Expand Down

0 comments on commit 954900a

Please sign in to comment.