[Python-checkins] bpo-30512: Add CAN Socket support for NetBSD (GH-30066)

serhiy-storchaka webhook-mailer at python.org
Fri Jan 21 02:44:21 EST 2022


https://github.com/python/cpython/commit/40fcd16889028bd3cd2289e0f8a2af43f17a5824
commit: 40fcd16889028bd3cd2289e0f8a2af43f17a5824
branch: main
author: Thomas Klausner <tk at giga.or.at>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022-01-21T09:44:05+02:00
summary:

bpo-30512: Add CAN Socket support for NetBSD (GH-30066)

files:
A Misc/NEWS.d/next/Core and Builtins/2021-12-12-00-49-19.bpo-30512.nU9E9V.rst
M Doc/library/socket.rst
M Doc/whatsnew/3.11.rst
M Modules/socketmodule.c
M Modules/socketmodule.h
M configure
M configure.ac
M pyconfig.h.in

diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index d6edc057f5e9c..679631a739092 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_*
 
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 5563e3d84de6d..ad421b16fbac3 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -264,6 +264,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
 -------
 
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 0000000000000..da2ce12fec15d
--- /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 0e275639967c2..1c8ef1eb3b5b3 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -7703,7 +7703,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);
@@ -7718,9 +7718,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);
+#ifdef 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
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index aea599f0ee6c8..db26c046c3637 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -129,6 +129,8 @@ typedef int socklen_t;
 
 #ifdef HAVE_LINUX_CAN_H
 # include <linux/can.h>
+#elif defined(HAVE_NETCAN_CAN_H)
+# include <netcan/can.h>
 #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 402e626b6992d..f40d425371dc6 100755
--- a/configure
+++ b/configure
@@ -8940,7 +8940,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 9c9a338576736..8d140427de48d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2411,7 +2411,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 <sys/socket.h>
 #endif
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 21822197708d3..a779ffadf200f 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -772,6 +772,9 @@
 /* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
 #undef HAVE_NDIR_H
 
+/* Define to 1 if you have the <netcan/can.h> header file. */
+#undef HAVE_NETCAN_CAN_H
+
 /* Define to 1 if you have the <netinet/in.h> header file. */
 #undef HAVE_NETINET_IN_H
 



More information about the Python-checkins mailing list