svn commit: r224795 - in user/gabor/tre-integration:
contrib/tre/lib include
Gabor Kovesdan
gabor at FreeBSD.org
Fri Aug 12 14:07:18 UTC 2011
Author: gabor
Date: Fri Aug 12 14:07:18 2011
New Revision: 224795
URL: http://svn.freebsd.org/changeset/base/224795
Log:
- Use malloc() instead of alloca()
- Introduce REG_GNU for GNU extensions
- Only process GNU-specific word-boundary notation if REG_GNU is specified
- Fix a compilation error
Modified:
user/gabor/tre-integration/contrib/tre/lib/fastmatch.c
user/gabor/tre-integration/contrib/tre/lib/tre.h
user/gabor/tre-integration/include/regex.h
Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Fri Aug 12 11:43:56 2011 (r224794)
+++ user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Fri Aug 12 14:07:18 2011 (r224795)
@@ -259,10 +259,13 @@ static int fastcmp(const void *, const v
{ \
if (fg->icase) \
{ \
- wp = alloca(plen * sizeof(tre_char_t)); \
+ wp = xmalloc(plen * sizeof(tre_char_t)); \
+ if (wp == NULL) \
+ return REG_ESPACE; \
for (int i = 0; i < plen; i++) \
wp[i] = towlower(pat[i]); \
_CALC_BMGS(arr, wp, plen); \
+ free(wp); \
} \
else \
_CALC_BMGS(arr, pat, plen); \
@@ -271,10 +274,13 @@ static int fastcmp(const void *, const v
{ \
if (fg->icase) \
{ \
- p = alloca(plen); \
+ p = xmalloc(plen); \
+ if (p == NULL) \
+ return REG_ESPACE; \
for (int i = 0; i < plen; i++) \
p[i] = tolower(pat[i]); \
_CALC_BMGS(arr, p, plen); \
+ free(p); \
} \
else \
_CALC_BMGS(arr, pat, plen); \
@@ -393,7 +399,8 @@ tre_fastcomp(fastmatch_t *fg, const tre_
pat++;
}
- if ((n >= 14) &&
+ /* Handle word-boundary matching when GNU extensions are enabled */
+ if ((cflags & REG_GNU) && (n >= 14) &&
(memcmp(pat, TRE_CHAR("[[:<:]]"), 7 * sizeof(tre_char_t)) == 0) &&
(memcmp(pat + n - 7, TRE_CHAR("[[:>:]]"),
7 * sizeof(tre_char_t)) == 0))
@@ -439,6 +446,10 @@ tre_fastcomp(fastmatch_t *fg, const tre_
return REG_OK;
}
+/*
+ * Executes matching of the precompiled pattern on the input string.
+ * Returns REG_OK or REG_NOMATCH depending on if we find a match or not.
+ */
int
tre_fastexec(const fastmatch_t *fg, const void *data, size_t len,
tre_str_type_t type, int nmatch, regmatch_t pmatch[])
@@ -480,7 +491,7 @@ tre_fastexec(const fastmatch_t *fg, cons
{
/* Simple text comparison. */
if (!((fg->bol && fg->eol) &&
- (type == STR_WIDE ? (wlen != fg->wlen) : (len != fg->len))))
+ (type == STR_WIDE ? (len != fg->wlen) : (len != fg->len))))
{
/* Determine where in data to start search at. */
j = fg->eol ? len - (type == STR_WIDE ? fg->wlen : fg->len) : 0;
Modified: user/gabor/tre-integration/contrib/tre/lib/tre.h
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre.h Fri Aug 12 11:43:56 2011 (r224794)
+++ user/gabor/tre-integration/contrib/tre/lib/tre.h Fri Aug 12 14:07:18 2011 (r224795)
@@ -89,6 +89,7 @@ typedef enum {
#define REG_RIGHT_ASSOC (REG_LITERAL << 1)
#define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
#define REG_PEND (REG_UNGREEDY << 1)
+#define REG_GNU (REG_PEND << 1)
/* POSIX tre_regexec() flags. */
#define REG_NOTBOL 1
Modified: user/gabor/tre-integration/include/regex.h
==============================================================================
--- user/gabor/tre-integration/include/regex.h Fri Aug 12 11:43:56 2011 (r224794)
+++ user/gabor/tre-integration/include/regex.h Fri Aug 12 14:07:18 2011 (r224795)
@@ -81,6 +81,7 @@ typedef enum {
#define REG_RIGHT_ASSOC (REG_LITERAL << 1)
#define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
#define REG_PEND (REG_UNGREEDY << 1)
+#define REG_GNU (REG_PEND << 1)
/* POSIX tre_regexec() flags. */
#define REG_NOTBOL 1
More information about the svn-src-user
mailing list