From 494b2d2d64a5755ccacb3451370e16114cbb77b2 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Sun, 12 Dec 2021 00:49:22 +0100 Subject: [PATCH 1/8] bpo-30512: add CAN Socket support for NetBSD --- .../2021-12-12-00-49-19.bpo-30512.nU9E9V.rst | 1 + Modules/socketmodule.c | 14 ++++++++++++++ Modules/socketmodule.h | 4 +++- configure | 3 ++- configure.ac | 3 ++- pyconfig.h.in | 3 +++ 6 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst b/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst new file mode 100644 index 00000000000000..ebcd568abbca71 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst @@ -0,0 +1 @@ +Add CAN Socket support for NetBSD diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 89e93c58187c96..aff07f74b14282 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -7790,6 +7790,20 @@ PyInit__socket(void) PyModule_AddIntMacro(m, J1939_FILTER_MAX); #endif +#ifdef HAVE_NETCAN_CAN_H + PyModule_AddIntMacro(m, CAN_EFF_FLAG); + PyModule_AddIntMacro(m, CAN_RTR_FLAG); + PyModule_AddIntMacro(m, CAN_ERR_FLAG); + + PyModule_AddIntMacro(m, CAN_SFF_MASK); + PyModule_AddIntMacro(m, CAN_EFF_MASK); + PyModule_AddIntMacro(m, CAN_ERR_MASK); + + PyModule_AddIntMacro(m, CAN_RAW_FILTER); + /* PyModule_AddIntMacro(m, CAN_RAW_ERR_FILTER); */ + PyModule_AddIntMacro(m, CAN_RAW_LOOPBACK); + PyModule_AddIntMacro(m, CAN_RAW_RECV_OWN_MSGS); +#endif #ifdef SOL_RDS PyModule_AddIntMacro(m, SOL_RDS); #endif diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h index aea599f0ee6c85..db26c046c36379 100644 --- a/Modules/socketmodule.h +++ b/Modules/socketmodule.h @@ -129,6 +129,8 @@ typedef int socklen_t; #ifdef HAVE_LINUX_CAN_H # include +#elif defined(HAVE_NETCAN_CAN_H) +# include #else # undef AF_CAN # undef PF_CAN @@ -253,7 +255,7 @@ typedef union sock_addr { #ifdef HAVE_NETPACKET_PACKET_H struct sockaddr_ll ll; #endif -#ifdef HAVE_LINUX_CAN_H +#if defined(HAVE_LINUX_CAN_H) || defined(HAVE_NETCAN_CAN_H) struct sockaddr_can can; #endif #ifdef HAVE_SYS_KERN_CONTROL_H diff --git a/configure b/configure index 3c2a9cf0a249dd..16284a48190dda 100755 --- a/configure +++ b/configure @@ -8782,7 +8782,8 @@ done # On Linux, can.h, can/bcm.h, can/j1939.h, can/raw.h require sys/socket.h -for ac_header in linux/can.h linux/can/bcm.h linux/can/j1939.h linux/can/raw.h +# On NetBSD, netcan/can.h requires sys/socket.h +for ac_header in linux/can.h linux/can/bcm.h linux/can/j1939.h linux/can/raw.h netcan/can.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" " diff --git a/configure.ac b/configure.ac index fa5e63cf5c3f98..6114b8a79ed507 100644 --- a/configure.ac +++ b/configure.ac @@ -2306,7 +2306,8 @@ AC_CHECK_HEADERS(linux/vm_sockets.h,,,[ ]) # On Linux, can.h, can/bcm.h, can/j1939.h, can/raw.h require sys/socket.h -AC_CHECK_HEADERS(linux/can.h linux/can/bcm.h linux/can/j1939.h linux/can/raw.h,,,[ +# On NetBSD, netcan/can.h requires sys/socket.h +AC_CHECK_HEADERS(linux/can.h linux/can/bcm.h linux/can/j1939.h linux/can/raw.h netcan/can.h,,,[ #ifdef HAVE_SYS_SOCKET_H #include #endif diff --git a/pyconfig.h.in b/pyconfig.h.in index efad243d0af8aa..88f95f0bca5e25 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -769,6 +769,9 @@ /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_NDIR_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETCAN_CAN_H + /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_IN_H From 41c4574422f48c4ae40a0ba63142c29f1c886545 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Sun, 12 Dec 2021 00:49:46 +0100 Subject: [PATCH 2/8] Fix unportable test(1) operator in configure script. --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 16284a48190dda..07f77e2780f2e9 100755 --- a/configure +++ b/configure @@ -10290,7 +10290,7 @@ then # small for the default recursion limit. Increase the stack size # to ensure that tests don't crash stack_size="1000000" # 16 MB - if test "$with_ubsan" == "yes" + if test "$with_ubsan" = "yes" then # Undefined behavior sanitizer requires an even deeper stack stack_size="4000000" # 64 MB diff --git a/configure.ac b/configure.ac index 6114b8a79ed507..339b5e73a76971 100644 --- a/configure.ac +++ b/configure.ac @@ -2847,7 +2847,7 @@ then # small for the default recursion limit. Increase the stack size # to ensure that tests don't crash stack_size="1000000" # 16 MB - if test "$with_ubsan" == "yes" + if test "$with_ubsan" = "yes" then # Undefined behavior sanitizer requires an even deeper stack stack_size="4000000" # 64 MB From c2ac8c10eef9558db65a54824c7033c17c7a4180 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Sat, 8 Jan 2022 22:39:56 +0100 Subject: [PATCH 3/8] Revert "Fix unportable test(1) operator in configure script." This reverts commit 41c4574422f48c4ae40a0ba63142c29f1c886545. --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 07f77e2780f2e9..16284a48190dda 100755 --- a/configure +++ b/configure @@ -10290,7 +10290,7 @@ then # small for the default recursion limit. Increase the stack size # to ensure that tests don't crash stack_size="1000000" # 16 MB - if test "$with_ubsan" = "yes" + if test "$with_ubsan" == "yes" then # Undefined behavior sanitizer requires an even deeper stack stack_size="4000000" # 64 MB diff --git a/configure.ac b/configure.ac index 339b5e73a76971..6114b8a79ed507 100644 --- a/configure.ac +++ b/configure.ac @@ -2847,7 +2847,7 @@ then # small for the default recursion limit. Increase the stack size # to ensure that tests don't crash stack_size="1000000" # 16 MB - if test "$with_ubsan" = "yes" + if test "$with_ubsan" == "yes" then # Undefined behavior sanitizer requires an even deeper stack stack_size="4000000" # 64 MB From a63be0e9ad3f4bcb66a51b82182d8129891cea2d Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Thu, 13 Jan 2022 17:54:58 +0100 Subject: [PATCH 4/8] Merge Linux and NetBSD cases. --- Modules/socketmodule.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index aff07f74b14282..71cb3b69168481 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -7698,7 +7698,7 @@ PyInit__socket(void) PyModule_AddIntMacro(m, SOL_CAN_RAW); PyModule_AddIntMacro(m, CAN_RAW); #endif -#ifdef HAVE_LINUX_CAN_H +#if defined(HAVE_LINUX_CAN_H) || defined(HAVE_NETCAN_CAN_H) PyModule_AddIntMacro(m, CAN_EFF_FLAG); PyModule_AddIntMacro(m, CAN_RTR_FLAG); PyModule_AddIntMacro(m, CAN_ERR_FLAG); @@ -7713,9 +7713,11 @@ PyInit__socket(void) PyModule_AddIntMacro(m, CAN_J1939); #endif #endif -#ifdef HAVE_LINUX_CAN_RAW_H +#if defined(HAVE_LINUX_CAN_RAW_H) || defined(HAVE_NETCAN_CAN_H) PyModule_AddIntMacro(m, CAN_RAW_FILTER); +#if defined(CAN_RAW_ERR_FILTER) PyModule_AddIntMacro(m, CAN_RAW_ERR_FILTER); +#endif PyModule_AddIntMacro(m, CAN_RAW_LOOPBACK); PyModule_AddIntMacro(m, CAN_RAW_RECV_OWN_MSGS); #endif @@ -7790,20 +7792,6 @@ PyInit__socket(void) PyModule_AddIntMacro(m, J1939_FILTER_MAX); #endif -#ifdef HAVE_NETCAN_CAN_H - PyModule_AddIntMacro(m, CAN_EFF_FLAG); - PyModule_AddIntMacro(m, CAN_RTR_FLAG); - PyModule_AddIntMacro(m, CAN_ERR_FLAG); - - PyModule_AddIntMacro(m, CAN_SFF_MASK); - PyModule_AddIntMacro(m, CAN_EFF_MASK); - PyModule_AddIntMacro(m, CAN_ERR_MASK); - - PyModule_AddIntMacro(m, CAN_RAW_FILTER); - /* PyModule_AddIntMacro(m, CAN_RAW_ERR_FILTER); */ - PyModule_AddIntMacro(m, CAN_RAW_LOOPBACK); - PyModule_AddIntMacro(m, CAN_RAW_RECV_OWN_MSGS); -#endif #ifdef SOL_RDS PyModule_AddIntMacro(m, SOL_RDS); #endif From c4441ceaa563da14ee05d0c942eb2764a70f9b25 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Thu, 13 Jan 2022 17:55:13 +0100 Subject: [PATCH 5/8] End sentence with dot. --- .../Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst b/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst index ebcd568abbca71..da2ce12fec15d1 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst @@ -1 +1 @@ -Add CAN Socket support for NetBSD +Add CAN Socket support for NetBSD. From 87f6f791b26951f2df3eccf0e84fd2d6eae4a080 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Thu, 13 Jan 2022 17:55:23 +0100 Subject: [PATCH 6/8] Update socket documentation about NetBSD support. --- Doc/library/socket.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index d6edc057f5e9cc..679631a7390928 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -396,10 +396,13 @@ Constants Many constants of these forms, documented in the Linux documentation, are also defined in the socket module. - .. availability:: Linux >= 2.6.25. + .. availability:: Linux >= 2.6.25, NetBSD >= 8. .. versionadded:: 3.3 + .. versionchanged:: 3.11 + NetBSD support was added. + .. data:: CAN_BCM CAN_BCM_* From 0a2e2736a2596e34e20a8103f92e2c4abf4e57cf Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 18 Jan 2022 23:51:09 +0100 Subject: [PATCH 7/8] ifdef vs. if defined consistency --- Modules/socketmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 71cb3b69168481..9f4edceffbb555 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -7715,7 +7715,7 @@ PyInit__socket(void) #endif #if defined(HAVE_LINUX_CAN_RAW_H) || defined(HAVE_NETCAN_CAN_H) PyModule_AddIntMacro(m, CAN_RAW_FILTER); -#if defined(CAN_RAW_ERR_FILTER) +#ifdef CAN_RAW_ERR_FILTER PyModule_AddIntMacro(m, CAN_RAW_ERR_FILTER); #endif PyModule_AddIntMacro(m, CAN_RAW_LOOPBACK); From 921d0a351498cb619046ea6c12c5f63868bc1b70 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 18 Jan 2022 23:53:19 +0100 Subject: [PATCH 8/8] Add Whatsnew entry for NetBSD support in socket module --- Doc/whatsnew/3.11.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8d1f4eba36eb24..0809018abbf84e 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -251,6 +251,13 @@ os (Contributed by Dong-hee Na in :issue:`44611`.) +socket +------ + +* Add CAN Socket support for NetBSD. + (Contributed by Thomas Klausner in :issue:`30512`.) + + sqlite3 -------