From 36e37d2611d37e72c0d671b7c5a2922e4fdac825 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 26 Jan 2023 09:42:28 +0100 Subject: [PATCH] misc: add re prefix (#659) * re_is_aligned: add backwards compat --- include/re_mbuf.h | 4 ++-- include/re_types.h | 21 +++++++++------------ src/bfcp/attr.c | 2 +- src/dns/client.c | 4 ++-- src/fmt/pl.c | 4 ++-- src/fmt/regex.c | 2 +- src/fmt/time.c | 10 +++++----- src/http/client.c | 2 +- src/mem/mem.c | 4 ++-- src/rtmp/conn.c | 2 +- src/sdp/media.c | 6 +++--- src/stun/attr.c | 4 ++-- 12 files changed, 31 insertions(+), 34 deletions(-) diff --git a/include/re_mbuf.h b/include/re_mbuf.h index 73b6290fd..505a983b9 100644 --- a/include/re_mbuf.h +++ b/include/re_mbuf.h @@ -16,12 +16,12 @@ /** Check that mbuf position does not exceed end */ #define MBUF_CHECK_POS(mb) \ if ((mb) && (mb)->pos > (mb)->end) { \ - BREAKPOINT; \ + RE_BREAKPOINT; \ } /** Check that mbuf end does not exceed size */ #define MBUF_CHECK_END(mb) \ if ((mb) && (mb)->end > (mb)->size) { \ - BREAKPOINT; \ + RE_BREAKPOINT; \ } #else #define MBUF_CHECK_POS(mb) diff --git a/include/re_types.h b/include/re_types.h index c30ddc96e..d83fd2609 100644 --- a/include/re_types.h +++ b/include/re_types.h @@ -50,10 +50,11 @@ typedef SSIZE_T ssize_t; /** Align a value to the boundary of mask */ -#define ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) +#define RE_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) /** Check alignment of pointer (p) and byte count (c) **/ -#define is_aligned(p, c) (((uintptr_t)(const void *)(p)) % (c) == 0) +#define re_is_aligned(p, c) (((uintptr_t)(const void *)(p)) % (c) == 0) +#define is_aligned re_is_aligned /** Get the minimal value */ #undef MIN @@ -77,11 +78,15 @@ typedef SSIZE_T ssize_t; /** Defines a soft breakpoint */ #if (defined(__i386__) || defined(__x86_64__)) -#define BREAKPOINT __asm__("int $0x03") +#define RE_BREAKPOINT __asm__("int $0x03") #else -#define BREAKPOINT +#define RE_BREAKPOINT #endif +/* Backwards compat */ +#define BREAKPOINT RE_BREAKPOINT + + /* Error return/goto debug helpers */ #ifdef TRACE_ERR #define PRINT_TRACE_ERR(err) \ @@ -235,14 +240,6 @@ typedef SSIZE_T ssize_t; #define EKEYREJECTED 129 #endif -/* - * Any C compiler conforming to C99 or later MUST support __func__ - */ -#if __STDC_VERSION__ >= 199901L -#define __REFUNC__ (const char *)__func__ -#else -#define __REFUNC__ __FUNCTION__ -#endif /* * Give the compiler a hint which branch is "likely" or "unlikely" (inspired diff --git a/src/bfcp/attr.c b/src/bfcp/attr.c index ffc5ef387..5072ae4b0 100644 --- a/src/bfcp/attr.c +++ b/src/bfcp/attr.c @@ -363,7 +363,7 @@ static int attr_decode(struct bfcp_attr **attrp, struct mbuf *mb, if (!attr->mand) break; - if (uma && uma->typec < ARRAY_SIZE(uma->typev)) + if (uma && uma->typec < RE_ARRAY_SIZE(uma->typev)) uma->typev[uma->typec++] = attr->type<<1; break; } diff --git a/src/dns/client.c b/src/dns/client.c index a5cf0777d..34e03737e 100644 --- a/src/dns/client.c +++ b/src/dns/client.c @@ -286,7 +286,7 @@ static int reply_recv(struct dnsc *dnsc, struct mbuf *mb) nv[2] = dq.hdr.nadd; DEBUG_INFO("--- ANSWER SECTION id: %d ---\n", q->id); - for (uint32_t i = 0; i < ARRAY_SIZE(nv); i++) { + for (uint32_t i = 0; i < RE_ARRAY_SIZE(nv); i++) { uint32_t l = nv[i]; if (l > RR_MAX) { @@ -1276,7 +1276,7 @@ int dnsc_srv_set(struct dnsc *dnsc, const struct sa *srvv, uint32_t srvc) if (!dnsc) return EINVAL; - dnsc->srvc = min((uint32_t)ARRAY_SIZE(dnsc->srvv), srvc); + dnsc->srvc = min((uint32_t)RE_ARRAY_SIZE(dnsc->srvv), srvc); if (srvv) { for (i=0; isrvc; i++) diff --git a/src/fmt/pl.c b/src/fmt/pl.c index 94ce6d272..e1e11a7f1 100644 --- a/src/fmt/pl.c +++ b/src/fmt/pl.c @@ -337,14 +337,14 @@ int pl_bool(bool *val, const struct pl *pl) if (!val || !pl) return EINVAL; - for (i = 0; i < ARRAY_SIZE(tval); ++i) { + for (i = 0; i < RE_ARRAY_SIZE(tval); ++i) { if (!pl_strcasecmp(pl, tval[i])) { *val = true; err = 0; } } - for (i = 0; i < ARRAY_SIZE(fval); ++i) { + for (i = 0; i < RE_ARRAY_SIZE(fval); ++i) { if (!pl_strcasecmp(pl, fval[i])) { *val = false; err = 0; diff --git a/src/fmt/regex.c b/src/fmt/regex.c index d2381853d..f177b8bdb 100644 --- a/src/fmt/regex.c +++ b/src/fmt/regex.c @@ -238,7 +238,7 @@ int re_regex(const char *ptr, size_t len, const char *expr, ...) } chr: - if (n >= ARRAY_SIZE(chrv)) + if (n >= RE_ARRAY_SIZE(chrv)) break; chrv[n].max = tolower(*ep); diff --git a/src/fmt/time.c b/src/fmt/time.c index 5baa8b07b..54778c134 100644 --- a/src/fmt/time.c +++ b/src/fmt/time.c @@ -49,11 +49,11 @@ int fmt_gmtime(struct re_printf *pf, void *ts) #endif return re_hprintf(pf, "%s, %02u %s %u %02u:%02u:%02u GMT", - dayv[min((unsigned)tm.tm_wday, ARRAY_SIZE(dayv)-1)], - tm.tm_mday, - monv[min((unsigned)tm.tm_mon, ARRAY_SIZE(monv)-1)], - tm.tm_year + 1900, - tm.tm_hour, tm.tm_min, tm.tm_sec); + dayv[min((unsigned)tm.tm_wday, RE_ARRAY_SIZE(dayv)-1)], + tm.tm_mday, + monv[min((unsigned)tm.tm_mon, RE_ARRAY_SIZE(monv)-1)], + tm.tm_year + 1900, + tm.tm_hour, tm.tm_min, tm.tm_sec); } diff --git a/src/http/client.c b/src/http/client.c index 554136a65..856158e64 100644 --- a/src/http/client.c +++ b/src/http/client.c @@ -673,7 +673,7 @@ static bool rr_handler(struct dnsrr *rr, void *arg) { struct http_req *req = arg; - if (req->srvc >= ARRAY_SIZE(req->srvv)) + if (req->srvc >= RE_ARRAY_SIZE(req->srvv)) return true; switch (rr->type) { diff --git a/src/mem/mem.c b/src/mem/mem.c index 945247f6c..0bf908bab 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -99,8 +99,8 @@ static inline void mem_unlock(void) #define MAGIC_CHECK(_m) \ if (mem_magic != (_m)->magic) { \ DEBUG_WARNING("%s: magic check failed 0x%08zx (%p)\n", \ - __REFUNC__, (_m)->magic, get_mem_data((_m))); \ - BREAKPOINT; \ + __func__, (_m)->magic, get_mem_data((_m))); \ + RE_BREAKPOINT; \ } #else #define STAT_ALLOC(_m, _size) (_m)->size = (uint32_t)(_size); diff --git a/src/rtmp/conn.c b/src/rtmp/conn.c index 15fbf4a94..50a822e80 100644 --- a/src/rtmp/conn.c +++ b/src/rtmp/conn.c @@ -723,7 +723,7 @@ static bool rr_handler(struct dnsrr *rr, void *arg) { struct rtmp_conn *conn = arg; - if (conn->srvc >= ARRAY_SIZE(conn->srvv)) + if (conn->srvc >= RE_ARRAY_SIZE(conn->srvv)) return true; switch (rr->type) { diff --git a/src/sdp/media.c b/src/sdp/media.c index 8c64eb00f..d5ec58517 100644 --- a/src/sdp/media.c +++ b/src/sdp/media.c @@ -32,7 +32,7 @@ static void destructor(void *arg) return; } - for (i=0; iprotov); i++) + for (i=0; iprotov); i++) mem_deref(m->protov[i]); list_unlink(&m->le); @@ -196,7 +196,7 @@ bool sdp_media_proto_cmp(struct sdp_media *m, const struct pl *proto, if (!pl_strcmp(proto, m->proto)) return true; - for (i=0; iprotov); i++) { + for (i=0; iprotov); i++) { if (!m->protov[i] || pl_strcmp(proto, m->protov[i])) continue; @@ -364,7 +364,7 @@ int sdp_media_set_alt_protos(struct sdp_media *m, unsigned protoc, ...) va_start(ap, protoc); - for (i=0; iprotov); i++) { + for (i=0; iprotov); i++) { m->protov[i] = mem_deref(m->protov[i]); diff --git a/src/stun/attr.c b/src/stun/attr.c index ce244bd83..8f981fef2 100644 --- a/src/stun/attr.c +++ b/src/stun/attr.c @@ -253,7 +253,7 @@ int stun_attr_decode(struct stun_attr **attrp, struct mbuf *mb, for (i=0; i= ARRAY_SIZE(attr->v.unknown_attr.typev)) + if (i >= RE_ARRAY_SIZE(attr->v.unknown_attr.typev)) continue; attr->v.unknown_attr.typev[i] = type; @@ -325,7 +325,7 @@ int stun_attr_decode(struct stun_attr **attrp, struct mbuf *mb, if (attr->type >= 0x8000) break; - if (ua && ua->typec < ARRAY_SIZE(ua->typev)) + if (ua && ua->typec < RE_ARRAY_SIZE(ua->typev)) ua->typev[ua->typec++] = attr->type; break; }