Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dscho committed Jan 24, 2024
1 parent 6f2425c commit 290aab3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions compat/regex/regcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
Expand Down
27 changes: 4 additions & 23 deletions compat/regex/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,13 @@

#define __STDC_WANT_IEC_60559_BFP_EXT__

#include <stdint.h>
#include <stdbool.h>

#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 <stdint.h>
#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
Expand Down
3 changes: 1 addition & 2 deletions compat/regex/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions compat/regex/regex_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 812 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:812:9: '__glibc_unlikely' macro redefined [-Werror,-Wmacro-redefined]
#define __glibc_likely(x) (x)

Check failure on line 813 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:813:9: '__glibc_likely' macro redefined [-Werror,-Wmacro-redefined]
#define libc_hidden_def(name)
#define libc_hidden_proto(name)
#define weak_alias(name, aliasname)
#define __always_inline inline

Check failure on line 817 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:817:9: '__always_inline' macro redefined [-Werror,-Wmacro-redefined]
#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))

Check failure on line 826 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:826:9: '__attribute_warn_unused_result__' macro redefined [-Werror,-Wmacro-redefined]
#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)

Check failure on line 858 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:858:9: '__attribute_nonnull__' macro redefined [-Werror,-Wmacro-redefined]
#define __attribute_maybe_unused__

Check failure on line 859 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:859:9: '__attribute_maybe_unused__' macro redefined [-Werror,-Wmacro-redefined]
#define __attribute_noinline__

Check failure on line 860 in compat/regex/regex_internal.h

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

compat/regex/regex_internal.h:860:9: '__attribute_noinline__' macro redefined [-Werror,-Wmacro-redefined]

/* True if the real type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))

#endif /* _REGEX_INTERNAL_H */
5 changes: 1 addition & 4 deletions compat/regex/regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -1243,7 +1242,6 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
}
}
return dest_node;
}
}
else
{
Expand Down Expand Up @@ -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);
Expand All @@ -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 <malloc/dynarray-skeleton.c>

/* Set the positions where the subexpressions are starts/ends to registers
PMATCH.
Expand Down

0 comments on commit 290aab3

Please sign in to comment.