From 745d0dd719bf298838ecdec46b703cc34a55ba75 Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 3 Jan 2021 10:50:02 +0000 Subject: 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 --- lib/libc/regex/regex2.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lib/libc') 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 -- cgit v1.2.3-59-g8ed1b