]> granicus.if.org Git - python/commitdiff
closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 12 Sep 2019 10:34:28 +0000 (03:34 -0700)
committerBenjamin Peterson <benjamin@python.org>
Thu, 12 Sep 2019 10:34:28 +0000 (11:34 +0100)
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@ebrent.net>
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 c472be135e392dd8d7fd09aacef03d496ddbf0c2..1bf562a03d556cad202a53bcbee6108cf58201ff 100644 (file)
@@ -1897,7 +1897,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 910e2bdd1319f1ac0a1638dd488abb8a4e4b98c8..594a0d6efad197f0bfc4331a75f13f39027f6f5f 100644 (file)
@@ -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);
           }
         }