From be3a711fb099f050bb41806bfd42871ecd32744b Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sat, 12 Jan 2019 20:32:15 +0000 Subject: [PATCH] libre2c_posix: use C-array initializers instead of variadic functions for offset lists. Variadic functions cause subtle toolchain-specific errors because integer literals used to initialize offsets may have different type than the type expected by variadic function (e.g. int vs long). --- re2c/libre2c_posix/test.cpp | 46 +++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/re2c/libre2c_posix/test.cpp b/re2c/libre2c_posix/test.cpp index 02efa262..36c6243f 100644 --- a/re2c/libre2c_posix/test.cpp +++ b/re2c/libre2c_posix/test.cpp @@ -1,11 +1,11 @@ #include -#include #include "src/util/c99_stdint.h" #include "regex.h" -int test(const char *pattern, const char *string, size_t nmatch, ...) +static int test(const char *pattern, const char *string + , size_t nmatch, const regoff_t *submatch) { regex_t re; regmatch_t *pmatch = new regmatch_t[nmatch]; @@ -24,12 +24,9 @@ int test(const char *pattern, const char *string, size_t nmatch, ...) goto end; } - va_list vl; - va_start(vl, nmatch); - for (uint32_t i = 0; i < nmatch; ++i) { - regoff_t so = va_arg(vl, regoff_t); - regoff_t eo = va_arg(vl, regoff_t); + regoff_t so = submatch[2 * i]; + regoff_t eo = submatch[2 * i + 1]; const regmatch_t &have = pmatch[i]; if (so != have.rm_so || eo != have.rm_eo) { @@ -45,7 +42,6 @@ int test(const char *pattern, const char *string, size_t nmatch, ...) } end: - va_end(vl); regfree(&re); delete[] pmatch; @@ -54,13 +50,33 @@ end: int main() { - int err = 0; + int e = 0; + + // poor man's replacement for C++11 initializer lists :) +#define GS static const regoff_t gs[] +#define T1(r,s,a,b) { GS = {a,b}; T(r,s,gs); } +#define T2(r,s,a,b,c,d) { GS = {a,b,c,d}; T(r,s,gs); } +#define T3(r,s,a,b,c,d,e,f) { GS = {a,b,c,d,e,f}; T(r,s,gs); } +#define T4(r,s,a,b,c,d,e,f,g,h) { GS = {a,b,c,d,e,f,g,h}; T(r,s,gs); } +#define T5(r,s,a,b,c,d,e,f,g,h,i,j) { GS = {a,b,c,d,e,f,g,h,i,j}; T(r,s,gs); } +#define T6(r,s,a,b,c,d,e,f,g,h,i,j,k,l) { GS = {a,b,c,d,e,f,g,h,i,j,k,l}; T(r,s,gs); } +#define T(r,s,gs) { \ + e |= test(r,s,sizeof(gs)/sizeof(gs[0])/2,gs); \ +} + + T1("a", "a", 0,1); + T2("(a)", "a", 0,1, 0,1); + T2("(a*)", "aaa", 0,3, 0,3); + T3("(a*)(b*)", "aabb", 0,4, 0,2, 2,4); + T3("(a*)(a*)", "aa", 0,2, 0,2, 2,2); - err |= test("a", "a", 1, 0,1); - err |= test("(a)", "a", 2, 0,1, 0,1); - err |= test("(a*)", "aaa", 2, 0,3, 0,3); - err |= test("(a*)(b*)", "aabb", 3, 0,4, 0,2, 2,4); - err |= test("(a*)(a*)", "aa", 3, 0,2, 0,2, 2,2); +#undef T +#undef T1 +#undef T2 +#undef T3 +#undef T4 +#undef T5 +#undef T6 - return err; + return e; } -- 2.40.0