Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Handle more corner cases in sys/event.h for C++ EV_S...



details:   https://anonhg.NetBSD.org/src/rev/18cb7953fceb
branches:  trunk
changeset: 964642:18cb7953fceb
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Aug 10 15:02:03 2019 +0000

description:
Handle more corner cases in sys/event.h for C++ EV_SET()

Handle the udata argument as Plain-Old-Data types separately.

 - int, long int, long long int
 - unsigned int, unsigned long int, unsigned long long int
 - void *

This approach handles each of the POD types separately on purpose as
intermediate types such as intptr_t can be either int or long (even long
long) and handling them is not portable.

This approach is compatibile with C++98 and newer.

Fixes i386 usage.

diffstat:

 sys/sys/event.h |  94 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 72 insertions(+), 22 deletions(-)

diffs (115 lines):

diff -r 0858a2bb5477 -r 18cb7953fceb sys/sys/event.h
--- a/sys/sys/event.h   Sat Aug 10 12:50:36 2019 +0000
+++ b/sys/sys/event.h   Sat Aug 10 15:02:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: event.h,v 1.34 2019/08/10 11:20:50 kamil Exp $ */
+/*     $NetBSD: event.h,v 1.35 2019/08/10 15:02:03 kamil Exp $ */
 
 /*-
  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon%FreeBSD.org@localhost>
@@ -55,6 +55,77 @@
        intptr_t        udata;          /* opaque user data identifier */
 };
 
+#ifdef __cplusplus
+#define EV_SET(kevp, ident, filter, flags, fflags, data, udata)        \
+    _EV_SET((kevp), __CAST(uintptr_t, (ident)), (filter), (flags), \
+    (fflags), (data), (udata))
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion-null"
+
+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)
+{
+       _kevp->ident = _ident;
+       _kevp->filter = _filter;
+       _kevp->flags = _flags;
+       _kevp->fflags = _fflags;
+       _kevp->data = _data;
+       _kevp->udata = reinterpret_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, int _udata)
+{
+       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+           reinterpret_cast<void *>(static_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, long int _udata)
+{
+       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+           reinterpret_cast<void *>(static_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, long long int _udata)
+{
+       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+           reinterpret_cast<void *>(static_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, unsigned int _udata)
+{
+       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+           reinterpret_cast<void *>(static_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, unsigned long int _udata)
+{
+       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+           reinterpret_cast<void *>(static_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,
+    unsigned long long int _udata)
+{
+       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
+           reinterpret_cast<void *>(static_cast<intptr_t>(_udata)));
+}
+
+#pragma GCC diagnistic pop
+#else
 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)
@@ -67,27 +138,6 @@
        _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));
-}
-
-static __inline void
-_EV_SET(struct kevent *_kevp, uintptr_t _ident, uint32_t _filter,
-    uint32_t _flags, uint32_t _fflags, int64_t _data, int _udata)
-{
-       _EV_SET(_kevp, _ident, _filter, _flags, _fflags, _data,
-           static_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)))



Home | Main Index | Thread Index | Old Index