Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys Make EV_SET() casts compatible with the C++ code
details: https://anonhg.NetBSD.org/src/rev/f1bd5a297628
branches: trunk
changeset: 453286:f1bd5a297628
user: kamil <kamil%NetBSD.org@localhost>
date: Tue Aug 06 11:21:59 2019 +0000
description:
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 cf9bc6e48700 -r f1bd5a297628 sys/sys/event.h
--- a/sys/sys/event.h Tue Aug 06 10:45:14 2019 +0000
+++ b/sys/sys/event.h Tue Aug 06 11:21:59 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.33 2019/08/06 11:21:59 kamil 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