Commit 3a6abe65 authored by Paul Eggert's avatar Paul Eggert

Simplify regex-emacs code by assuming Emacs

* src/regex-emacs.c: Omit no-longer-needed AIX code.
Don’t ignore GCC warnings.
Include regex-emacs.h immediately after config.h,
to test that it’s independent.
Omit the "#ifndef emacs" and "#ifdef REGEX_MALLOC" and
"#if WIDE_CHAR_SUPPORT" or "#ifdef _REGEX_RE_COMP",
code, as we are no longer interested in compiling outside
Emacs (with or without debugging or native wide char support)
or in avoiding alloca.
(REGEX_EMACS_DEBUG, regex_emacs_debug): Rename from DEBUG and debug,
to avoid collision with other DEBUGS.  All uses changed.
In debugging output, change %ld and %zd to %zu when appropriate.
No need to include stddef.h, stdlib.h, sys/types.h, wchar.h,
wctype.h, locale/localeinfo.h, locale/elem-hash.h, langinfo.h,
libintl.h, unistd.h, stdbool.h, string.h, stdio.h, assert.h.
All uses of assert changed to eassert.
(RE_DUP_MAX, reg_syntax_t, RE_BACKSLASH_ESCAPE_IN_LISTS)
(RE_BK_PLUS_QM, RE_CHAR_CLASSES, RE_CONTEXT_INDEP_ANCHORS)
(RE_CONTEXT_INDEP_OPS, RE_CONTEXT_INVALID_OPS, RE_DOT_NEWLINE)
(RE_DOT_NOT_NULL, RE_HAT_LISTS_NOT_NEWLINE, RE_INTERVALS)
(RE_LIMITED_OPS, RE_NEWLINE_ALT, RE_NO_BK_BRACES)
(RE_NO_BK_PARENS, RE_NO_BK_REFS, RE_NO_BK_VBAR)
(RE_NO_EMPTY_RANGES, RE_UNMATCHED_RIGHT_PAREN_ORD)
(RE_NO_POSIX_BACKTRACKING, RE_NO_GNU_OPS, RE_FRUGAL)
(RE_SHY_GROUPS, RE_NO_NEWLINE_ANCHOR, RE_SYNTAX_EMACS)
(REG_NOERROR, REG_NOMATCH, REG_BADPAT, REG_ECOLLATE)
(REG_ECTYPE, REG_EESCAPE, REG_ESUBREG, REG_EBRACK, REG_EPAREN)
(REG_EBRACE, REG_BADBR, REG_ERANGE, REG_ESPACE, REG_BADRPT)
(REG_EEND, REG_ESIZE, REG_ERPAREN, REG_ERANGEX, REG_ESIZEBR)
(reg_errcode_t, REGS_UNALLOCATED, REGS_REALLOCATE, REGS_FIXED)
(RE_NREGS, RE_TRANSLATE, RE_TRANSLATE_P):
Move here from regex-emacs.h.
(RE_NREGS): Define unconditionally.
(boolean): Remove.  All uses replaced by bool.
(WIDE_CHAR_SUPPORT, regfree, regexec, regcomp, regerror):
(re_set_syntax, re_syntax_options, WEAK_ALIAS, gettext, gettext_noop):
Remove.  All uses removed.
(malloc, realloc, free): Do not redefine.  Adjust all callers
to use xmalloc, xrealloc, xfree instead.
(re_error_msgid): Use C99 to avoid need to keep in same order
as reg_error_t.
(REGEX_USE_SAFE_ALLOCA): Simplify by using USE_SAFE_ALLOCA.
(REGEX_ALLOCATE, REGEX_REALLOCATE, REGEX_FREE, REGEX_ALLOCATE_STACK)
(REGEX_REALLOCATE_STACK, REGEX_FREE_STACK): Remove.
All callers changed to use the non-REGEX_MALLOC version.
(REGEX_TALLOC): Remove.  All callers changed to use SAFE_ALLOCA.
(re_set_syntax): Remove; unused.
(MATCH_MAY_ALLOCATE): Remove; now always true.  All uses simplified.
(INIT_FAILURE_ALLOC): Define unconditionally.
(re_compile_fastmap): Now static.
(re_compile_pattern): Avoid unnecessary cast.
* src/regex-emacs.h (EMACS_REGEX_H): Renamed from _REGEX_H to
avoid possible collision with glibc.
Don’t include sys/types.h.  All uses of ssize_t changed to ptrdiff_t.
Don’t worry about C++ or VMS.
Assume emacs is defined and that _REGEX_RE_COMP and WIDE_CHAR_SUPPORT
are not.
Define struct re_registers before including lisp.h.
(REG_ENOSYS, RE_TRANSLATE_TYPE): Remove; all uses replaced by
Lisp_Object.
(regoff_t): Remove.  All uses replaced with ptrdiff_t.
(re_match, regcomp, regexec, regerror, regfree):
Remove decl of nonexistent functions.
(RE_DEBUG, RE_SYNTAX_AWK, RE_SYNTAX_GNU_AWK)
(RE_SYNTAX_POSIX_AWK, RE_SYNTAX_GREP, RE_SYNTAX_EGREP)
(RE_SYNTAX_POSIX_EGREP, RE_SYNTAX_ED, RE_SYNTAX_SED)
(_RE_SYNTAX_POSIX_COMMON, RE_SYNTAX_POSIX_BASIC)
(RE_SYNTAX_POSIX_MINIMAL_BASIC, RE_SYNTAX_POSIX_EXTENDED)
(RE_SYNTAX_POSIX_MINIMAL_EXTENDED, REG_EXTENDED, REG_ICASE)
(REG_NEWLINE, REG_NOSUB, REG_NOTBOL, REG_NOTEOL, regmatch_t):
Remove; unused.
* src/search.c (Fset_match_data): Simplify range test now that
we know it’s ptrdiff_t.
parent d904cc83
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -59,8 +59,8 @@ static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
static struct regexp_cache *searchbuf_head;
/* Every call to re_match, etc., must pass &search_regs as the regs
argument unless you can show it is unnecessary (i.e., if re_match
/* Every call to re_search, etc., must pass &search_regs as the regs
argument unless you can show it is unnecessary (i.e., if re_search
is certainly going to be called again before region-around-match
can be called).
......@@ -2189,8 +2189,8 @@ set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes)
the match position. */
if (search_regs.num_regs == 0)
{
search_regs.start = xmalloc (2 * sizeof (regoff_t));
search_regs.end = xmalloc (2 * sizeof (regoff_t));
search_regs.start = xmalloc (2 * sizeof *search_regs.start);
search_regs.end = xmalloc (2 * sizeof *search_regs.end);
search_regs.num_regs = 2;
}
......@@ -3001,9 +3001,9 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
memory_full (SIZE_MAX);
search_regs.start =
xpalloc (search_regs.start, &num_regs, length - num_regs,
min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t));
min (PTRDIFF_MAX, UINT_MAX), sizeof *search_regs.start);
search_regs.end =
xrealloc (search_regs.end, num_regs * sizeof (regoff_t));
xrealloc (search_regs.end, num_regs * sizeof *search_regs.end);
for (i = search_regs.num_regs; i < num_regs; i++)
search_regs.start[i] = -1;
......@@ -3058,12 +3058,9 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
XSETFASTINT (marker, 0);
CHECK_NUMBER_COERCE_MARKER (marker);
if ((XINT (from) < 0
? TYPE_MINIMUM (regoff_t) <= XINT (from)
: XINT (from) <= TYPE_MAXIMUM (regoff_t))
&& (XINT (marker) < 0
? TYPE_MINIMUM (regoff_t) <= XINT (marker)
: XINT (marker) <= TYPE_MAXIMUM (regoff_t)))
if (PTRDIFF_MIN <= XINT (from) && XINT (from) <= PTRDIFF_MAX
&& PTRDIFF_MIN <= XINT (marker)
&& XINT (marker) <= PTRDIFF_MAX)
{
search_regs.start[i] = XINT (from);
search_regs.end[i] = XINT (marker);
......
......@@ -112,8 +112,8 @@ struct thread_state
struct buffer *m_current_buffer;
#define current_buffer (current_thread->m_current_buffer)
/* Every call to re_match, etc., must pass &search_regs as the regs
argument unless you can show it is unnecessary (i.e., if re_match
/* Every call to re_match_2, etc., must pass &search_regs as the regs
argument unless you can show it is unnecessary (i.e., if re_match_2
is certainly going to be called again before region-around-match
can be called).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment