[Python-checkins] closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392) (GH-16018)

Benjamin Peterson webhook-mailer at python.org
Thu Sep 12 06:34:32 EDT 2019


https://github.com/python/cpython/commit/f60fd95dcc189ace8c0a2177a394b9cc20389a1e
commit: f60fd95dcc189ace8c0a2177a394b9cc20389a1e
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Benjamin Peterson <benjamin at python.org>
date: 2019-09-12T11:34:28+01:00
summary:

closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392) (GH-16018)

This fixes a regression from 3.5. In recent releases, `getsockname()` in the AF_CAN case has returned a string.
(cherry picked from commit 954900a3f98a8c0dea14dd575490237f3f8626b3)

Co-authored-by: bggardner <brent at ebrent.net>

files:
A Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst
M Lib/test/test_socket.py
M Modules/socketmodule.c

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index c472be135e39..1bf562a03d55 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1897,7 +1897,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
diff --git a/Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst b/Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst
new file mode 100644
index 000000000000..09e109734221
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst
@@ -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.
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 910e2bdd1319..594a0d6efad1 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1524,7 +1524,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);
           }
         }



More information about the Python-checkins mailing list