]> granicus.if.org Git - python/commitdiff
closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH...
authorbggardner <brent@ebrent.net>
Thu, 12 Sep 2019 10:02:48 +0000 (06:02 -0400)
committerBenjamin Peterson <benjamin@python.org>
Thu, 12 Sep 2019 10:02:48 +0000 (11:02 +0100)
This fixes a regression from 3.5. In recent releases, `getsockname()` in the AF_CAN case has returned a string.

Lib/test/test_socket.py
Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst [new file with mode: 0644]
Modules/socketmodule.c

index b855c523f080d2d5e39fab62972eea7729a8dcc2..b74549024b789116de22eb057d4900a3b0661312 100755 (executable)
@@ -1948,7 +1948,9 @@ class BasicCANTest(unittest.TestCase):
 
     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 (file)
index 0000000..09e1097
--- /dev/null
@@ -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.
index 3548b0c87875b808a8247e4a6103ebe7eeb066df..c649fa3c982f95edcaf15499c1d7dbfaff9f15a2 100644 (file)
@@ -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);
           }
         }