From da56b18e2d366c18e7403b4575b9a3cf01bb1520 Mon Sep 17 00:00:00 2001 From: bggardner Date: Wed, 26 Jun 2019 07:59:39 -0400 Subject: [PATCH 1/9] bpo-37405: socket.getsockname() returns string instead of tuple --- Modules/socketmodule.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 73e64f235a6f2d..5f8a9081e9e487 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1513,8 +1513,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto) #endif /* CAN_ISOTP */ default: { - return Py_BuildValue("O&", PyUnicode_DecodeFSDefault, - ifname); + return Py_BuildValue("O&h", PyUnicode_DecodeFSDefault, + ifname, + a->can_family); } } } From 0cd0ac903c3dbd4e202c7d34c1c5a66ca17e9573 Mon Sep 17 00:00:00 2001 From: bggardner Date: Wed, 26 Jun 2019 14:14:06 -0400 Subject: [PATCH 2/9] Added BasicCANTest.testBind() to check return of getsockname() --- Lib/test/test_socket.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 50094de58bf1c9..e8c5312383c326 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1921,7 +1921,13 @@ def testCreateBCMSocket(self): def testBindAny(self): with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: s.bind(('', )) - + + def testBind(self): + with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: + address = ('', ) + s.bind(address) + self.assertEqual(s.getsockname(), address) + def testTooLongInterfaceName(self): # most systems limit IFNAMSIZ to 16, take 1024 to be sure with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: From 34e708b9874a52e21a614586fe4963a178689258 Mon Sep 17 00:00:00 2001 From: bggardner Date: Wed, 26 Jun 2019 14:26:31 -0400 Subject: [PATCH 3/9] Removed whitespace --- Lib/test/test_socket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index e8c5312383c326..aa6b1812e8e073 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1921,13 +1921,13 @@ def testCreateBCMSocket(self): def testBindAny(self): with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: s.bind(('', )) - + def testBind(self): with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: address = ('', ) s.bind(address) self.assertEqual(s.getsockname(), address) - + def testTooLongInterfaceName(self): # most systems limit IFNAMSIZ to 16, take 1024 to be sure with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: From a538f0dfc723f11cae2be00061ceba53e0ff3950 Mon Sep 17 00:00:00 2001 From: bggardner Date: Wed, 26 Jun 2019 14:39:08 -0400 Subject: [PATCH 4/9] Remove more whitespace --- Lib/test/test_socket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index aa6b1812e8e073..c3788a9b5ff5f0 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1927,7 +1927,7 @@ def testBind(self): address = ('', ) s.bind(address) self.assertEqual(s.getsockname(), address) - + def testTooLongInterfaceName(self): # most systems limit IFNAMSIZ to 16, take 1024 to be sure with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: From 8763f3b47229613bd9a3f9f1102f6d14602b52c8 Mon Sep 17 00:00:00 2001 From: bggardner Date: Wed, 26 Jun 2019 20:43:14 -0400 Subject: [PATCH 5/9] Replaced BasicCANTest.testBind() with additional line in BasicCANTest.testBindAny() --- Lib/test/test_socket.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index c3788a9b5ff5f0..149446e7f4b4a0 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1921,12 +1921,7 @@ def testCreateBCMSocket(self): def testBindAny(self): with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: s.bind(('', )) - - def testBind(self): - with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: - address = ('', ) - s.bind(address) - self.assertEqual(s.getsockname(), address) + self.assertIsInstance(s.getsockname(), tuple) def testTooLongInterfaceName(self): # most systems limit IFNAMSIZ to 16, take 1024 to be sure From cc2c37fdc197b9f3e22a038fe753412bfea5796d Mon Sep 17 00:00:00 2001 From: bggardner Date: Thu, 27 Jun 2019 20:56:55 -0400 Subject: [PATCH 6/9] Removed AF_CAN from makesockaddr return tuple --- Modules/socketmodule.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 5f8a9081e9e487..81b8a0677b19d5 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1513,9 +1513,8 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto) #endif /* CAN_ISOTP */ default: { - return Py_BuildValue("O&h", PyUnicode_DecodeFSDefault, - ifname, - a->can_family); + return Py_BuildValue("(O&)", PyUnicode_DecodeFSDefault, + ifname); } } } From de6995f80f3a981471347f5520bae6825bf49200 Mon Sep 17 00:00:00 2001 From: bggardner Date: Wed, 11 Sep 2019 20:08:55 -0400 Subject: [PATCH 7/9] Update test_socket.py --- Lib/test/test_socket.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 149446e7f4b4a0..2cd177ed1a10e2 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1920,8 +1920,9 @@ def testCreateBCMSocket(self): def testBindAny(self): with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: - s.bind(('', )) - self.assertIsInstance(s.getsockname(), tuple) + address = ('', ) + s.bind(address) + self.assertEqual(s.getsockname(), address) def testTooLongInterfaceName(self): # most systems limit IFNAMSIZ to 16, take 1024 to be sure From f5937be919c5b2913fc29564edc4f4c60321af1e Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Wed, 11 Sep 2019 20:28:05 -0400 Subject: [PATCH 8/9] Added NEWS.d entry --- .../next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst 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 00000000000000..c054cf0aeb0a3c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst @@ -0,0 +1,4 @@ +Fixed regression bug for socket.getsockname() for non-CAN_ISOTP AF_CAN +address family sockets by returning a tuple instead of string. The second +item of the returned tuple is now empty instead of the integer value of the +family. From b72196f28def37137f7acc32cdb6c70ec6c7ee69 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 12 Sep 2019 10:38:26 +0100 Subject: [PATCH 9/9] remove confusing sentence about second element of a 1-tuple --- .../next/Library/2019-09-11-20-27-41.bpo-37405.MG5xiY.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 index c054cf0aeb0a3c..09e10973422106 100644 --- 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 @@ -1,4 +1,2 @@ Fixed regression bug for socket.getsockname() for non-CAN_ISOTP AF_CAN -address family sockets by returning a tuple instead of string. The second -item of the returned tuple is now empty instead of the integer value of the -family. +address family sockets by returning a 1-tuple instead of string.