Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Still does not compile... ☹️

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Jan 24, 2024
1 parent a24969d commit e0f779a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
2 changes: 2 additions & 0 deletions compat/regex/regcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,7 @@ 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 @@ -2740,6 +2741,7 @@ 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
30 changes: 24 additions & 6 deletions compat/regex/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@

#define __STDC_WANT_IEC_60559_BFP_EXT__

#ifndef _LIBC
# include <libc-config.h>
#include <stdint.h>
#include <stdbool.h>

# if __GNUC_PREREQ (4, 6)
# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
# pragma GCC diagnostic ignored "-Wvla"
# endif
#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))

/* Make sure no one compiles this code with a C++ compiler. */
#if defined __cplusplus && defined _LIBC
# error "This is C code, use a C compiler"
Expand Down
20 changes: 0 additions & 20 deletions compat/regex/regex_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,9 @@
#include <stdio.h>
#include <string.h>

#include <langinfo.h>
#include <locale.h>
#include <wchar.h>
#include <wctype.h>
#include <stdckdint.h>
#include <stdint.h>

#ifndef _LIBC
# include <dynarray.h>
#endif

#include <intprops.h>
#include <verify.h>

#if defined DEBUG && DEBUG != 0
# include <assert.h>
Expand Down Expand Up @@ -818,14 +808,4 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
return 1;
}

#ifdef _LIBC
# if __glibc_has_attribute (__fallthrough__)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
# endif
#else
# include "attribute.h"
#endif

#endif /* _REGEX_INTERNAL_H */
7 changes: 5 additions & 2 deletions compat/regex/regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len);

int
regexec (const regex_t *__restrict preg, const char *__restrict string,
size_t nmatch, regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags)
size_t nmatch, regmatch_t *pmatch, int eflags)

Check failure on line 188 in compat/regex/regexec.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

compat/regex/regexec.c:188:37: argument 4 of type 'regmatch_t *' declared as a pointer [-Werror=vla-parameter]

Check failure on line 188 in compat/regex/regexec.c

View workflow job for this annotation

GitHub Actions / win build

compat/regex/regexec.c:188:37: argument 4 of type 'regmatch_t *' declared as a pointer [-Werror=vla-parameter]
{
reg_errcode_t err;
Idx start, length;
Expand Down Expand Up @@ -1214,6 +1214,7 @@ 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 @@ -1242,6 +1243,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
}
}
return dest_node;
}
}
else
{
Expand Down Expand Up @@ -1338,6 +1340,7 @@ 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 @@ -1347,13 +1350,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 e0f779a

Please sign in to comment.