tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: EV_SET() better C++ compat with alternative implementations



From: Christos Zoulas <christos%zoulas.com@localhost>
Subject: Re: EV_SET() better C++ compat with alternative implementations
Date: Sun, 11 Aug 2019 20:08:56 +0300

> Now you get warnings with -Wold-style-cast (which is the reason for __CAST() in the first place).
>
> christos


In the C++ case, we could use template specialization.  This is quick and dirty,
but something to consider.

Aran

--- /usr/include/sys/event.h	2019-08-09 13:07:39.000000000 -0700
+++ event.h	2019-08-11 10:14:58.638460454 -0700
@@ -36,6 +36,10 @@
 #include <sys/inttypes.h>		/* for uintptr_t */
 #include <sys/null.h>			/* for NULL */

+#ifdef __cplusplus
+#include <cstddef>
+#endif
+
 #define	EVFILT_READ		0U
 #define	EVFILT_WRITE		1U
 #define	EVFILT_AIO		2U	/* attached to aio requests */
@@ -56,7 +60,7 @@
 };

 static __inline void
-_EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
+__EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
     uint32_t _flags, uint32_t _fflags, int64_t _data, intptr_t _udata)
 {
 	_kevp->ident = _ident;
@@ -72,17 +76,32 @@
     _EV_SET((kevp), __CAST(uintptr_t, (ident)), (filter), (flags), \
     (fflags), (data), (udata))

-static __inline void
+template<class T> __inline void
+_EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
+    uint32_t _flags, uint32_t _fflags, int64_t _data, T* _udata)
+{
+        __EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+                 reinterpret_cast<intptr_t>(_udata));
+}
+
+template<class T> __inline void
 _EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
-    uint32_t _flags, uint32_t _fflags, int64_t _data, void *_udata)
+  uint32_t _flags, uint32_t _fflags, int64_t _data, T _udata)
 {
-	_EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
-	    reinterpret_cast<intptr_t>(_udata));
+        __EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data, _udata);
 }
+
+template<>  __inline void
+_EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
+  uint32_t _flags, uint32_t _fflags, int64_t _data, std::nullptr_t _udata)
+{
+        __EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data, 0);
+}
+
 #else
 #define EV_SET(kevp, ident, filter, flags, fflags, data, udata)	\
-    _EV_SET((kevp), __CAST(uintptr_t, (ident)), (filter), (flags), \
-    (fflags), (data), __CAST(intptr_t, (udata)))
+        __EV_SET((kevp), __CAST(uintptr_t, (ident)), (filter), (flags), \
+                (fflags), (data), __CAST(intptr_t, (udata)))
 #endif

 /* actions */

Attachment: pgpGIPwvveqKq.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index