diff --git a/Makefile b/Makefile index 3fe461f8d0f6d1..cc50d381292638 100644 --- a/Makefile +++ b/Makefile @@ -2054,6 +2054,9 @@ endif ifdef NO_REGEX COMPAT_CFLAGS += -Icompat/regex COMPAT_OBJS += compat/regex/regex.o + +compat/regex/%.o: COMPAT_CFLAGS += -Wno-declaration-after-statement -Wno-implicit-fallthrough -Wno-unused-function + else ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS COMPAT_CFLAGS += -DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c index 53325f6468e9a6..29a71d31e444cb 100644 --- a/compat/regex/regcomp.c +++ b/compat/regex/regcomp.c @@ -2675,7 +2675,6 @@ build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, && strlen ((char *) end_elem->opr.name) > 1))) return REG_ECOLLATE; - { unsigned int start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0] @@ -2741,7 +2740,6 @@ build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, if (start_wc <= wc && wc <= end_wc) bitset_set (sbcset, wc); } - } return REG_NOERROR; } diff --git a/compat/regex/regex.c b/compat/regex/regex.c index 191797fc43ea06..4943b0e0e2120d 100644 --- a/compat/regex/regex.c +++ b/compat/regex/regex.c @@ -19,32 +19,13 @@ #define __STDC_WANT_IEC_60559_BFP_EXT__ -#include -#include - #define __USE_GNU #define __STRICT_ANSI__ -#define assume(x) -#define __glibc_unlikely(x) (x) -#define __glibc_likely(x) (x) -#define libc_hidden_def(name) -#define weak_alias(name, aliasname) -#define __always_inline inline -#define nl_langinfo(x) "UTF8" -#define FALLTHROUGH /* fallthru */ -#define uint_fast32_t uint32_t -/* This imitates the `RESULT_MUST_BE_USED` macro in `git-compat-util.h` */ -/* The sentinel attribute is valid from gcc version 4.0 */ -#if defined(__GNUC__) && (__GNUC__ >= 4) -/* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */ -#define __attribute_warn_unused_result__ __attribute__ ((warn_unused_result)) -#else -#define __attribute_warn_unused_result__ -#endif - -/* True if the real type T is signed. */ -#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) +#include +#define bool int +#define true 1 +#define false 0 /* Make sure no one compiles this code with a C++ compiler. */ #if defined __cplusplus && defined _LIBC diff --git a/compat/regex/regex.h b/compat/regex/regex.h index 469db298ba5ed8..a98e857a73456e 100644 --- a/compat/regex/regex.h +++ b/compat/regex/regex.h @@ -683,8 +683,7 @@ extern int regcomp (regex_t *_Restrict_ __preg, extern int regexec (const regex_t *_Restrict_ __preg, const char *_Restrict_ __String, size_t __nmatch, - regmatch_t __pmatch[_Restrict_arr_ - _REGEX_NELTS (__nmatch)], + regmatch_t *__pmatch, int __eflags); extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h index 9544183637eb05..126c0f3f60bc7e 100644 --- a/compat/regex/regex_internal.h +++ b/compat/regex/regex_internal.h @@ -808,4 +808,58 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) return 1; } +#define assume(x) +#define __glibc_unlikely(x) (x) +#define __glibc_likely(x) (x) +#define libc_hidden_def(name) +#define libc_hidden_proto(name) +#define weak_alias(name, aliasname) +#define __always_inline inline +#define nl_langinfo(x) "UTF8" +#define FALLTHROUGH /* fallthrough */ +#define uint_fast32_t uint32_t + +/* This imitates the `RESULT_MUST_BE_USED` macro in `git-compat-util.h` */ +/* The sentinel attribute is valid from gcc version 4.0 */ +#if defined(__GNUC__) && (__GNUC__ >= 4) +/* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */ +#define __attribute_warn_unused_result__ __attribute__ ((warn_unused_result)) +#else +#define __attribute_warn_unused_result__ +#endif + +#if defined(__HP_cc) && (__HP_cc >= 61000) +#define _Noreturn __attribute__((noreturn)) +#define _Noreturn_PTR +#elif defined(__GNUC__) && !defined(NO_NORETURN) +#define _Noreturn __attribute__((__noreturn__)) +#define _Noreturn_PTR __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define _Noreturn __declspec(noreturn) +#define _Noreturn_PTR +#else +#define _Noreturn +#define _Noreturn_PTR +#ifndef __GNUC__ +#ifndef __attribute__ +#define __attribute__(x) +#endif +#endif +#endif + +# ifdef __GNUC__ +# define ckd_add(R, A, B) __builtin_add_overflow ((A), (B), (R)) +# define ckd_sub(R, A, B) __builtin_sub_overflow ((A), (B), (R)) +# define ckd_mul(R, A, B) __builtin_mul_overflow ((A), (B), (R)) +# else +# error "we need a compiler extension for this" +# endif + +#define __attribute_nonnull__(x) +#define __attribute_maybe_unused__ +#define __attribute_noinline__ + +/* True if the real type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + #endif /* _REGEX_INTERNAL_H */ diff --git a/compat/regex/regexec.c b/compat/regex/regexec.c index 0e461b6f226fe0..0909625500e8cb 100644 --- a/compat/regex/regexec.c +++ b/compat/regex/regexec.c @@ -1214,7 +1214,6 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, return -2; } - { /* Pick a valid destination, or return -1 if none is found. */ Idx dest_node = -1; for (Idx i = 0; i < edests->nelem; i++) @@ -1243,7 +1242,6 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, } } return dest_node; - } } else { @@ -1340,7 +1338,6 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, { if (fs == NULL || fs->num == 0) return -1; - { Idx num = --fs->num; *pidx = fs->stack[num].idx; memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs); @@ -1350,13 +1347,13 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, *eps_via_nodes = fs->stack[num].eps_via_nodes; DEBUG_ASSERT (0 <= fs->stack[num].node); return fs->stack[num].node; - } } #define DYNARRAY_STRUCT regmatch_list #define DYNARRAY_ELEMENT regmatch_t #define DYNARRAY_PREFIX regmatch_list_ +#include /* Set the positions where the subexpressions are starts/ends to registers PMATCH.