Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/sys Pull up following revision(s) (requested by kamil...



details:   https://anonhg.NetBSD.org/src/rev/08153e790ec1
branches:  netbsd-9
changeset: 458137:08153e790ec1
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Aug 06 16:22:04 2019 +0000

description:
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@.

diffstat:

 sys/sys/event.h |  24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r b70ee51abbc6 -r 08153e790ec1 sys/sys/event.h
--- a/sys/sys/event.h   Tue Aug 06 16:20:19 2019 +0000
+++ b/sys/sys/event.h   Tue Aug 06 16:22:04 2019 +0000
@@ -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 <jlemon%FreeBSD.org@localhost>
@@ -55,10 +55,6 @@
        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 @@
        _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 */



Home | Main Index | Thread Index | Old Index