#include "lisp.h"
#include "buffer.h"
#include "syntax.h"
+#include "lib/str.h"
#else /* not emacs */
#define REGEX_ALLOCATE malloc
#define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
-#define REGEX_FREE free
+#define REGEX_mem_free free
#else /* not REGEX_MALLOC */
destination)
/* No need to do anything to free, after alloca. */
-#define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */
+#define REGEX_mem_free(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */
#endif /* not REGEX_MALLOC */
r_alloc (&failure_stack_ptr, (size))
#define REGEX_REALLOCATE_STACK(source, osize, nsize) \
r_re_alloc (&failure_stack_ptr, (nsize))
-#define REGEX_FREE_STACK(ptr) \
+#define REGEX_mem_free_STACK(ptr) \
r_alloc_free (&failure_stack_ptr)
#else /* not using relocating allocator */
#define REGEX_ALLOCATE_STACK malloc
#define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
-#define REGEX_FREE_STACK free
+#define REGEX_mem_free_STACK free
#else /* not REGEX_MALLOC */
#define REGEX_REALLOCATE_STACK(source, osize, nsize) \
REGEX_REALLOCATE (source, osize, nsize)
/* No need to explicitly free anything. */
-#define REGEX_FREE_STACK(arg)
+#define REGEX_mem_free_STACK(arg)
#endif /* not REGEX_MALLOC */
#endif /* not using relocating allocator */
fail_stack.avail = 0; \
} while (0)
-#define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
+#define RESET_FAIL_STACK() REGEX_mem_free_STACK (fail_stack.stack)
#else
#define INIT_FAIL_STACK() \
do { \
examined nor set. */
/* Return, freeing storage we allocated. */
-#define FREE_STACK_RETURN(value) \
+#define mem_free_STACK_RETURN(value) \
return (free (compile_stack.stack), value) /* __MEM_CHECKED__ */
#ifndef HAVE_ISCTYPE
bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
}
if (!bufp->buffer)
- FREE_STACK_RETURN (REG_ESPACE);
+ mem_free_STACK_RETURN (REG_ESPACE);
bufp->allocated = INIT_BUF_SIZE;
}
/* If there is no previous pattern... */
if (!laststart) {
if (syntax & RE_CONTEXT_INVALID_OPS)
- FREE_STACK_RETURN (REG_BADRPT);
+ mem_free_STACK_RETURN (REG_BADRPT);
else if (!(syntax & RE_CONTEXT_INDEP_OPS))
goto normal_char;
}
else if (syntax & RE_BK_PLUS_QM && c == '\\') {
if (p == pend)
- FREE_STACK_RETURN (REG_EESCAPE);
+ mem_free_STACK_RETURN (REG_EESCAPE);
PATFETCH (c1);
if (!(c1 == '+' || c1 == '?')) {
boolean had_char_class = false;
if (p == pend)
- FREE_STACK_RETURN (REG_EBRACK);
+ mem_free_STACK_RETURN (REG_EBRACK);
/* Ensure that we have enough space to push a charset: the
opcode, the length count, and the bitset; 34 bytes in all. */
/* Read in characters and ranges, setting map bits. */
for (;;) {
if (p == pend)
- FREE_STACK_RETURN (REG_EBRACK);
+ mem_free_STACK_RETURN (REG_EBRACK);
PATFETCH (c);
/* \ might escape characters inside [...] and [^...]. */
if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') {
if (p == pend)
- FREE_STACK_RETURN (REG_EESCAPE);
+ mem_free_STACK_RETURN (REG_EESCAPE);
PATFETCH (c1);
SET_LIST_BIT (c1);
/* Look ahead to see if it's a range when the last thing
was a character class. */
if (had_char_class && c == '-' && *p != ']')
- FREE_STACK_RETURN (REG_ERANGE);
+ mem_free_STACK_RETURN (REG_ERANGE);
/* Look ahead to see if it's a range when the last thing
was a character: if this is a hyphen not at the
reg_errcode_t ret
= compile_range (&p, pend, translate, syntax, b);
if (ret != REG_NOERROR)
- FREE_STACK_RETURN (ret);
+ mem_free_STACK_RETURN (ret);
}
else if (p[0] == '-' && p[1] != ']') { /* This handles ranges made up of characters only. */
ret = compile_range (&p, pend, translate, syntax, b);
if (ret != REG_NOERROR)
- FREE_STACK_RETURN (ret);
+ mem_free_STACK_RETURN (ret);
}
/* See if we're at the beginning of a possible character
/* If pattern is `[[:'. */
if (p == pend)
- FREE_STACK_RETURN (REG_EBRACK);
+ mem_free_STACK_RETURN (REG_EBRACK);
for (;;) {
PATFETCH (c);
wt = ctype (str);
if (wt == 0)
- FREE_STACK_RETURN (REG_ECTYPE);
+ mem_free_STACK_RETURN (REG_ECTYPE);
/* Throw away the ] at the end of the character
class. */
PATFETCH (c);
if (p == pend)
- FREE_STACK_RETURN (REG_EBRACK);
+ mem_free_STACK_RETURN (REG_EBRACK);
for (ch = 0; ch < 1 << BYTEWIDTH; ++ch) {
if (isctype (ch, wt))
boolean is_xdigit = STREQ (str, "xdigit");
if (!IS_CHAR_CLASS (str))
- FREE_STACK_RETURN (REG_ECTYPE);
+ mem_free_STACK_RETURN (REG_ECTYPE);
/* Throw away the ] at the end of the character
class. */
PATFETCH (c);
if (p == pend)
- FREE_STACK_RETURN (REG_EBRACK);
+ mem_free_STACK_RETURN (REG_EBRACK);
for (ch = 0; ch < 1 << BYTEWIDTH; ch++) {
/* This was split into 3 if's to
case '\\':
if (p == pend)
- FREE_STACK_RETURN (REG_EESCAPE);
+ mem_free_STACK_RETURN (REG_EESCAPE);
/* Do not translate the character after the \, so that we can
distinguish, e.g., \B from \b, even if we normally would
if (syntax & RE_NO_BK_PARENS)
goto normal_backslash;
- if (COMPILE_STACK_EMPTY)
- if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
+ if (COMPILE_STACK_EMPTY) {
+ if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) {
goto normal_backslash;
- else
- FREE_STACK_RETURN (REG_ERPAREN);
+ } else {
+ mem_free_STACK_RETURN (REG_ERPAREN);
+ }
+ }
handle_close:
if (fixup_alt_jump) { /* Push a dummy failure point at the end of the
}
/* See similar code for backslashed left paren above. */
- if (COMPILE_STACK_EMPTY)
- if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
+ if (COMPILE_STACK_EMPTY) {
+ if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) {
goto normal_char;
- else
- FREE_STACK_RETURN (REG_ERPAREN);
+ } else {
+ mem_free_STACK_RETURN (REG_ERPAREN);
+ }
+ }
/* Since we just checked for an empty stack above, this
``can't happen''. */
if (syntax & RE_NO_BK_BRACES)
goto unfetch_interval;
else
- FREE_STACK_RETURN (REG_EBRACE);
+ mem_free_STACK_RETURN (REG_EBRACE);
}
GET_UNSIGNED_NUMBER (lower_bound);
if (syntax & RE_NO_BK_BRACES)
goto unfetch_interval;
else
- FREE_STACK_RETURN (REG_BADBR);
+ mem_free_STACK_RETURN (REG_BADBR);
}
if (!(syntax & RE_NO_BK_BRACES)) {
if (c != '\\')
- FREE_STACK_RETURN (REG_EBRACE);
+ mem_free_STACK_RETURN (REG_EBRACE);
PATFETCH (c);
}
if (syntax & RE_NO_BK_BRACES)
goto unfetch_interval;
else
- FREE_STACK_RETURN (REG_BADBR);
+ mem_free_STACK_RETURN (REG_BADBR);
}
/* We just parsed a valid interval. */
/* If it's invalid to have no preceding re. */
if (!laststart) {
if (syntax & RE_CONTEXT_INVALID_OPS)
- FREE_STACK_RETURN (REG_BADRPT);
+ mem_free_STACK_RETURN (REG_BADRPT);
else if (syntax & RE_CONTEXT_INDEP_OPS)
laststart = b;
else
c1 = c - '0';
if (c1 > regnum)
- FREE_STACK_RETURN (REG_ESUBREG);
+ mem_free_STACK_RETURN (REG_ESUBREG);
/* Can't back reference to a subexpression if inside of it. */
if (group_in_compile_stack (compile_stack, (regnum_t) c1))
STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
if (!COMPILE_STACK_EMPTY)
- FREE_STACK_RETURN (REG_EPAREN);
+ mem_free_STACK_RETURN (REG_EPAREN);
/* If we don't want backtracking, force success
the first time we reach the end of the compiled pattern. */
/* Free everything we malloc. */
#ifdef MATCH_MAY_ALLOCATE
-#define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
-#define FREE_VARIABLES() \
+#define mem_free_VAR(var) if (var) REGEX_mem_free (var); var = NULL
+#define mem_free_VARIABLES() \
do { \
- REGEX_FREE_STACK (fail_stack.stack); \
- FREE_VAR (regstart); \
- FREE_VAR (regend); \
- FREE_VAR (old_regstart); \
- FREE_VAR (old_regend); \
- FREE_VAR (best_regstart); \
- FREE_VAR (best_regend); \
- FREE_VAR (reg_info); \
- FREE_VAR (reg_dummy); \
- FREE_VAR (reg_info_dummy); \
+ REGEX_mem_free_STACK (fail_stack.stack); \
+ mem_free_VAR (regstart); \
+ mem_free_VAR (regend); \
+ mem_free_VAR (old_regstart); \
+ mem_free_VAR (old_regend); \
+ mem_free_VAR (best_regstart); \
+ mem_free_VAR (best_regend); \
+ mem_free_VAR (reg_info); \
+ mem_free_VAR (reg_dummy); \
+ mem_free_VAR (reg_info_dummy); \
} while (0)
#else
-#define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
+#define mem_free_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
#endif /* not MATCH_MAY_ALLOCATE */
/* These values must meet several constraints. They must not be valid
if (!(regstart && regend && old_regstart && old_regend && reg_info
&& best_regstart && best_regend && reg_dummy && reg_info_dummy)) {
- FREE_VARIABLES ();
+ mem_free_VARIABLES ();
return -2;
}
}
else {
/* We must initialize all our variables to NULL, so that
- `FREE_VARIABLES' doesn't try to free them. */
+ `mem_free_VARIABLES' doesn't try to free them. */
regstart = regend = old_regstart = old_regend = best_regstart
= best_regend = reg_dummy = NULL;
reg_info = reg_info_dummy = (register_info_type *) NULL;
/* The starting position is bogus. */
if (pos < 0 || pos > size1 + size2) {
- FREE_VARIABLES ();
+ mem_free_VARIABLES ();
return -1;
}
regs->start = TALLOC (regs->num_regs, regoff_t);
regs->end = TALLOC (regs->num_regs, regoff_t);
if (regs->start == NULL || regs->end == NULL) {
- FREE_VARIABLES ();
+ mem_free_VARIABLES ();
return -2;
}
bufp->regs_allocated = REGS_REALLOCATE;
RETALLOC (regs->start, regs->num_regs, regoff_t);
RETALLOC (regs->end, regs->num_regs, regoff_t);
if (regs->start == NULL || regs->end == NULL) {
- FREE_VARIABLES ();
+ mem_free_VARIABLES ();
return -2;
}
}
DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
- FREE_VARIABLES ();
+ mem_free_VARIABLES ();
return mcnt;
}
if (best_regs_set)
goto restore_best_regs;
- FREE_VARIABLES ();
+ mem_free_VARIABLES ();
return -1; /* Failure to match. */
} /* re_match_2 */