summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex/regex2.h
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2021-01-03 10:50:02 +0000
committertb <tb@openbsd.org>2021-01-03 10:50:02 +0000
commit745d0dd719bf298838ecdec46b703cc34a55ba75 (patch)
treea3378e921a054ad0b8ef70e5d193b908903d5186 /lib/libc/regex/regex2.h
parentAllocate address space for reposting vga devices using km_alloc(9) rather (diff)
downloadwireguard-openbsd-745d0dd719bf298838ecdec46b703cc34a55ba75.tar.xz
wireguard-openbsd-745d0dd719bf298838ecdec46b703cc34a55ba75.zip
Turn macros into inline functions so that there is no need to document in
comments that they will evaluate their arguments multiple times. From miod, ok millert
Diffstat (limited to 'lib/libc/regex/regex2.h')
-rw-r--r--lib/libc/regex/regex2.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/libc/regex/regex2.h b/lib/libc/regex/regex2.h
index 7f8f73ad842..5a609f4aea8 100644
--- a/lib/libc/regex/regex2.h
+++ b/lib/libc/regex/regex2.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: regex2.h,v 1.10 2020/12/31 17:20:19 millert Exp $ */
+/* $OpenBSD: regex2.h,v 1.11 2021/01/03 10:50:02 tb Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -107,10 +107,26 @@ typedef struct {
uch mask; /* bit within array */
uch hash; /* hash code */
} cset;
-/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
-#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
-#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
+
+static inline void
+CHadd(cset *cs, char c)
+{
+ cs->ptr[(uch)c] |= cs->mask;
+ cs->hash += c;
+}
+
+static inline void
+CHsub(cset *cs, char c)
+{
+ cs->ptr[(uch)c] &= ~cs->mask;
+ cs->hash -= c;
+}
+
+static inline uch
+CHIN(const cset *cs, char c)
+{
+ return cs->ptr[(uch)c] & cs->mask;
+}
/*
* main compiled-expression structure