Module Name:    src
Committed By:   martin
Date:           Tue Aug  6 16:22:04 UTC 2019

Modified Files:
        src/sys/sys [netbsd-9]: event.h

Log Message:
Pull up following revision(s) (requested by kamil in ticket #22):

        sys/sys/event.h: revision 1.33

Make EV_SET() casts compatible with the C++ code

EV_SET() handles cast that are expected to work with alternative
kqueue/kevent implementations that take arguments in different types.

Unfortunately void* -> intptr_t cast cannot be done with
static_cast<intptr_t>() as it needs reinterpret_cast<intptr_t>().

Just switching to reinterpret_cast<intptr_t>() is still not sufficient as=
it does not handle NULL argument without a compiler error/warning.

Add a compatibility function for the C++ case of _EV_SET() that accepts
the udata argument in the form of void* and performs clean
reinterpret_cast<>() internally.

There is no change for C users.

Tested by <nia>

Proposed on tech-userlevel@.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.32.8.1 src/sys/sys/event.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/event.h
diff -u src/sys/sys/event.h:1.32 src/sys/sys/event.h:1.32.8.1
--- src/sys/sys/event.h:1.32	Tue Jan  9 03:31:13 2018
+++ src/sys/sys/event.h	Tue Aug  6 16:22:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: event.h,v 1.32 2018/01/09 03:31:13 christos Exp $	*/
+/*	$NetBSD: event.h,v 1.32.8.1 2019/08/06 16:22:04 martin Exp $	*/
 
 /*-
  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jle...@freebsd.org>
@@ -55,10 +55,6 @@ struct kevent {
 	intptr_t	udata;		/* opaque user data identifier */
 };
 
-#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)))
-
 static __inline void
 _EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
     uint32_t _flags, uint32_t _fflags, int64_t _data, intptr_t _udata)
@@ -71,6 +67,24 @@ _EV_SET(struct kevent *_kevp, uintptr_t 
 	_kevp->udata = _udata;
 }
 
+#ifdef __cplusplus
+#define EV_SET(kevp, ident, filter, flags, fflags, data, udata)	\
+    _EV_SET((kevp), __CAST(uintptr_t, (ident)), (filter), (flags), \
+    (fflags), (data), (udata))
+
+static __inline void
+_EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
+    uint32_t _flags, uint32_t _fflags, int64_t _data, void *_udata)
+{
+	_EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+	    reinterpret_cast<intptr_t>(_udata));
+}
+#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)))
+#endif
+
 /* actions */
 #define	EV_ADD		0x0001U		/* add event to kq (implies ENABLE) */
 #define	EV_DELETE	0x0002U		/* delete event from kq */

Reply via email to