diff options
| author | Tom Tromey | 2018-08-09 17:56:53 -0600 |
|---|---|---|
| committer | Tom Tromey | 2018-08-09 17:56:53 -0600 |
| commit | accb7b7ecc19f85c2750ded1046a464bc73c6a52 (patch) | |
| tree | 1aa94af022d6700a93a8ff2b73f5b210046ac010 /src | |
| parent | f822a2516d88eeb2118fbbc8554f155e86dfd74e (diff) | |
| parent | 53483df0de0085dbc9ef0b15a0f629ab808b0147 (diff) | |
| download | emacs-accb7b7ecc19f85c2750ded1046a464bc73c6a52.tar.gz emacs-accb7b7ecc19f85c2750ded1046a464bc73c6a52.zip | |
Merge remote-tracking branch 'origin/master' into feature/bignum
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.in | 2 | ||||
| -rw-r--r-- | src/alloc.c | 65 | ||||
| -rw-r--r-- | src/callint.c | 2 | ||||
| -rw-r--r-- | src/casetab.c | 3 | ||||
| -rw-r--r-- | src/character.c | 10 | ||||
| -rw-r--r-- | src/chartab.c | 4 | ||||
| -rw-r--r-- | src/dbusbind.c | 4 | ||||
| -rw-r--r-- | src/deps.mk | 9 | ||||
| -rw-r--r-- | src/dired.c | 2 | ||||
| -rw-r--r-- | src/dispextern.h | 2 | ||||
| -rw-r--r-- | src/editfns.c | 68 | ||||
| -rw-r--r-- | src/emacs.c | 19 | ||||
| -rw-r--r-- | src/eval.c | 20 | ||||
| -rw-r--r-- | src/fileio.c | 35 | ||||
| -rw-r--r-- | src/floatfns.c | 7 | ||||
| -rw-r--r-- | src/fns.c | 103 | ||||
| -rw-r--r-- | src/frame.c | 27 | ||||
| -rw-r--r-- | src/gnutls.c | 38 | ||||
| -rw-r--r-- | src/image.c | 2 | ||||
| -rw-r--r-- | src/intervals.c | 2 | ||||
| -rw-r--r-- | src/intervals.h | 2 | ||||
| -rw-r--r-- | src/json.c | 11 | ||||
| -rw-r--r-- | src/keyboard.c | 47 | ||||
| -rw-r--r-- | src/lisp.h | 14 | ||||
| -rw-r--r-- | src/lread.c | 18 | ||||
| -rw-r--r-- | src/menu.c | 6 | ||||
| -rw-r--r-- | src/nsfns.m | 4 | ||||
| -rw-r--r-- | src/nsmenu.m | 2 | ||||
| -rw-r--r-- | src/nsselect.m | 6 | ||||
| -rw-r--r-- | src/print.c | 48 | ||||
| -rw-r--r-- | src/process.c | 33 | ||||
| -rw-r--r-- | src/regex-emacs.c (renamed from src/regex.c) | 2727 | ||||
| -rw-r--r-- | src/regex-emacs.h | 197 | ||||
| -rw-r--r-- | src/regex.h | 654 | ||||
| -rw-r--r-- | src/search.c | 36 | ||||
| -rw-r--r-- | src/syntax.c | 11 | ||||
| -rw-r--r-- | src/terminal.c | 2 | ||||
| -rw-r--r-- | src/textprop.c | 22 | ||||
| -rw-r--r-- | src/thread.c | 43 | ||||
| -rw-r--r-- | src/thread.h | 9 | ||||
| -rw-r--r-- | src/w32cygwinx.c | 37 | ||||
| -rw-r--r-- | src/w32term.c | 2 | ||||
| -rw-r--r-- | src/xdisp.c | 55 | ||||
| -rw-r--r-- | src/xfaces.c | 4 | ||||
| -rw-r--r-- | src/xfns.c | 4 | ||||
| -rw-r--r-- | src/xmenu.c | 4 | ||||
| -rw-r--r-- | src/xselect.c | 4 | ||||
| -rw-r--r-- | src/xwidget.c | 2 |
48 files changed, 1316 insertions, 3112 deletions
diff --git a/src/Makefile.in b/src/Makefile.in index 05d24acef6c..52ce7605f7b 100644 --- a/src/Makefile.in +++ b/src/Makefile.in | |||
| @@ -394,7 +394,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \ | |||
| 394 | emacs.o keyboard.o macros.o keymap.o sysdep.o \ | 394 | emacs.o keyboard.o macros.o keymap.o sysdep.o \ |
| 395 | buffer.o filelock.o insdel.o marker.o \ | 395 | buffer.o filelock.o insdel.o marker.o \ |
| 396 | minibuf.o fileio.o dired.o \ | 396 | minibuf.o fileio.o dired.o \ |
| 397 | cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o \ | 397 | cmds.o casetab.o casefiddle.o indent.o search.o regex-emacs.o undo.o \ |
| 398 | alloc.o data.o doc.o editfns.o callint.o \ | 398 | alloc.o data.o doc.o editfns.o callint.o \ |
| 399 | eval.o floatfns.o fns.o font.o print.o lread.o $(MODULES_OBJ) \ | 399 | eval.o floatfns.o fns.o font.o print.o lread.o $(MODULES_OBJ) \ |
| 400 | syntax.o $(UNEXEC_OBJ) bytecode.o \ | 400 | syntax.o $(UNEXEC_OBJ) bytecode.o \ |
diff --git a/src/alloc.c b/src/alloc.c index a8bc55beb40..c3e02c20f85 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2932,7 +2932,7 @@ set_next_vector (struct Lisp_Vector *v, struct Lisp_Vector *p) | |||
| 2932 | for the most common cases; it's not required to be a power of two, but | 2932 | for the most common cases; it's not required to be a power of two, but |
| 2933 | it's expected to be a mult-of-ROUNDUP_SIZE (see below). */ | 2933 | it's expected to be a mult-of-ROUNDUP_SIZE (see below). */ |
| 2934 | 2934 | ||
| 2935 | #define VECTOR_BLOCK_SIZE 4096 | 2935 | enum { VECTOR_BLOCK_SIZE = 4096 }; |
| 2936 | 2936 | ||
| 2937 | /* Vector size requests are a multiple of this. */ | 2937 | /* Vector size requests are a multiple of this. */ |
| 2938 | enum { roundup_size = COMMON_MULTIPLE (LISP_ALIGNMENT, word_size) }; | 2938 | enum { roundup_size = COMMON_MULTIPLE (LISP_ALIGNMENT, word_size) }; |
| @@ -2948,22 +2948,21 @@ verify (VECTOR_BLOCK_SIZE <= (1 << PSEUDOVECTOR_SIZE_BITS)); | |||
| 2948 | 2948 | ||
| 2949 | /* Rounding helps to maintain alignment constraints if USE_LSB_TAG. */ | 2949 | /* Rounding helps to maintain alignment constraints if USE_LSB_TAG. */ |
| 2950 | 2950 | ||
| 2951 | #define VECTOR_BLOCK_BYTES (VECTOR_BLOCK_SIZE - vroundup_ct (sizeof (void *))) | 2951 | enum {VECTOR_BLOCK_BYTES = VECTOR_BLOCK_SIZE - vroundup_ct (sizeof (void *))}; |
| 2952 | 2952 | ||
| 2953 | /* Size of the minimal vector allocated from block. */ | 2953 | /* Size of the minimal vector allocated from block. */ |
| 2954 | 2954 | ||
| 2955 | #define VBLOCK_BYTES_MIN vroundup_ct (header_size + sizeof (Lisp_Object)) | 2955 | enum { VBLOCK_BYTES_MIN = vroundup_ct (header_size + sizeof (Lisp_Object)) }; |
| 2956 | 2956 | ||
| 2957 | /* Size of the largest vector allocated from block. */ | 2957 | /* Size of the largest vector allocated from block. */ |
| 2958 | 2958 | ||
| 2959 | #define VBLOCK_BYTES_MAX \ | 2959 | enum { VBLOCK_BYTES_MAX = vroundup_ct ((VECTOR_BLOCK_BYTES / 2) - word_size) }; |
| 2960 | vroundup ((VECTOR_BLOCK_BYTES / 2) - word_size) | ||
| 2961 | 2960 | ||
| 2962 | /* We maintain one free list for each possible block-allocated | 2961 | /* We maintain one free list for each possible block-allocated |
| 2963 | vector size, and this is the number of free lists we have. */ | 2962 | vector size, and this is the number of free lists we have. */ |
| 2964 | 2963 | ||
| 2965 | #define VECTOR_MAX_FREE_LIST_INDEX \ | 2964 | enum { VECTOR_MAX_FREE_LIST_INDEX = |
| 2966 | ((VECTOR_BLOCK_BYTES - VBLOCK_BYTES_MIN) / roundup_size + 1) | 2965 | (VECTOR_BLOCK_BYTES - VBLOCK_BYTES_MIN) / roundup_size + 1 }; |
| 2967 | 2966 | ||
| 2968 | /* Common shortcut to advance vector pointer over a block data. */ | 2967 | /* Common shortcut to advance vector pointer over a block data. */ |
| 2969 | 2968 | ||
| @@ -3090,14 +3089,14 @@ init_vectors (void) | |||
| 3090 | /* Allocate vector from a vector block. */ | 3089 | /* Allocate vector from a vector block. */ |
| 3091 | 3090 | ||
| 3092 | static struct Lisp_Vector * | 3091 | static struct Lisp_Vector * |
| 3093 | allocate_vector_from_block (size_t nbytes) | 3092 | allocate_vector_from_block (ptrdiff_t nbytes) |
| 3094 | { | 3093 | { |
| 3095 | struct Lisp_Vector *vector; | 3094 | struct Lisp_Vector *vector; |
| 3096 | struct vector_block *block; | 3095 | struct vector_block *block; |
| 3097 | size_t index, restbytes; | 3096 | size_t index, restbytes; |
| 3098 | 3097 | ||
| 3099 | eassert (VBLOCK_BYTES_MIN <= nbytes && nbytes <= VBLOCK_BYTES_MAX); | 3098 | eassume (VBLOCK_BYTES_MIN <= nbytes && nbytes <= VBLOCK_BYTES_MAX); |
| 3100 | eassert (nbytes % roundup_size == 0); | 3099 | eassume (nbytes % roundup_size == 0); |
| 3101 | 3100 | ||
| 3102 | /* First, try to allocate from a free list | 3101 | /* First, try to allocate from a free list |
| 3103 | containing vectors of the requested size. */ | 3102 | containing vectors of the requested size. */ |
| @@ -3182,35 +3181,45 @@ vector_nbytes (struct Lisp_Vector *v) | |||
| 3182 | return vroundup (header_size + word_size * nwords); | 3181 | return vroundup (header_size + word_size * nwords); |
| 3183 | } | 3182 | } |
| 3184 | 3183 | ||
| 3184 | /* Convert a pseudovector pointer P to its underlying struct T pointer. | ||
| 3185 | Verify that the struct is small, since cleanup_vector is called | ||
| 3186 | only on small vector-like objects. */ | ||
| 3187 | |||
| 3188 | #define PSEUDOVEC_STRUCT(p, t) \ | ||
| 3189 | verify_expr ((header_size + VECSIZE (struct t) * word_size \ | ||
| 3190 | <= VBLOCK_BYTES_MAX), \ | ||
| 3191 | (struct t *) (p)) | ||
| 3192 | |||
| 3185 | /* Release extra resources still in use by VECTOR, which may be any | 3193 | /* Release extra resources still in use by VECTOR, which may be any |
| 3186 | vector-like object. */ | 3194 | small vector-like object. */ |
| 3187 | 3195 | ||
| 3188 | static void | 3196 | static void |
| 3189 | cleanup_vector (struct Lisp_Vector *vector) | 3197 | cleanup_vector (struct Lisp_Vector *vector) |
| 3190 | { | 3198 | { |
| 3191 | detect_suspicious_free (vector); | 3199 | detect_suspicious_free (vector); |
| 3192 | if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FONT) | 3200 | if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FONT)) |
| 3193 | && ((vector->header.size & PSEUDOVECTOR_SIZE_MASK) | ||
| 3194 | == FONT_OBJECT_MAX)) | ||
| 3195 | { | 3201 | { |
| 3196 | struct font_driver const *drv = ((struct font *) vector)->driver; | 3202 | if ((vector->header.size & PSEUDOVECTOR_SIZE_MASK) == FONT_OBJECT_MAX) |
| 3197 | |||
| 3198 | /* The font driver might sometimes be NULL, e.g. if Emacs was | ||
| 3199 | interrupted before it had time to set it up. */ | ||
| 3200 | if (drv) | ||
| 3201 | { | 3203 | { |
| 3202 | /* Attempt to catch subtle bugs like Bug#16140. */ | 3204 | struct font *font = PSEUDOVEC_STRUCT (vector, font); |
| 3203 | eassert (valid_font_driver (drv)); | 3205 | struct font_driver const *drv = font->driver; |
| 3204 | drv->close ((struct font *) vector); | 3206 | |
| 3207 | /* The font driver might sometimes be NULL, e.g. if Emacs was | ||
| 3208 | interrupted before it had time to set it up. */ | ||
| 3209 | if (drv) | ||
| 3210 | { | ||
| 3211 | /* Attempt to catch subtle bugs like Bug#16140. */ | ||
| 3212 | eassert (valid_font_driver (drv)); | ||
| 3213 | drv->close (font); | ||
| 3214 | } | ||
| 3205 | } | 3215 | } |
| 3206 | } | 3216 | } |
| 3207 | 3217 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_THREAD)) | |
| 3208 | if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_THREAD)) | 3218 | finalize_one_thread (PSEUDOVEC_STRUCT (vector, thread_state)); |
| 3209 | finalize_one_thread ((struct thread_state *) vector); | ||
| 3210 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_MUTEX)) | 3219 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_MUTEX)) |
| 3211 | finalize_one_mutex ((struct Lisp_Mutex *) vector); | 3220 | finalize_one_mutex (PSEUDOVEC_STRUCT (vector, Lisp_Mutex)); |
| 3212 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_CONDVAR)) | 3221 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_CONDVAR)) |
| 3213 | finalize_one_condvar ((struct Lisp_CondVar *) vector); | 3222 | finalize_one_condvar (PSEUDOVEC_STRUCT (vector, Lisp_CondVar)); |
| 3214 | } | 3223 | } |
| 3215 | 3224 | ||
| 3216 | /* Reclaim space used by unmarked vectors. */ | 3225 | /* Reclaim space used by unmarked vectors. */ |
| @@ -6719,7 +6728,7 @@ mark_object (Lisp_Object arg) | |||
| 6719 | CHECK_ALLOCATED_AND_LIVE (live_cons_p); | 6728 | CHECK_ALLOCATED_AND_LIVE (live_cons_p); |
| 6720 | CONS_MARK (ptr); | 6729 | CONS_MARK (ptr); |
| 6721 | /* If the cdr is nil, avoid recursion for the car. */ | 6730 | /* If the cdr is nil, avoid recursion for the car. */ |
| 6722 | if (EQ (ptr->u.s.u.cdr, Qnil)) | 6731 | if (NILP (ptr->u.s.u.cdr)) |
| 6723 | { | 6732 | { |
| 6724 | obj = ptr->u.s.car; | 6733 | obj = ptr->u.s.car; |
| 6725 | cdr_count = 0; | 6734 | cdr_count = 0; |
diff --git a/src/callint.c b/src/callint.c index c8b75859e60..81efb267bdf 100644 --- a/src/callint.c +++ b/src/callint.c | |||
| @@ -200,7 +200,7 @@ fix_command (Lisp_Object input, Lisp_Object values) | |||
| 200 | carelt = XCAR (elt); | 200 | carelt = XCAR (elt); |
| 201 | /* If it is (if X Y), look at Y. */ | 201 | /* If it is (if X Y), look at Y. */ |
| 202 | if (EQ (carelt, Qif) | 202 | if (EQ (carelt, Qif) |
| 203 | && EQ (Fnthcdr (make_fixnum (3), elt), Qnil)) | 203 | && NILP (Fnthcdr (make_fixnum (3), elt))) |
| 204 | elt = Fnth (make_fixnum (2), elt); | 204 | elt = Fnth (make_fixnum (2), elt); |
| 205 | /* If it is (when ... Y), look at Y. */ | 205 | /* If it is (when ... Y), look at Y. */ |
| 206 | else if (EQ (carelt, Qwhen)) | 206 | else if (EQ (carelt, Qwhen)) |
diff --git a/src/casetab.c b/src/casetab.c index 6b1c64f89e4..0e742de2104 100644 --- a/src/casetab.c +++ b/src/casetab.c | |||
| @@ -144,7 +144,8 @@ set_case_table (Lisp_Object table, bool standard) | |||
| 144 | set_char_table_extras (table, 2, eqv); | 144 | set_char_table_extras (table, 2, eqv); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ | 147 | /* This is so set_image_of_range_1 in regex-emacs.c can find the EQV |
| 148 | table. */ | ||
| 148 | set_char_table_extras (canon, 2, eqv); | 149 | set_char_table_extras (canon, 2, eqv); |
| 149 | 150 | ||
| 150 | if (standard) | 151 | if (standard) |
diff --git a/src/character.c b/src/character.c index 97698d77890..851e61e778f 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -34,6 +34,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 34 | #include "lisp.h" | 34 | #include "lisp.h" |
| 35 | #include "character.h" | 35 | #include "character.h" |
| 36 | #include "buffer.h" | 36 | #include "buffer.h" |
| 37 | #include "dispextern.h" | ||
| 37 | #include "composite.h" | 38 | #include "composite.h" |
| 38 | #include "disptab.h" | 39 | #include "disptab.h" |
| 39 | 40 | ||
| @@ -288,10 +289,15 @@ char_width (int c, struct Lisp_Char_Table *dp) | |||
| 288 | if (VECTORP (disp)) | 289 | if (VECTORP (disp)) |
| 289 | for (i = 0, width = 0; i < ASIZE (disp); i++) | 290 | for (i = 0, width = 0; i < ASIZE (disp); i++) |
| 290 | { | 291 | { |
| 292 | int c = -1; | ||
| 291 | ch = AREF (disp, i); | 293 | ch = AREF (disp, i); |
| 292 | if (CHARACTERP (ch)) | 294 | if (GLYPH_CODE_P (ch)) |
| 295 | c = GLYPH_CODE_CHAR (ch); | ||
| 296 | else if (CHARACTERP (ch)) | ||
| 297 | c = XFASTINT (ch); | ||
| 298 | if (c >= 0) | ||
| 293 | { | 299 | { |
| 294 | int w = CHARACTER_WIDTH (XFIXNAT (ch)); | 300 | int w = CHARACTER_WIDTH (c); |
| 295 | if (INT_ADD_WRAPV (width, w, &width)) | 301 | if (INT_ADD_WRAPV (width, w, &width)) |
| 296 | string_overflow (); | 302 | string_overflow (); |
| 297 | } | 303 | } |
diff --git a/src/chartab.c b/src/chartab.c index 0383a84a04d..3d38b3ce12e 100644 --- a/src/chartab.c +++ b/src/chartab.c | |||
| @@ -605,7 +605,7 @@ a cons of character codes (for characters in the range), or a character code. * | |||
| 605 | Lisp_Object val; | 605 | Lisp_Object val; |
| 606 | CHECK_CHAR_TABLE (char_table); | 606 | CHECK_CHAR_TABLE (char_table); |
| 607 | 607 | ||
| 608 | if (EQ (range, Qnil)) | 608 | if (NILP (range)) |
| 609 | val = XCHAR_TABLE (char_table)->defalt; | 609 | val = XCHAR_TABLE (char_table)->defalt; |
| 610 | else if (CHARACTERP (range)) | 610 | else if (CHARACTERP (range)) |
| 611 | val = CHAR_TABLE_REF (char_table, XFIXNAT (range)); | 611 | val = CHAR_TABLE_REF (char_table, XFIXNAT (range)); |
| @@ -642,7 +642,7 @@ or a character code. Return VALUE. */) | |||
| 642 | for (i = 0; i < chartab_size[0]; i++) | 642 | for (i = 0; i < chartab_size[0]; i++) |
| 643 | set_char_table_contents (char_table, i, value); | 643 | set_char_table_contents (char_table, i, value); |
| 644 | } | 644 | } |
| 645 | else if (EQ (range, Qnil)) | 645 | else if (NILP (range)) |
| 646 | set_char_table_defalt (char_table, value); | 646 | set_char_table_defalt (char_table, value); |
| 647 | else if (CHARACTERP (range)) | 647 | else if (CHARACTERP (range)) |
| 648 | char_table_set (char_table, XFIXNUM (range), value); | 648 | char_table_set (char_table, XFIXNUM (range), value); |
diff --git a/src/dbusbind.c b/src/dbusbind.c index 4cf5604d745..fe92d3997bd 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -200,7 +200,7 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 200 | `dbus-send-signal', into corresponding C values appended as | 200 | `dbus-send-signal', into corresponding C values appended as |
| 201 | arguments to a D-Bus message. */ | 201 | arguments to a D-Bus message. */ |
| 202 | #define XD_OBJECT_TO_DBUS_TYPE(object) \ | 202 | #define XD_OBJECT_TO_DBUS_TYPE(object) \ |
| 203 | ((EQ (object, Qt) || EQ (object, Qnil)) ? DBUS_TYPE_BOOLEAN \ | 203 | ((EQ (object, Qt) || NILP (object)) ? DBUS_TYPE_BOOLEAN \ |
| 204 | : (FIXNATP (object)) ? DBUS_TYPE_UINT32 \ | 204 | : (FIXNATP (object)) ? DBUS_TYPE_UINT32 \ |
| 205 | : (FIXNUMP (object)) ? DBUS_TYPE_INT32 \ | 205 | : (FIXNUMP (object)) ? DBUS_TYPE_INT32 \ |
| 206 | : (FLOATP (object)) ? DBUS_TYPE_DOUBLE \ | 206 | : (FLOATP (object)) ? DBUS_TYPE_DOUBLE \ |
| @@ -360,7 +360,7 @@ xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object) | |||
| 360 | break; | 360 | break; |
| 361 | 361 | ||
| 362 | case DBUS_TYPE_BOOLEAN: | 362 | case DBUS_TYPE_BOOLEAN: |
| 363 | if (!EQ (object, Qt) && !EQ (object, Qnil)) | 363 | if (!EQ (object, Qt) && !NILP (object)) |
| 364 | wrong_type_argument (intern ("booleanp"), object); | 364 | wrong_type_argument (intern ("booleanp"), object); |
| 365 | sprintf (signature, "%c", dtype); | 365 | sprintf (signature, "%c", dtype); |
| 366 | break; | 366 | break; |
diff --git a/src/deps.mk b/src/deps.mk index 7b6ae9cd8e0..f202d0e1041 100644 --- a/src/deps.mk +++ b/src/deps.mk | |||
| @@ -71,7 +71,7 @@ cmds.o: cmds.c syntax.h buffer.h character.h commands.h window.h lisp.h \ | |||
| 71 | pre-crt0.o: pre-crt0.c | 71 | pre-crt0.o: pre-crt0.c |
| 72 | dbusbind.o: dbusbind.c termhooks.h frame.h keyboard.h lisp.h $(config_h) | 72 | dbusbind.o: dbusbind.c termhooks.h frame.h keyboard.h lisp.h $(config_h) |
| 73 | dired.o: dired.c commands.h buffer.h lisp.h $(config_h) character.h charset.h \ | 73 | dired.o: dired.c commands.h buffer.h lisp.h $(config_h) character.h charset.h \ |
| 74 | coding.h regex.h systime.h blockinput.h atimer.h composite.h \ | 74 | coding.h regex-emacs.h systime.h blockinput.h atimer.h composite.h \ |
| 75 | ../lib/filemode.h ../lib/unistd.h globals.h | 75 | ../lib/filemode.h ../lib/unistd.h globals.h |
| 76 | dispnew.o: dispnew.c systime.h commands.h process.h frame.h coding.h \ | 76 | dispnew.o: dispnew.c systime.h commands.h process.h frame.h coding.h \ |
| 77 | window.h buffer.h termchar.h termopts.h termhooks.h cm.h \ | 77 | window.h buffer.h termchar.h termopts.h termhooks.h cm.h \ |
| @@ -169,20 +169,21 @@ process.o: process.c process.h buffer.h window.h termhooks.h termopts.h \ | |||
| 169 | blockinput.h atimer.h coding.h msdos.h nsterm.h composite.h \ | 169 | blockinput.h atimer.h coding.h msdos.h nsterm.h composite.h \ |
| 170 | keyboard.h lisp.h globals.h $(config_h) character.h xgselect.h sysselect.h \ | 170 | keyboard.h lisp.h globals.h $(config_h) character.h xgselect.h sysselect.h \ |
| 171 | ../lib/unistd.h gnutls.h | 171 | ../lib/unistd.h gnutls.h |
| 172 | regex.o: regex.c syntax.h buffer.h lisp.h globals.h $(config_h) regex.h \ | 172 | regex-emacs.o: regex-emacs.c syntax.h buffer.h lisp.h globals.h \ |
| 173 | $(config_h) regex-emacs.h \ | ||
| 173 | category.h character.h | 174 | category.h character.h |
| 174 | region-cache.o: region-cache.c buffer.h region-cache.h \ | 175 | region-cache.o: region-cache.c buffer.h region-cache.h \ |
| 175 | lisp.h globals.h $(config_h) | 176 | lisp.h globals.h $(config_h) |
| 176 | scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \ | 177 | scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \ |
| 177 | termhooks.h lisp.h globals.h $(config_h) systime.h coding.h composite.h \ | 178 | termhooks.h lisp.h globals.h $(config_h) systime.h coding.h composite.h \ |
| 178 | window.h | 179 | window.h |
| 179 | search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \ | 180 | search.o: search.c regex-emacs.h commands.h buffer.h region-cache.h syntax.h \ |
| 180 | blockinput.h atimer.h systime.h category.h character.h charset.h \ | 181 | blockinput.h atimer.h systime.h category.h character.h charset.h \ |
| 181 | $(INTERVALS_H) lisp.h globals.h $(config_h) | 182 | $(INTERVALS_H) lisp.h globals.h $(config_h) |
| 182 | sound.o: sound.c dispextern.h syssignal.h lisp.h globals.h $(config_h) \ | 183 | sound.o: sound.c dispextern.h syssignal.h lisp.h globals.h $(config_h) \ |
| 183 | atimer.h systime.h ../lib/unistd.h msdos.h | 184 | atimer.h systime.h ../lib/unistd.h msdos.h |
| 184 | syntax.o: syntax.c syntax.h buffer.h commands.h category.h character.h \ | 185 | syntax.o: syntax.c syntax.h buffer.h commands.h category.h character.h \ |
| 185 | keymap.h regex.h $(INTERVALS_H) lisp.h globals.h $(config_h) | 186 | keymap.h regex-emacs.h $(INTERVALS_H) lisp.h globals.h $(config_h) |
| 186 | sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \ | 187 | sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \ |
| 187 | process.h dispextern.h termhooks.h termchar.h termopts.h coding.h \ | 188 | process.h dispextern.h termhooks.h termchar.h termopts.h coding.h \ |
| 188 | frame.h atimer.h window.h msdos.h dosfns.h keyboard.h cm.h lisp.h \ | 189 | frame.h atimer.h window.h msdos.h dosfns.h keyboard.h cm.h lisp.h \ |
diff --git a/src/dired.c b/src/dired.c index 3bb5997bd69..b92cd2b9f01 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -1058,7 +1058,7 @@ return a list with one element, taken from `user-real-login-name'. */) | |||
| 1058 | 1058 | ||
| 1059 | endpwent (); | 1059 | endpwent (); |
| 1060 | #endif | 1060 | #endif |
| 1061 | if (EQ (users, Qnil)) | 1061 | if (NILP (users)) |
| 1062 | /* At least current user is always known. */ | 1062 | /* At least current user is always known. */ |
| 1063 | users = list1 (Vuser_real_login_name); | 1063 | users = list1 (Vuser_real_login_name); |
| 1064 | return users; | 1064 | return users; |
diff --git a/src/dispextern.h b/src/dispextern.h index 944a37d4889..9cc65f6a3d4 100644 --- a/src/dispextern.h +++ b/src/dispextern.h | |||
| @@ -2482,7 +2482,7 @@ struct it | |||
| 2482 | 2482 | ||
| 2483 | If `what' is anything else, these two are undefined (will | 2483 | If `what' is anything else, these two are undefined (will |
| 2484 | probably hold values for the last IT_CHARACTER or IT_COMPOSITION | 2484 | probably hold values for the last IT_CHARACTER or IT_COMPOSITION |
| 2485 | traversed by the iterator. | 2485 | traversed by the iterator). |
| 2486 | 2486 | ||
| 2487 | The values are updated by get_next_display_element, so they are | 2487 | The values are updated by get_next_display_element, so they are |
| 2488 | out of sync with the value returned by IT_CHARPOS between the | 2488 | out of sync with the value returned by IT_CHARPOS between the |
diff --git a/src/editfns.c b/src/editfns.c index f9157cd8449..b1b9eb632f3 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -3256,21 +3256,9 @@ differences between the two buffers. */) | |||
| 3256 | Instead, we announce a single modification for the entire | 3256 | Instead, we announce a single modification for the entire |
| 3257 | modified region. But don't do that if the caller inhibited | 3257 | modified region. But don't do that if the caller inhibited |
| 3258 | modification hooks, because then they don't want that. */ | 3258 | modification hooks, because then they don't want that. */ |
| 3259 | ptrdiff_t from, to; | ||
| 3260 | if (!inhibit_modification_hooks) | 3259 | if (!inhibit_modification_hooks) |
| 3261 | { | 3260 | { |
| 3262 | ptrdiff_t k, l; | 3261 | prepare_to_modify_buffer (BEGV, ZV, NULL); |
| 3263 | |||
| 3264 | /* Find the first character position to be changed. */ | ||
| 3265 | for (k = 0; k < size_a && !bit_is_set (ctx.deletions, k); k++) | ||
| 3266 | ; | ||
| 3267 | from = BEGV + k; | ||
| 3268 | |||
| 3269 | /* Find the last character position to be changed. */ | ||
| 3270 | for (l = size_a; l > 0 && !bit_is_set (ctx.deletions, l - 1); l--) | ||
| 3271 | ; | ||
| 3272 | to = BEGV + l; | ||
| 3273 | prepare_to_modify_buffer (from, to, NULL); | ||
| 3274 | specbind (Qinhibit_modification_hooks, Qt); | 3262 | specbind (Qinhibit_modification_hooks, Qt); |
| 3275 | modification_hooks_inhibited = true; | 3263 | modification_hooks_inhibited = true; |
| 3276 | } | 3264 | } |
| @@ -3322,9 +3310,8 @@ differences between the two buffers. */) | |||
| 3322 | 3310 | ||
| 3323 | if (modification_hooks_inhibited) | 3311 | if (modification_hooks_inhibited) |
| 3324 | { | 3312 | { |
| 3325 | ptrdiff_t updated_to = to + ZV - BEGV - size_a; | 3313 | signal_after_change (BEGV, size_a, ZV - BEGV); |
| 3326 | signal_after_change (from, to - from, updated_to - from); | 3314 | update_compositions (BEGV, ZV, CHECK_INSIDE); |
| 3327 | update_compositions (from, updated_to, CHECK_INSIDE); | ||
| 3328 | } | 3315 | } |
| 3329 | 3316 | ||
| 3330 | return Qnil; | 3317 | return Qnil; |
| @@ -4195,14 +4182,14 @@ Nth argument is substituted instead of the next one. A format can | |||
| 4195 | contain either numbered or unnumbered %-sequences but not both, except | 4182 | contain either numbered or unnumbered %-sequences but not both, except |
| 4196 | that %% can be mixed with numbered %-sequences. | 4183 | that %% can be mixed with numbered %-sequences. |
| 4197 | 4184 | ||
| 4198 | The + flag character inserts a + before any positive number, while a | 4185 | The + flag character inserts a + before any nonnegative number, while a |
| 4199 | space inserts a space before any positive number; these flags only | 4186 | space inserts a space before any nonnegative number; these flags |
| 4200 | affect %d, %e, %f, and %g sequences, and the + flag takes precedence. | 4187 | affect only numeric %-sequences, and the + flag takes precedence. |
| 4201 | The - and 0 flags affect the width specifier, as described below. | 4188 | The - and 0 flags affect the width specifier, as described below. |
| 4202 | 4189 | ||
| 4203 | The # flag means to use an alternate display form for %o, %x, %X, %e, | 4190 | The # flag means to use an alternate display form for %o, %x, %X, %e, |
| 4204 | %f, and %g sequences: for %o, it ensures that the result begins with | 4191 | %f, and %g sequences: for %o, it ensures that the result begins with |
| 4205 | \"0\"; for %x and %X, it prefixes the result with \"0x\" or \"0X\"; | 4192 | \"0\"; for %x and %X, it prefixes nonzero results with \"0x\" or \"0X\"; |
| 4206 | for %e and %f, it causes a decimal point to be included even if the | 4193 | for %e and %f, it causes a decimal point to be included even if the |
| 4207 | precision is zero; for %g, it causes a decimal point to be | 4194 | precision is zero; for %g, it causes a decimal point to be |
| 4208 | included even if the precision is zero, and also forces trailing | 4195 | included even if the precision is zero, and also forces trailing |
| @@ -4756,10 +4743,22 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) | |||
| 4756 | } | 4743 | } |
| 4757 | else | 4744 | else |
| 4758 | { | 4745 | { |
| 4759 | /* Don't sign-extend for octal or hex printing. */ | ||
| 4760 | uprintmax_t x; | 4746 | uprintmax_t x; |
| 4761 | if (FIXNUMP (arg)) | 4747 | bool negative; |
| 4762 | x = XUFIXNUM (arg); | 4748 | if (INTEGERP (arg)) |
| 4749 | { | ||
| 4750 | if (binary_as_unsigned) | ||
| 4751 | { | ||
| 4752 | x = XUINT (arg); | ||
| 4753 | negative = false; | ||
| 4754 | } | ||
| 4755 | else | ||
| 4756 | { | ||
| 4757 | EMACS_INT i = XINT (arg); | ||
| 4758 | negative = i < 0; | ||
| 4759 | x = negative ? -i : i; | ||
| 4760 | } | ||
| 4761 | } | ||
| 4763 | else | 4762 | else |
| 4764 | { | 4763 | { |
| 4765 | double d = XFLOAT_DATA (arg); | 4764 | double d = XFLOAT_DATA (arg); |
| @@ -4767,8 +4766,13 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) | |||
| 4767 | if (! (0 <= d && d < uprintmax + 1)) | 4766 | if (! (0 <= d && d < uprintmax + 1)) |
| 4768 | xsignal1 (Qoverflow_error, arg); | 4767 | xsignal1 (Qoverflow_error, arg); |
| 4769 | x = d; | 4768 | x = d; |
| 4769 | negative = false; | ||
| 4770 | } | 4770 | } |
| 4771 | sprintf_bytes = sprintf (sprintf_buf, convspec, prec, x); | 4771 | sprintf_buf[0] = negative ? '-' : plus_flag ? '+' : ' '; |
| 4772 | bool signedp = negative | plus_flag | space_flag; | ||
| 4773 | sprintf_bytes = sprintf (sprintf_buf + signedp, | ||
| 4774 | convspec, prec, x); | ||
| 4775 | sprintf_bytes += signedp; | ||
| 4772 | } | 4776 | } |
| 4773 | 4777 | ||
| 4774 | /* Now the length of the formatted item is known, except it omits | 4778 | /* Now the length of the formatted item is known, except it omits |
| @@ -5578,6 +5582,22 @@ functions if all the text being accessed has this property. */); | |||
| 5578 | DEFVAR_LISP ("operating-system-release", Voperating_system_release, | 5582 | DEFVAR_LISP ("operating-system-release", Voperating_system_release, |
| 5579 | doc: /* The release of the operating system Emacs is running on. */); | 5583 | doc: /* The release of the operating system Emacs is running on. */); |
| 5580 | 5584 | ||
| 5585 | DEFVAR_BOOL ("binary-as-unsigned", | ||
| 5586 | binary_as_unsigned, | ||
| 5587 | doc: /* Non-nil means `format' %x and %o treat integers as unsigned. | ||
| 5588 | This has machine-dependent results. Nil means to treat integers as | ||
| 5589 | signed, which is portable; for example, if N is a negative integer, | ||
| 5590 | (read (format "#x%x") N) returns N only when this variable is nil. | ||
| 5591 | |||
| 5592 | This variable is experimental; email 32252@debbugs.gnu.org if you need | ||
| 5593 | it to be non-nil. */); | ||
| 5594 | /* For now, default to true if bignums exist, false in traditional Emacs. */ | ||
| 5595 | #ifdef lisp_h_FIXNUMP | ||
| 5596 | binary_as_unsigned = false; | ||
| 5597 | #else | ||
| 5598 | binary_as_unsigned = true; | ||
| 5599 | #endif | ||
| 5600 | |||
| 5581 | defsubr (&Spropertize); | 5601 | defsubr (&Spropertize); |
| 5582 | defsubr (&Schar_equal); | 5602 | defsubr (&Schar_equal); |
| 5583 | defsubr (&Sgoto_char); | 5603 | defsubr (&Sgoto_char); |
diff --git a/src/emacs.c b/src/emacs.c index dc62ce80667..97205d2b2a2 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -84,7 +84,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 84 | #include "composite.h" | 84 | #include "composite.h" |
| 85 | #include "dispextern.h" | 85 | #include "dispextern.h" |
| 86 | #include "ptr-bounds.h" | 86 | #include "ptr-bounds.h" |
| 87 | #include "regex.h" | 87 | #include "regex-emacs.h" |
| 88 | #include "sheap.h" | 88 | #include "sheap.h" |
| 89 | #include "syntax.h" | 89 | #include "syntax.h" |
| 90 | #include "sysselect.h" | 90 | #include "sysselect.h" |
| @@ -862,9 +862,9 @@ main (int argc, char **argv) | |||
| 862 | { | 862 | { |
| 863 | rlim_t lim = rlim.rlim_cur; | 863 | rlim_t lim = rlim.rlim_cur; |
| 864 | 864 | ||
| 865 | /* Approximate the amount regex.c needs per unit of | 865 | /* Approximate the amount regex-emacs.c needs per unit of |
| 866 | emacs_re_max_failures, then add 33% to cover the size of the | 866 | emacs_re_max_failures, then add 33% to cover the size of the |
| 867 | smaller stacks that regex.c successively allocates and | 867 | smaller stacks that regex-emacs.c successively allocates and |
| 868 | discards on its way to the maximum. */ | 868 | discards on its way to the maximum. */ |
| 869 | int min_ratio = 20 * sizeof (char *); | 869 | int min_ratio = 20 * sizeof (char *); |
| 870 | int ratio = min_ratio + min_ratio / 3; | 870 | int ratio = min_ratio + min_ratio / 3; |
| @@ -903,7 +903,7 @@ main (int argc, char **argv) | |||
| 903 | lim = newlim; | 903 | lim = newlim; |
| 904 | } | 904 | } |
| 905 | } | 905 | } |
| 906 | /* If the stack is big enough, let regex.c more of it before | 906 | /* If the stack is big enough, let regex-emacs.c more of it before |
| 907 | falling back to heap allocation. */ | 907 | falling back to heap allocation. */ |
| 908 | emacs_re_safe_alloca = max | 908 | emacs_re_safe_alloca = max |
| 909 | (min (lim - extra, SIZE_MAX) * (min_ratio / ratio), | 909 | (min (lim - extra, SIZE_MAX) * (min_ratio / ratio), |
| @@ -2035,6 +2035,10 @@ all of which are called before Emacs is actually killed. */ | |||
| 2035 | { | 2035 | { |
| 2036 | int exit_code; | 2036 | int exit_code; |
| 2037 | 2037 | ||
| 2038 | #ifdef HAVE_LIBSYSTEMD | ||
| 2039 | sd_notify(0, "STOPPING=1"); | ||
| 2040 | #endif /* HAVE_LIBSYSTEMD */ | ||
| 2041 | |||
| 2038 | /* Fsignal calls emacs_abort () if it sees that waiting_for_input is | 2042 | /* Fsignal calls emacs_abort () if it sees that waiting_for_input is |
| 2039 | set. */ | 2043 | set. */ |
| 2040 | waiting_for_input = 0; | 2044 | waiting_for_input = 0; |
| @@ -2495,6 +2499,13 @@ from the parent process and its tty file descriptors. */) | |||
| 2495 | error ("This function can only be called after loading the init files"); | 2499 | error ("This function can only be called after loading the init files"); |
| 2496 | #ifndef WINDOWSNT | 2500 | #ifndef WINDOWSNT |
| 2497 | 2501 | ||
| 2502 | if (daemon_type == 1) | ||
| 2503 | { | ||
| 2504 | #ifdef HAVE_LIBSYSTEMD | ||
| 2505 | sd_notify(0, "READY=1"); | ||
| 2506 | #endif /* HAVE_LIBSYSTEMD */ | ||
| 2507 | } | ||
| 2508 | |||
| 2498 | if (daemon_type == 2) | 2509 | if (daemon_type == 2) |
| 2499 | { | 2510 | { |
| 2500 | int nfd; | 2511 | int nfd; |
diff --git a/src/eval.c b/src/eval.c index f7d4d5be2aa..8745ba9ef99 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -1732,28 +1732,12 @@ xsignal3 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2, Lisp_Obj | |||
| 1732 | } | 1732 | } |
| 1733 | 1733 | ||
| 1734 | /* Signal `error' with message S, and additional arg ARG. | 1734 | /* Signal `error' with message S, and additional arg ARG. |
| 1735 | If ARG is not a genuine list, make it a one-element list. */ | 1735 | If ARG is not a proper list, make it a one-element list. */ |
| 1736 | 1736 | ||
| 1737 | void | 1737 | void |
| 1738 | signal_error (const char *s, Lisp_Object arg) | 1738 | signal_error (const char *s, Lisp_Object arg) |
| 1739 | { | 1739 | { |
| 1740 | Lisp_Object tortoise, hare; | 1740 | if (NILP (Fproper_list_p (arg))) |
| 1741 | |||
| 1742 | hare = tortoise = arg; | ||
| 1743 | while (CONSP (hare)) | ||
| 1744 | { | ||
| 1745 | hare = XCDR (hare); | ||
| 1746 | if (!CONSP (hare)) | ||
| 1747 | break; | ||
| 1748 | |||
| 1749 | hare = XCDR (hare); | ||
| 1750 | tortoise = XCDR (tortoise); | ||
| 1751 | |||
| 1752 | if (EQ (hare, tortoise)) | ||
| 1753 | break; | ||
| 1754 | } | ||
| 1755 | |||
| 1756 | if (!NILP (hare)) | ||
| 1757 | arg = list1 (arg); | 1741 | arg = list1 (arg); |
| 1758 | 1742 | ||
| 1759 | xsignal (Qerror, Fcons (build_string (s), arg)); | 1743 | xsignal (Qerror, Fcons (build_string (s), arg)); |
diff --git a/src/fileio.c b/src/fileio.c index 14089dcf49a..04e763f83b5 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -196,8 +196,8 @@ check_writable (const char *filename, int amode) | |||
| 196 | list before reporting it; this saves report_file_errno's caller the | 196 | list before reporting it; this saves report_file_errno's caller the |
| 197 | trouble of preserving errno before calling list1. */ | 197 | trouble of preserving errno before calling list1. */ |
| 198 | 198 | ||
| 199 | void | 199 | Lisp_Object |
| 200 | report_file_errno (char const *string, Lisp_Object name, int errorno) | 200 | get_file_errno_data (char const *string, Lisp_Object name, int errorno) |
| 201 | { | 201 | { |
| 202 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | 202 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); |
| 203 | char *str = emacs_strerror (errorno); | 203 | char *str = emacs_strerror (errorno); |
| @@ -207,10 +207,18 @@ report_file_errno (char const *string, Lisp_Object name, int errorno) | |||
| 207 | Lisp_Object errdata = Fcons (errstring, data); | 207 | Lisp_Object errdata = Fcons (errstring, data); |
| 208 | 208 | ||
| 209 | if (errorno == EEXIST) | 209 | if (errorno == EEXIST) |
| 210 | xsignal (Qfile_already_exists, errdata); | 210 | return Fcons (Qfile_already_exists, errdata); |
| 211 | else | 211 | else |
| 212 | xsignal (errorno == ENOENT ? Qfile_missing : Qfile_error, | 212 | return Fcons (errorno == ENOENT ? Qfile_missing : Qfile_error, |
| 213 | Fcons (build_string (string), errdata)); | 213 | Fcons (build_string (string), errdata)); |
| 214 | } | ||
| 215 | |||
| 216 | void | ||
| 217 | report_file_errno (char const *string, Lisp_Object name, int errorno) | ||
| 218 | { | ||
| 219 | Lisp_Object data = get_file_errno_data (string, name, errorno); | ||
| 220 | |||
| 221 | xsignal (Fcar (data), Fcdr (data)); | ||
| 214 | } | 222 | } |
| 215 | 223 | ||
| 216 | /* Signal a file-access failure that set errno. STRING describes the | 224 | /* Signal a file-access failure that set errno. STRING describes the |
| @@ -2288,6 +2296,21 @@ The arg must be a string. */) | |||
| 2288 | if (!NILP (handler)) | 2296 | if (!NILP (handler)) |
| 2289 | return call2 (handler, Qfile_name_case_insensitive_p, filename); | 2297 | return call2 (handler, Qfile_name_case_insensitive_p, filename); |
| 2290 | 2298 | ||
| 2299 | /* If the file doesn't exist, move up the filesystem tree until we | ||
| 2300 | reach an existing directory or the root. */ | ||
| 2301 | if (NILP (Ffile_exists_p (filename))) | ||
| 2302 | { | ||
| 2303 | filename = Ffile_name_directory (filename); | ||
| 2304 | while (NILP (Ffile_exists_p (filename))) | ||
| 2305 | { | ||
| 2306 | Lisp_Object newname = expand_and_dir_to_file (filename); | ||
| 2307 | /* Avoid infinite loop if the root is reported as non-existing | ||
| 2308 | (impossible?). */ | ||
| 2309 | if (!NILP (Fstring_equal (newname, filename))) | ||
| 2310 | break; | ||
| 2311 | filename = newname; | ||
| 2312 | } | ||
| 2313 | } | ||
| 2291 | filename = ENCODE_FILE (filename); | 2314 | filename = ENCODE_FILE (filename); |
| 2292 | return file_name_case_insensitive_p (SSDATA (filename)) ? Qt : Qnil; | 2315 | return file_name_case_insensitive_p (SSDATA (filename)) ? Qt : Qnil; |
| 2293 | } | 2316 | } |
| @@ -5714,7 +5737,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) | |||
| 5714 | spare the user annoying messages. */ | 5737 | spare the user annoying messages. */ |
| 5715 | && XFIXNAT (BVAR (b, save_length)) > 5000 | 5738 | && XFIXNAT (BVAR (b, save_length)) > 5000 |
| 5716 | /* These messages are frequent and annoying for `*mail*'. */ | 5739 | /* These messages are frequent and annoying for `*mail*'. */ |
| 5717 | && !EQ (BVAR (b, filename), Qnil) | 5740 | && !NILP (BVAR (b, filename)) |
| 5718 | && NILP (no_message)) | 5741 | && NILP (no_message)) |
| 5719 | { | 5742 | { |
| 5720 | /* It has shrunk too much; turn off auto-saving here. */ | 5743 | /* It has shrunk too much; turn off auto-saving here. */ |
diff --git a/src/floatfns.c b/src/floatfns.c index f8463f32445..bbf7df4db37 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -47,13 +47,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 47 | 47 | ||
| 48 | #include <count-leading-zeros.h> | 48 | #include <count-leading-zeros.h> |
| 49 | 49 | ||
| 50 | #ifndef isfinite | ||
| 51 | # define isfinite(x) ((x) - (x) == 0) | ||
| 52 | #endif | ||
| 53 | #ifndef isnan | ||
| 54 | # define isnan(x) ((x) != (x)) | ||
| 55 | #endif | ||
| 56 | |||
| 57 | /* Check that X is a floating point number. */ | 50 | /* Check that X is a floating point number. */ |
| 58 | 51 | ||
| 59 | static void | 52 | static void |
| @@ -144,6 +144,28 @@ which is at least the number of distinct elements. */) | |||
| 144 | return make_fixnum_or_float (len); | 144 | return make_fixnum_or_float (len); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | DEFUN ("proper-list-p", Fproper_list_p, Sproper_list_p, 1, 1, 0, | ||
| 148 | doc: /* Return OBJECT's length if it is a proper list, nil otherwise. | ||
| 149 | A proper list is neither circular nor dotted (i.e., its last cdr is nil). */ | ||
| 150 | attributes: const) | ||
| 151 | (Lisp_Object object) | ||
| 152 | { | ||
| 153 | intptr_t len = 0; | ||
| 154 | Lisp_Object last_tail = object; | ||
| 155 | Lisp_Object tail = object; | ||
| 156 | FOR_EACH_TAIL_SAFE (tail) | ||
| 157 | { | ||
| 158 | len++; | ||
| 159 | rarely_quit (len); | ||
| 160 | last_tail = XCDR (tail); | ||
| 161 | } | ||
| 162 | if (!NILP (last_tail)) | ||
| 163 | return Qnil; | ||
| 164 | if (MOST_POSITIVE_FIXNUM < len) | ||
| 165 | xsignal0 (Qoverflow_error); | ||
| 166 | return make_number (len); | ||
| 167 | } | ||
| 168 | |||
| 147 | DEFUN ("string-bytes", Fstring_bytes, Sstring_bytes, 1, 1, 0, | 169 | DEFUN ("string-bytes", Fstring_bytes, Sstring_bytes, 1, 1, 0, |
| 148 | doc: /* Return the number of bytes in STRING. | 170 | doc: /* Return the number of bytes in STRING. |
| 149 | If STRING is multibyte, this may be greater than the length of STRING. */) | 171 | If STRING is multibyte, this may be greater than the length of STRING. */) |
| @@ -718,7 +740,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 718 | val = make_uninit_string (result_len); | 740 | val = make_uninit_string (result_len); |
| 719 | 741 | ||
| 720 | /* In `append', if all but last arg are nil, return last arg. */ | 742 | /* In `append', if all but last arg are nil, return last arg. */ |
| 721 | if (target_type == Lisp_Cons && EQ (val, Qnil)) | 743 | if (target_type == Lisp_Cons && NILP (val)) |
| 722 | return last_tail; | 744 | return last_tail; |
| 723 | 745 | ||
| 724 | /* Copy the contents of the args into the result. */ | 746 | /* Copy the contents of the args into the result. */ |
| @@ -1419,6 +1441,29 @@ DEFUN ("elt", Felt, Selt, 2, 2, 0, | |||
| 1419 | return Faref (sequence, n); | 1441 | return Faref (sequence, n); |
| 1420 | } | 1442 | } |
| 1421 | 1443 | ||
| 1444 | enum { WORDS_PER_DOUBLE = (sizeof (double) / sizeof (EMACS_UINT) | ||
| 1445 | + (sizeof (double) % sizeof (EMACS_UINT) != 0)) }; | ||
| 1446 | union double_and_words | ||
| 1447 | { | ||
| 1448 | double val; | ||
| 1449 | EMACS_UINT word[WORDS_PER_DOUBLE]; | ||
| 1450 | }; | ||
| 1451 | |||
| 1452 | /* Return true if X and Y are the same floating-point value. | ||
| 1453 | This looks at X's and Y's representation, since (unlike '==') | ||
| 1454 | it returns true if X and Y are the same NaN. */ | ||
| 1455 | static bool | ||
| 1456 | same_float (Lisp_Object x, Lisp_Object y) | ||
| 1457 | { | ||
| 1458 | union double_and_words | ||
| 1459 | xu = { .val = XFLOAT_DATA (x) }, | ||
| 1460 | yu = { .val = XFLOAT_DATA (y) }; | ||
| 1461 | EMACS_UINT neql = 0; | ||
| 1462 | for (int i = 0; i < WORDS_PER_DOUBLE; i++) | ||
| 1463 | neql |= xu.word[i] ^ yu.word[i]; | ||
| 1464 | return !neql; | ||
| 1465 | } | ||
| 1466 | |||
| 1422 | DEFUN ("member", Fmember, Smember, 2, 2, 0, | 1467 | DEFUN ("member", Fmember, Smember, 2, 2, 0, |
| 1423 | doc: /* Return non-nil if ELT is an element of LIST. Comparison done with `equal'. | 1468 | doc: /* Return non-nil if ELT is an element of LIST. Comparison done with `equal'. |
| 1424 | The value is actually the tail of LIST whose car is ELT. */) | 1469 | The value is actually the tail of LIST whose car is ELT. */) |
| @@ -1457,7 +1502,7 @@ The value is actually the tail of LIST whose car is ELT. */) | |||
| 1457 | FOR_EACH_TAIL (tail) | 1502 | FOR_EACH_TAIL (tail) |
| 1458 | { | 1503 | { |
| 1459 | Lisp_Object tem = XCAR (tail); | 1504 | Lisp_Object tem = XCAR (tail); |
| 1460 | if (FLOATP (tem) && equal_no_quit (elt, tem)) | 1505 | if (FLOATP (tem) && same_float (elt, tem)) |
| 1461 | return tail; | 1506 | return tail; |
| 1462 | } | 1507 | } |
| 1463 | CHECK_LIST_END (tail, list); | 1508 | CHECK_LIST_END (tail, list); |
| @@ -2170,11 +2215,15 @@ The PLIST is modified by side effects. */) | |||
| 2170 | } | 2215 | } |
| 2171 | 2216 | ||
| 2172 | DEFUN ("eql", Feql, Seql, 2, 2, 0, | 2217 | DEFUN ("eql", Feql, Seql, 2, 2, 0, |
| 2173 | doc: /* Return t if the two args are the same Lisp object. | 2218 | doc: /* Return t if the two args are `eq' or are indistinguishable numbers. |
| 2174 | Floating-point numbers of equal value are `eql', but they may not be `eq'. */) | 2219 | Floating-point values with the same sign, exponent and fraction are `eql'. |
| 2220 | This differs from numeric comparison: (eql 0.0 -0.0) returns nil and | ||
| 2221 | \(eql 0.0e+NaN 0.0e+NaN) returns t, whereas `=' does the opposite. */) | ||
| 2175 | (Lisp_Object obj1, Lisp_Object obj2) | 2222 | (Lisp_Object obj1, Lisp_Object obj2) |
| 2176 | { | 2223 | { |
| 2177 | if (FLOATP (obj1) || BIGNUMP (obj1)) | 2224 | if (FLOATP (obj1)) |
| 2225 | return FLOATP (obj2) && same_float (obj1, obj2) ? Qt : Qnil; | ||
| 2226 | else if (BIGNUMP (obj1)) | ||
| 2178 | return equal_no_quit (obj1, obj2) ? Qt : Qnil; | 2227 | return equal_no_quit (obj1, obj2) ? Qt : Qnil; |
| 2179 | else | 2228 | else |
| 2180 | return EQ (obj1, obj2) ? Qt : Qnil; | 2229 | return EQ (obj1, obj2) ? Qt : Qnil; |
| @@ -2185,8 +2234,8 @@ DEFUN ("equal", Fequal, Sequal, 2, 2, 0, | |||
| 2185 | They must have the same data type. | 2234 | They must have the same data type. |
| 2186 | Conses are compared by comparing the cars and the cdrs. | 2235 | Conses are compared by comparing the cars and the cdrs. |
| 2187 | Vectors and strings are compared element by element. | 2236 | Vectors and strings are compared element by element. |
| 2188 | Numbers are compared by value, but integers cannot equal floats. | 2237 | Numbers are compared via `eql', so integers do not equal floats. |
| 2189 | (Use `=' if you want integers and floats to be able to be equal.) | 2238 | \(Use `=' if you want integers and floats to be able to be equal.) |
| 2190 | Symbols must match exactly. */) | 2239 | Symbols must match exactly. */) |
| 2191 | (Lisp_Object o1, Lisp_Object o2) | 2240 | (Lisp_Object o1, Lisp_Object o2) |
| 2192 | { | 2241 | { |
| @@ -2266,13 +2315,7 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind, | |||
| 2266 | switch (XTYPE (o1)) | 2315 | switch (XTYPE (o1)) |
| 2267 | { | 2316 | { |
| 2268 | case Lisp_Float: | 2317 | case Lisp_Float: |
| 2269 | { | 2318 | return same_float (o1, o2); |
| 2270 | double d1 = XFLOAT_DATA (o1); | ||
| 2271 | double d2 = XFLOAT_DATA (o2); | ||
| 2272 | /* If d is a NaN, then d != d. Two NaNs should be `equal' even | ||
| 2273 | though they are not =. */ | ||
| 2274 | return d1 == d2 || (d1 != d1 && d2 != d2); | ||
| 2275 | } | ||
| 2276 | 2319 | ||
| 2277 | case Lisp_Cons: | 2320 | case Lisp_Cons: |
| 2278 | if (equal_kind == EQUAL_NO_QUIT) | 2321 | if (equal_kind == EQUAL_NO_QUIT) |
| @@ -3708,9 +3751,8 @@ HASH_INDEX (struct Lisp_Hash_Table *h, ptrdiff_t idx) | |||
| 3708 | return XFIXNUM (AREF (h->index, idx)); | 3751 | return XFIXNUM (AREF (h->index, idx)); |
| 3709 | } | 3752 | } |
| 3710 | 3753 | ||
| 3711 | /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code | 3754 | /* Compare KEY1 and KEY2 in hash table HT using `eql'. Value is true |
| 3712 | HASH2 in hash table H using `eql'. Value is true if KEY1 and | 3755 | if KEY1 and KEY2 are the same. KEY1 and KEY2 must not be eq. */ |
| 3713 | KEY2 are the same. */ | ||
| 3714 | 3756 | ||
| 3715 | static bool | 3757 | static bool |
| 3716 | cmpfn_eql (struct hash_table_test *ht, | 3758 | cmpfn_eql (struct hash_table_test *ht, |
| @@ -3719,7 +3761,7 @@ cmpfn_eql (struct hash_table_test *ht, | |||
| 3719 | { | 3761 | { |
| 3720 | if (FLOATP (key1) | 3762 | if (FLOATP (key1) |
| 3721 | && FLOATP (key2) | 3763 | && FLOATP (key2) |
| 3722 | && XFLOAT_DATA (key1) == XFLOAT_DATA (key2)) | 3764 | && same_float (key1, key2)) |
| 3723 | return true; | 3765 | return true; |
| 3724 | return (BIGNUMP (key1) | 3766 | return (BIGNUMP (key1) |
| 3725 | && BIGNUMP (key2) | 3767 | && BIGNUMP (key2) |
| @@ -3727,9 +3769,8 @@ cmpfn_eql (struct hash_table_test *ht, | |||
| 3727 | } | 3769 | } |
| 3728 | 3770 | ||
| 3729 | 3771 | ||
| 3730 | /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code | 3772 | /* Compare KEY1 and KEY2 in hash table HT using `equal'. Value is |
| 3731 | HASH2 in hash table H using `equal'. Value is true if KEY1 and | 3773 | true if KEY1 and KEY2 are the same. */ |
| 3732 | KEY2 are the same. */ | ||
| 3733 | 3774 | ||
| 3734 | static bool | 3775 | static bool |
| 3735 | cmpfn_equal (struct hash_table_test *ht, | 3776 | cmpfn_equal (struct hash_table_test *ht, |
| @@ -3740,9 +3781,8 @@ cmpfn_equal (struct hash_table_test *ht, | |||
| 3740 | } | 3781 | } |
| 3741 | 3782 | ||
| 3742 | 3783 | ||
| 3743 | /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code | 3784 | /* Compare KEY1 and KEY2 in hash table HT using HT->user_cmp_function. |
| 3744 | HASH2 in hash table H using H->user_cmp_function. Value is true | 3785 | Value is true if KEY1 and KEY2 are the same. */ |
| 3745 | if KEY1 and KEY2 are the same. */ | ||
| 3746 | 3786 | ||
| 3747 | static bool | 3787 | static bool |
| 3748 | cmpfn_user_defined (struct hash_table_test *ht, | 3788 | cmpfn_user_defined (struct hash_table_test *ht, |
| @@ -4336,18 +4376,8 @@ static EMACS_UINT | |||
| 4336 | sxhash_float (double val) | 4376 | sxhash_float (double val) |
| 4337 | { | 4377 | { |
| 4338 | EMACS_UINT hash = 0; | 4378 | EMACS_UINT hash = 0; |
| 4339 | enum { | 4379 | union double_and_words u = { .val = val }; |
| 4340 | WORDS_PER_DOUBLE = (sizeof val / sizeof hash | 4380 | for (int i = 0; i < WORDS_PER_DOUBLE; i++) |
| 4341 | + (sizeof val % sizeof hash != 0)) | ||
| 4342 | }; | ||
| 4343 | union { | ||
| 4344 | double val; | ||
| 4345 | EMACS_UINT word[WORDS_PER_DOUBLE]; | ||
| 4346 | } u; | ||
| 4347 | int i; | ||
| 4348 | u.val = val; | ||
| 4349 | memset (&u.val + 1, 0, sizeof u - sizeof u.val); | ||
| 4350 | for (i = 0; i < WORDS_PER_DOUBLE; i++) | ||
| 4351 | hash = sxhash_combine (hash, u.word[i]); | 4381 | hash = sxhash_combine (hash, u.word[i]); |
| 4352 | return SXHASH_REDUCE (hash); | 4382 | return SXHASH_REDUCE (hash); |
| 4353 | } | 4383 | } |
| @@ -5319,6 +5349,7 @@ this variable. */); | |||
| 5319 | defsubr (&Srandom); | 5349 | defsubr (&Srandom); |
| 5320 | defsubr (&Slength); | 5350 | defsubr (&Slength); |
| 5321 | defsubr (&Ssafe_length); | 5351 | defsubr (&Ssafe_length); |
| 5352 | defsubr (&Sproper_list_p); | ||
| 5322 | defsubr (&Sstring_bytes); | 5353 | defsubr (&Sstring_bytes); |
| 5323 | defsubr (&Sstring_distance); | 5354 | defsubr (&Sstring_distance); |
| 5324 | defsubr (&Sstring_equal); | 5355 | defsubr (&Sstring_equal); |
diff --git a/src/frame.c b/src/frame.c index c2e3d4b6190..f9a73c8ffef 100644 --- a/src/frame.c +++ b/src/frame.c | |||
| @@ -139,14 +139,9 @@ check_window_system (struct frame *f) | |||
| 139 | /* Return the value of frame parameter PROP in frame FRAME. */ | 139 | /* Return the value of frame parameter PROP in frame FRAME. */ |
| 140 | 140 | ||
| 141 | Lisp_Object | 141 | Lisp_Object |
| 142 | get_frame_param (register struct frame *frame, Lisp_Object prop) | 142 | get_frame_param (struct frame *frame, Lisp_Object prop) |
| 143 | { | 143 | { |
| 144 | register Lisp_Object tem; | 144 | return Fcdr (Fassq (prop, frame->param_alist)); |
| 145 | |||
| 146 | tem = Fassq (prop, frame->param_alist); | ||
| 147 | if (EQ (tem, Qnil)) | ||
| 148 | return tem; | ||
| 149 | return Fcdr (tem); | ||
| 150 | } | 145 | } |
| 151 | 146 | ||
| 152 | 147 | ||
| @@ -189,9 +184,9 @@ frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter) | |||
| 189 | || (CONSP (frame_inhibit_implied_resize) | 184 | || (CONSP (frame_inhibit_implied_resize) |
| 190 | && !NILP (Fmemq (parameter, frame_inhibit_implied_resize))) | 185 | && !NILP (Fmemq (parameter, frame_inhibit_implied_resize))) |
| 191 | || (horizontal | 186 | || (horizontal |
| 192 | && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight)) | 187 | && !NILP (fullscreen) && !EQ (fullscreen, Qfullheight)) |
| 193 | || (!horizontal | 188 | || (!horizontal |
| 194 | && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth)) | 189 | && !NILP (fullscreen) && !EQ (fullscreen, Qfullwidth)) |
| 195 | || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) | 190 | || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) |
| 196 | : ((horizontal && f->inhibit_horizontal_resize) | 191 | : ((horizontal && f->inhibit_horizontal_resize) |
| 197 | || (!horizontal && f->inhibit_vertical_resize))); | 192 | || (!horizontal && f->inhibit_vertical_resize))); |
| @@ -2808,10 +2803,8 @@ frames_discard_buffer (Lisp_Object buffer) | |||
| 2808 | void | 2803 | void |
| 2809 | store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val) | 2804 | store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val) |
| 2810 | { | 2805 | { |
| 2811 | register Lisp_Object tem; | 2806 | Lisp_Object tem = Fassq (prop, *alistptr); |
| 2812 | 2807 | if (NILP (tem)) | |
| 2813 | tem = Fassq (prop, *alistptr); | ||
| 2814 | if (EQ (tem, Qnil)) | ||
| 2815 | *alistptr = Fcons (Fcons (prop, val), *alistptr); | 2808 | *alistptr = Fcons (Fcons (prop, val), *alistptr); |
| 2816 | else | 2809 | else |
| 2817 | Fsetcdr (tem, val); | 2810 | Fsetcdr (tem, val); |
| @@ -2975,7 +2968,7 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val) | |||
| 2975 | 2968 | ||
| 2976 | /* Update the frame parameter alist. */ | 2969 | /* Update the frame parameter alist. */ |
| 2977 | old_alist_elt = Fassq (prop, f->param_alist); | 2970 | old_alist_elt = Fassq (prop, f->param_alist); |
| 2978 | if (EQ (old_alist_elt, Qnil)) | 2971 | if (NILP (old_alist_elt)) |
| 2979 | fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist)); | 2972 | fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist)); |
| 2980 | else | 2973 | else |
| 2981 | Fsetcdr (old_alist_elt, val); | 2974 | Fsetcdr (old_alist_elt, val); |
| @@ -4516,13 +4509,13 @@ x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval) | |||
| 4516 | void | 4509 | void |
| 4517 | x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | 4510 | x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
| 4518 | { | 4511 | { |
| 4519 | f->auto_raise = !EQ (Qnil, arg); | 4512 | f->auto_raise = !NILP (arg); |
| 4520 | } | 4513 | } |
| 4521 | 4514 | ||
| 4522 | void | 4515 | void |
| 4523 | x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | 4516 | x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
| 4524 | { | 4517 | { |
| 4525 | f->auto_lower = !EQ (Qnil, arg); | 4518 | f->auto_lower = !NILP (arg); |
| 4526 | } | 4519 | } |
| 4527 | 4520 | ||
| 4528 | void | 4521 | void |
| @@ -4973,7 +4966,7 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, | |||
| 4973 | 4966 | ||
| 4974 | /* If it wasn't specified in ALIST or the Lisp-level defaults, | 4967 | /* If it wasn't specified in ALIST or the Lisp-level defaults, |
| 4975 | look in the X resources. */ | 4968 | look in the X resources. */ |
| 4976 | if (EQ (tem, Qnil)) | 4969 | if (NILP (tem)) |
| 4977 | { | 4970 | { |
| 4978 | if (attribute && dpyinfo) | 4971 | if (attribute && dpyinfo) |
| 4979 | { | 4972 | { |
diff --git a/src/gnutls.c b/src/gnutls.c index 111dc612483..2d455ea1ba1 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -2071,7 +2071,14 @@ gnutls_symmetric (bool encrypting, Lisp_Object cipher, | |||
| 2071 | cipher = intern (SSDATA (cipher)); | 2071 | cipher = intern (SSDATA (cipher)); |
| 2072 | 2072 | ||
| 2073 | if (SYMBOLP (cipher)) | 2073 | if (SYMBOLP (cipher)) |
| 2074 | info = XCDR (Fassq (cipher, Fgnutls_ciphers ())); | 2074 | { |
| 2075 | info = Fassq (cipher, Fgnutls_ciphers ()); | ||
| 2076 | if (!CONSP (info)) | ||
| 2077 | xsignal2 (Qerror, | ||
| 2078 | build_string ("GnuTLS cipher is invalid or not found"), | ||
| 2079 | cipher); | ||
| 2080 | info = XCDR (info); | ||
| 2081 | } | ||
| 2075 | else if (TYPE_RANGED_FIXNUMP (gnutls_cipher_algorithm_t, cipher)) | 2082 | else if (TYPE_RANGED_FIXNUMP (gnutls_cipher_algorithm_t, cipher)) |
| 2076 | gca = XFIXNUM (cipher); | 2083 | gca = XFIXNUM (cipher); |
| 2077 | else | 2084 | else |
| @@ -2086,7 +2093,8 @@ gnutls_symmetric (bool encrypting, Lisp_Object cipher, | |||
| 2086 | 2093 | ||
| 2087 | ptrdiff_t key_size = gnutls_cipher_get_key_size (gca); | 2094 | ptrdiff_t key_size = gnutls_cipher_get_key_size (gca); |
| 2088 | if (key_size == 0) | 2095 | if (key_size == 0) |
| 2089 | error ("GnuTLS cipher is invalid or not found"); | 2096 | xsignal2 (Qerror, |
| 2097 | build_string ("GnuTLS cipher is invalid or not found"), cipher); | ||
| 2090 | 2098 | ||
| 2091 | ptrdiff_t kstart_byte, kend_byte; | 2099 | ptrdiff_t kstart_byte, kend_byte; |
| 2092 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); | 2100 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); |
| @@ -2342,7 +2350,14 @@ itself. */) | |||
| 2342 | hash_method = intern (SSDATA (hash_method)); | 2350 | hash_method = intern (SSDATA (hash_method)); |
| 2343 | 2351 | ||
| 2344 | if (SYMBOLP (hash_method)) | 2352 | if (SYMBOLP (hash_method)) |
| 2345 | info = XCDR (Fassq (hash_method, Fgnutls_macs ())); | 2353 | { |
| 2354 | info = Fassq (hash_method, Fgnutls_macs ()); | ||
| 2355 | if (!CONSP (info)) | ||
| 2356 | xsignal2 (Qerror, | ||
| 2357 | build_string ("GnuTLS MAC-method is invalid or not found"), | ||
| 2358 | hash_method); | ||
| 2359 | info = XCDR (info); | ||
| 2360 | } | ||
| 2346 | else if (TYPE_RANGED_FIXNUMP (gnutls_mac_algorithm_t, hash_method)) | 2361 | else if (TYPE_RANGED_FIXNUMP (gnutls_mac_algorithm_t, hash_method)) |
| 2347 | gma = XFIXNUM (hash_method); | 2362 | gma = XFIXNUM (hash_method); |
| 2348 | else | 2363 | else |
| @@ -2357,7 +2372,9 @@ itself. */) | |||
| 2357 | 2372 | ||
| 2358 | ptrdiff_t digest_length = gnutls_hmac_get_len (gma); | 2373 | ptrdiff_t digest_length = gnutls_hmac_get_len (gma); |
| 2359 | if (digest_length == 0) | 2374 | if (digest_length == 0) |
| 2360 | error ("GnuTLS MAC-method is invalid or not found"); | 2375 | xsignal2 (Qerror, |
| 2376 | build_string ("GnuTLS MAC-method is invalid or not found"), | ||
| 2377 | hash_method); | ||
| 2361 | 2378 | ||
| 2362 | ptrdiff_t kstart_byte, kend_byte; | 2379 | ptrdiff_t kstart_byte, kend_byte; |
| 2363 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); | 2380 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); |
| @@ -2423,7 +2440,14 @@ the number itself. */) | |||
| 2423 | digest_method = intern (SSDATA (digest_method)); | 2440 | digest_method = intern (SSDATA (digest_method)); |
| 2424 | 2441 | ||
| 2425 | if (SYMBOLP (digest_method)) | 2442 | if (SYMBOLP (digest_method)) |
| 2426 | info = XCDR (Fassq (digest_method, Fgnutls_digests ())); | 2443 | { |
| 2444 | info = Fassq (digest_method, Fgnutls_digests ()); | ||
| 2445 | if (!CONSP (info)) | ||
| 2446 | xsignal2 (Qerror, | ||
| 2447 | build_string ("GnuTLS digest-method is invalid or not found"), | ||
| 2448 | digest_method); | ||
| 2449 | info = XCDR (info); | ||
| 2450 | } | ||
| 2427 | else if (TYPE_RANGED_FIXNUMP (gnutls_digest_algorithm_t, digest_method)) | 2451 | else if (TYPE_RANGED_FIXNUMP (gnutls_digest_algorithm_t, digest_method)) |
| 2428 | gda = XFIXNUM (digest_method); | 2452 | gda = XFIXNUM (digest_method); |
| 2429 | else | 2453 | else |
| @@ -2438,7 +2462,9 @@ the number itself. */) | |||
| 2438 | 2462 | ||
| 2439 | ptrdiff_t digest_length = gnutls_hash_get_len (gda); | 2463 | ptrdiff_t digest_length = gnutls_hash_get_len (gda); |
| 2440 | if (digest_length == 0) | 2464 | if (digest_length == 0) |
| 2441 | error ("GnuTLS digest-method is invalid or not found"); | 2465 | xsignal2 (Qerror, |
| 2466 | build_string ("GnuTLS digest-method is invalid or not found"), | ||
| 2467 | digest_method); | ||
| 2442 | 2468 | ||
| 2443 | gnutls_hash_hd_t hash; | 2469 | gnutls_hash_hd_t hash; |
| 2444 | int ret = gnutls_hash_init (&hash, gda); | 2470 | int ret = gnutls_hash_init (&hash, gda); |
diff --git a/src/image.c b/src/image.c index 78eaf8a7598..499c1b6aed8 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -1610,7 +1610,7 @@ Anything else, means only clear those images which refer to FILTER, | |||
| 1610 | which is then usually a filename. */) | 1610 | which is then usually a filename. */) |
| 1611 | (Lisp_Object filter) | 1611 | (Lisp_Object filter) |
| 1612 | { | 1612 | { |
| 1613 | if (!(EQ (filter, Qnil) || FRAMEP (filter))) | 1613 | if (! (NILP (filter) || FRAMEP (filter))) |
| 1614 | clear_image_caches (filter); | 1614 | clear_image_caches (filter); |
| 1615 | else | 1615 | else |
| 1616 | clear_image_cache (decode_window_system_frame (filter), Qt); | 1616 | clear_image_cache (decode_window_system_frame (filter), Qt); |
diff --git a/src/intervals.c b/src/intervals.c index af27afea0dc..7e7771414fd 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -197,7 +197,7 @@ intervals_equal (INTERVAL i0, INTERVAL i1) | |||
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | /* i0 has something i1 doesn't. */ | 199 | /* i0 has something i1 doesn't. */ |
| 200 | if (EQ (i1_val, Qnil)) | 200 | if (NILP (i1_val)) |
| 201 | return false; | 201 | return false; |
| 202 | 202 | ||
| 203 | /* i0 and i1 both have sym, but it has different values in each. */ | 203 | /* i0 and i1 both have sym, but it has different values in each. */ |
diff --git a/src/intervals.h b/src/intervals.h index 162c4efc62e..f37372a42c8 100644 --- a/src/intervals.h +++ b/src/intervals.h | |||
| @@ -116,7 +116,7 @@ struct interval | |||
| 116 | 116 | ||
| 117 | /* True if this is a default interval, which is the same as being null | 117 | /* True if this is a default interval, which is the same as being null |
| 118 | or having no properties. */ | 118 | or having no properties. */ |
| 119 | #define DEFAULT_INTERVAL_P(i) (!i || EQ ((i)->plist, Qnil)) | 119 | #define DEFAULT_INTERVAL_P(i) (!i || NILP ((i)->plist)) |
| 120 | 120 | ||
| 121 | /* Test what type of parent we have. Three possibilities: another | 121 | /* Test what type of parent we have. Three possibilities: another |
| 122 | interval, a buffer or string object, or NULL. */ | 122 | interval, a buffer or string object, or NULL. */ |
diff --git a/src/json.c b/src/json.c index 17edb4140e0..4e413a2bd51 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -7,7 +7,7 @@ This file is part of GNU Emacs. | |||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or (at | 9 | the Free Software Foundation, either version 3 of the License, or (at |
| 10 | nyour option) any later version. | 10 | your option) any later version. |
| 11 | 11 | ||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | 12 | GNU Emacs is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| @@ -159,7 +159,12 @@ init_json_functions (void) | |||
| 159 | than PTRDIFF_MAX. Such objects wouldn't play well with the rest of | 159 | than PTRDIFF_MAX. Such objects wouldn't play well with the rest of |
| 160 | Emacs's codebase, which generally uses ptrdiff_t for sizes and | 160 | Emacs's codebase, which generally uses ptrdiff_t for sizes and |
| 161 | indices. The other functions in this file also generally assume | 161 | indices. The other functions in this file also generally assume |
| 162 | that size_t values never exceed PTRDIFF_MAX. */ | 162 | that size_t values never exceed PTRDIFF_MAX. |
| 163 | |||
| 164 | In addition, we need to use a custom allocator because on | ||
| 165 | MS-Windows we replace malloc/free with our own functions, see | ||
| 166 | w32heap.c, so we must force the library to use our allocator, or | ||
| 167 | else we won't be able to free storage allocated by the library. */ | ||
| 163 | 168 | ||
| 164 | static void * | 169 | static void * |
| 165 | json_malloc (size_t size) | 170 | json_malloc (size_t size) |
| @@ -605,7 +610,7 @@ usage: (json-serialize OBJECT &rest ARGS) */) | |||
| 605 | char *string = json_dumps (json, JSON_COMPACT); | 610 | char *string = json_dumps (json, JSON_COMPACT); |
| 606 | if (string == NULL) | 611 | if (string == NULL) |
| 607 | json_out_of_memory (); | 612 | json_out_of_memory (); |
| 608 | record_unwind_protect_ptr (free, string); | 613 | record_unwind_protect_ptr (json_free, string); |
| 609 | 614 | ||
| 610 | return unbind_to (count, json_build_string (string)); | 615 | return unbind_to (count, json_build_string (string)); |
| 611 | } | 616 | } |
diff --git a/src/keyboard.c b/src/keyboard.c index 4c8807d6801..e596b2880b0 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -3150,6 +3150,10 @@ help_char_p (Lisp_Object c) | |||
| 3150 | static void | 3150 | static void |
| 3151 | record_char (Lisp_Object c) | 3151 | record_char (Lisp_Object c) |
| 3152 | { | 3152 | { |
| 3153 | /* quail.el binds this to avoid recording keys twice. */ | ||
| 3154 | if (inhibit_record_char) | ||
| 3155 | return; | ||
| 3156 | |||
| 3153 | int recorded = 0; | 3157 | int recorded = 0; |
| 3154 | 3158 | ||
| 3155 | if (CONSP (c) && (EQ (XCAR (c), Qhelp_echo) || EQ (XCAR (c), Qmouse_movement))) | 3159 | if (CONSP (c) && (EQ (XCAR (c), Qhelp_echo) || EQ (XCAR (c), Qmouse_movement))) |
| @@ -3256,7 +3260,7 @@ record_char (Lisp_Object c) | |||
| 3256 | /* Write c to the dribble file. If c is a lispy event, write | 3260 | /* Write c to the dribble file. If c is a lispy event, write |
| 3257 | the event's symbol to the dribble file, in <brackets>. Bleaugh. | 3261 | the event's symbol to the dribble file, in <brackets>. Bleaugh. |
| 3258 | If you, dear reader, have a better idea, you've got the source. :-) */ | 3262 | If you, dear reader, have a better idea, you've got the source. :-) */ |
| 3259 | if (dribble) | 3263 | if (dribble && NILP (Vexecuting_kbd_macro)) |
| 3260 | { | 3264 | { |
| 3261 | block_input (); | 3265 | block_input (); |
| 3262 | if (FIXNUMP (c)) | 3266 | if (FIXNUMP (c)) |
| @@ -10110,10 +10114,13 @@ DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, | |||
| 10110 | 10114 | ||
| 10111 | DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | 10115 | DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, |
| 10112 | "FOpen dribble file: ", | 10116 | "FOpen dribble file: ", |
| 10113 | doc: /* Start writing all keyboard characters to a dribble file called FILE. | 10117 | doc: /* Start writing input events to a dribble file called FILE. |
| 10114 | If FILE is nil, close any open dribble file. | 10118 | If FILE is nil, close any open dribble file. |
| 10115 | The file will be closed when Emacs exits. | 10119 | The file will be closed when Emacs exits. |
| 10116 | 10120 | ||
| 10121 | The events written to the file include keyboard and mouse input | ||
| 10122 | events, but not events from executing keyboard macros. | ||
| 10123 | |||
| 10117 | Be aware that this records ALL characters you type! | 10124 | Be aware that this records ALL characters you type! |
| 10118 | This may include sensitive information such as passwords. */) | 10125 | This may include sensitive information such as passwords. */) |
| 10119 | (Lisp_Object file) | 10126 | (Lisp_Object file) |
| @@ -11813,10 +11820,10 @@ if the command is in this list, the selection is not updated. */); | |||
| 11813 | 11820 | ||
| 11814 | DEFVAR_LISP ("debug-on-event", | 11821 | DEFVAR_LISP ("debug-on-event", |
| 11815 | Vdebug_on_event, | 11822 | Vdebug_on_event, |
| 11816 | doc: /* Enter debugger on this event. When Emacs | 11823 | doc: /* Enter debugger on this event. |
| 11817 | receives the special event specified by this variable, it will try to | 11824 | When Emacs receives the special event specified by this variable, |
| 11818 | break into the debugger as soon as possible instead of processing the | 11825 | it will try to break into the debugger as soon as possible instead |
| 11819 | event normally through `special-event-map'. | 11826 | of processing the event normally through `special-event-map'. |
| 11820 | 11827 | ||
| 11821 | Currently, the only supported values for this | 11828 | Currently, the only supported values for this |
| 11822 | variable are `sigusr1' and `sigusr2'. */); | 11829 | variable are `sigusr1' and `sigusr2'. */); |
| @@ -11824,21 +11831,23 @@ variable are `sigusr1' and `sigusr2'. */); | |||
| 11824 | 11831 | ||
| 11825 | DEFVAR_BOOL ("attempt-stack-overflow-recovery", | 11832 | DEFVAR_BOOL ("attempt-stack-overflow-recovery", |
| 11826 | attempt_stack_overflow_recovery, | 11833 | attempt_stack_overflow_recovery, |
| 11827 | doc: /* If non-nil, attempt to recover from C stack | 11834 | doc: /* If non-nil, attempt to recover from C stack overflows. |
| 11828 | overflow. This recovery is unsafe and may lead to deadlocks or data | 11835 | This recovery is potentially unsafe and may lead to deadlocks or data |
| 11829 | corruption, but it usually works and may preserve modified buffers | 11836 | corruption, but it usually works and may preserve modified buffers |
| 11830 | that would otherwise be lost. If nil, treat stack overflow like any | 11837 | that would otherwise be lost. If nil, treat stack overflow like any |
| 11831 | other kind of crash. */); | 11838 | other kind of crash or fatal error. */); |
| 11832 | attempt_stack_overflow_recovery = true; | 11839 | attempt_stack_overflow_recovery = true; |
| 11833 | 11840 | ||
| 11834 | DEFVAR_BOOL ("attempt-orderly-shutdown-on-fatal-signal", | 11841 | DEFVAR_BOOL ("attempt-orderly-shutdown-on-fatal-signal", |
| 11835 | attempt_orderly_shutdown_on_fatal_signal, | 11842 | attempt_orderly_shutdown_on_fatal_signal, |
| 11836 | doc: /* If non-nil, attempt to perform an orderly | 11843 | doc: /* If non-nil, attempt orderly shutdown on fatal signals. |
| 11837 | shutdown when Emacs receives a fatal signal (e.g., a crash). | 11844 | By default this variable is non-nil, and Emacs attempts to perform |
| 11838 | This cleanup is unsafe and may lead to deadlocks or data corruption, | 11845 | an orderly shutdown when it catches a fatal signal (e.g., a crash). |
| 11839 | but it usually works and may preserve modified buffers that would | 11846 | The orderly shutdown includes an attempt to auto-save your unsaved edits |
| 11840 | otherwise be lost. If nil, crash immediately in response to fatal | 11847 | and other useful cleanups. These cleanups are potentially unsafe and may |
| 11841 | signals. */); | 11848 | lead to deadlocks or data corruption, but it usually works and may |
| 11849 | preserve data in modified buffers that would otherwise be lost. | ||
| 11850 | If nil, Emacs crashes immediately in response to fatal signals. */); | ||
| 11842 | attempt_orderly_shutdown_on_fatal_signal = true; | 11851 | attempt_orderly_shutdown_on_fatal_signal = true; |
| 11843 | 11852 | ||
| 11844 | /* Create the initial keyboard. Qt means 'unset'. */ | 11853 | /* Create the initial keyboard. Qt means 'unset'. */ |
| @@ -11848,6 +11857,14 @@ signals. */); | |||
| 11848 | Vwhile_no_input_ignore_events, | 11857 | Vwhile_no_input_ignore_events, |
| 11849 | doc: /* Ignored events from while-no-input. */); | 11858 | doc: /* Ignored events from while-no-input. */); |
| 11850 | Vwhile_no_input_ignore_events = Qnil; | 11859 | Vwhile_no_input_ignore_events = Qnil; |
| 11860 | |||
| 11861 | DEFVAR_BOOL ("inhibit--record-char", | ||
| 11862 | inhibit_record_char, | ||
| 11863 | doc: /* If non-nil, don't record input events. | ||
| 11864 | This inhibits recording input events for the purposes of keyboard | ||
| 11865 | macros, dribble file, and `recent-keys'. | ||
| 11866 | Internal use only. */); | ||
| 11867 | inhibit_record_char = false; | ||
| 11851 | } | 11868 | } |
| 11852 | 11869 | ||
| 11853 | void | 11870 | void |
diff --git a/src/lisp.h b/src/lisp.h index 6726d69fced..6ca34168928 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2704,17 +2704,14 @@ XFLOAT_DATA (Lisp_Object f) | |||
| 2704 | 2704 | ||
| 2705 | /* Most hosts nowadays use IEEE floating point, so they use IEC 60559 | 2705 | /* Most hosts nowadays use IEEE floating point, so they use IEC 60559 |
| 2706 | representations, have infinities and NaNs, and do not trap on | 2706 | representations, have infinities and NaNs, and do not trap on |
| 2707 | exceptions. Define IEEE_FLOATING_POINT if this host is one of the | 2707 | exceptions. Define IEEE_FLOATING_POINT to 1 if this host is one of the |
| 2708 | typical ones. The C11 macro __STDC_IEC_559__ is close to what is | 2708 | typical ones. The C11 macro __STDC_IEC_559__ is close to what is |
| 2709 | wanted here, but is not quite right because Emacs does not require | 2709 | wanted here, but is not quite right because Emacs does not require |
| 2710 | all the features of C11 Annex F (and does not require C11 at all, | 2710 | all the features of C11 Annex F (and does not require C11 at all, |
| 2711 | for that matter). */ | 2711 | for that matter). */ |
| 2712 | enum | 2712 | |
| 2713 | { | 2713 | #define IEEE_FLOATING_POINT (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ |
| 2714 | IEEE_FLOATING_POINT | 2714 | && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128) |
| 2715 | = (FLT_RADIX == 2 && FLT_MANT_DIG == 24 | ||
| 2716 | && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128) | ||
| 2717 | }; | ||
| 2718 | 2715 | ||
| 2719 | /* A character, declared with the following typedef, is a member | 2716 | /* A character, declared with the following typedef, is a member |
| 2720 | of some character set associated with the current buffer. */ | 2717 | of some character set associated with the current buffer. */ |
| @@ -4120,6 +4117,7 @@ extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object, | |||
| 4120 | extern void close_file_unwind (int); | 4117 | extern void close_file_unwind (int); |
| 4121 | extern void fclose_unwind (void *); | 4118 | extern void fclose_unwind (void *); |
| 4122 | extern void restore_point_unwind (Lisp_Object); | 4119 | extern void restore_point_unwind (Lisp_Object); |
| 4120 | extern Lisp_Object get_file_errno_data (const char *, Lisp_Object, int); | ||
| 4123 | extern _Noreturn void report_file_errno (const char *, Lisp_Object, int); | 4121 | extern _Noreturn void report_file_errno (const char *, Lisp_Object, int); |
| 4124 | extern _Noreturn void report_file_error (const char *, Lisp_Object); | 4122 | extern _Noreturn void report_file_error (const char *, Lisp_Object); |
| 4125 | extern _Noreturn void report_file_notify_error (const char *, Lisp_Object); | 4123 | extern _Noreturn void report_file_notify_error (const char *, Lisp_Object); |
| @@ -4803,7 +4801,7 @@ enum | |||
| 4803 | #define FOR_EACH_TAIL(tail) \ | 4801 | #define FOR_EACH_TAIL(tail) \ |
| 4804 | FOR_EACH_TAIL_INTERNAL (tail, circular_list (tail), true) | 4802 | FOR_EACH_TAIL_INTERNAL (tail, circular_list (tail), true) |
| 4805 | 4803 | ||
| 4806 | /* Like FOR_EACH_TAIL (LIST), except do not signal or quit. | 4804 | /* Like FOR_EACH_TAIL (TAIL), except do not signal or quit. |
| 4807 | If the loop exits due to a cycle, TAIL’s value is undefined. */ | 4805 | If the loop exits due to a cycle, TAIL’s value is undefined. */ |
| 4808 | 4806 | ||
| 4809 | #define FOR_EACH_TAIL_SAFE(tail) \ | 4807 | #define FOR_EACH_TAIL_SAFE(tail) \ |
diff --git a/src/lread.c b/src/lread.c index 3a2d9c8a6d3..df2fe581203 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -72,6 +72,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 72 | #define file_tell ftell | 72 | #define file_tell ftell |
| 73 | #endif | 73 | #endif |
| 74 | 74 | ||
| 75 | #if IEEE_FLOATING_POINT | ||
| 76 | # include <ieee754.h> | ||
| 77 | #endif | ||
| 78 | |||
| 75 | /* The objects or placeholders read with the #n=object form. | 79 | /* The objects or placeholders read with the #n=object form. |
| 76 | 80 | ||
| 77 | A hash table maps a number to either a placeholder (while the | 81 | A hash table maps a number to either a placeholder (while the |
| @@ -2730,7 +2734,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) | |||
| 2730 | int c; | 2734 | int c; |
| 2731 | bool uninterned_symbol = false; | 2735 | bool uninterned_symbol = false; |
| 2732 | bool multibyte; | 2736 | bool multibyte; |
| 2733 | char stackbuf[MAX_ALLOCA]; | 2737 | char stackbuf[128]; /* Small, as read1 is recursive (Bug#31995). */ |
| 2734 | current_thread->stack_top = stackbuf; | 2738 | current_thread->stack_top = stackbuf; |
| 2735 | 2739 | ||
| 2736 | *pch = 0; | 2740 | *pch = 0; |
| @@ -3616,7 +3620,7 @@ substitute_object_recurse (struct subst *subst, Lisp_Object subtree) | |||
| 3616 | return subtree; | 3620 | return subtree; |
| 3617 | 3621 | ||
| 3618 | /* If we've been to this node before, don't explore it again. */ | 3622 | /* If we've been to this node before, don't explore it again. */ |
| 3619 | if (!EQ (Qnil, Fmemq (subtree, subst->seen))) | 3623 | if (!NILP (Fmemq (subtree, subst->seen))) |
| 3620 | return subtree; | 3624 | return subtree; |
| 3621 | 3625 | ||
| 3622 | /* If this node can be the entry point to a cycle, remember that | 3626 | /* If this node can be the entry point to a cycle, remember that |
| @@ -3763,14 +3767,18 @@ string_to_number (char const *string, int base, int flags) | |||
| 3763 | cp += 3; | 3767 | cp += 3; |
| 3764 | value = INFINITY; | 3768 | value = INFINITY; |
| 3765 | } | 3769 | } |
| 3770 | #if IEEE_FLOATING_POINT | ||
| 3766 | else if (cp[-1] == '+' | 3771 | else if (cp[-1] == '+' |
| 3767 | && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') | 3772 | && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') |
| 3768 | { | 3773 | { |
| 3769 | state |= E_EXP; | 3774 | state |= E_EXP; |
| 3770 | cp += 3; | 3775 | cp += 3; |
| 3771 | /* NAN is a "positive" NaN on all known Emacs hosts. */ | 3776 | union ieee754_double u |
| 3772 | value = NAN; | 3777 | = { .ieee_nan = { .exponent = -1, .quiet_nan = 1, |
| 3778 | .mantissa0 = n >> 31 >> 1, .mantissa1 = n }}; | ||
| 3779 | value = u.d; | ||
| 3773 | } | 3780 | } |
| 3781 | #endif | ||
| 3774 | else | 3782 | else |
| 3775 | cp = ecp; | 3783 | cp = ecp; |
| 3776 | } | 3784 | } |
| @@ -4236,7 +4244,7 @@ usage: (unintern NAME OBARRAY) */) | |||
| 4236 | session if we unintern them, as well as even more ways to use | 4244 | session if we unintern them, as well as even more ways to use |
| 4237 | `setq' or `fset' or whatnot to make the Emacs session | 4245 | `setq' or `fset' or whatnot to make the Emacs session |
| 4238 | unusable. Let's not go down this silly road. --Stef */ | 4246 | unusable. Let's not go down this silly road. --Stef */ |
| 4239 | /* if (EQ (tem, Qnil) || EQ (tem, Qt)) | 4247 | /* if (NILP (tem) || EQ (tem, Qt)) |
| 4240 | error ("Attempt to unintern t or nil"); */ | 4248 | error ("Attempt to unintern t or nil"); */ |
| 4241 | 4249 | ||
| 4242 | XSYMBOL (tem)->u.s.interned = SYMBOL_UNINTERNED; | 4250 | XSYMBOL (tem)->u.s.interned = SYMBOL_UNINTERNED; |
diff --git a/src/menu.c b/src/menu.c index eac82017d3e..d75a8424a56 100644 --- a/src/menu.c +++ b/src/menu.c | |||
| @@ -647,7 +647,7 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 647 | i = start; | 647 | i = start; |
| 648 | while (i < end) | 648 | while (i < end) |
| 649 | { | 649 | { |
| 650 | if (EQ (AREF (menu_items, i), Qnil)) | 650 | if (NILP (AREF (menu_items, i))) |
| 651 | { | 651 | { |
| 652 | submenu_stack[submenu_depth++] = save_wv; | 652 | submenu_stack[submenu_depth++] = save_wv; |
| 653 | save_wv = prev_wv; | 653 | save_wv = prev_wv; |
| @@ -900,7 +900,7 @@ find_and_call_menu_selection (struct frame *f, int menu_bar_items_used, | |||
| 900 | 900 | ||
| 901 | while (i < menu_bar_items_used) | 901 | while (i < menu_bar_items_used) |
| 902 | { | 902 | { |
| 903 | if (EQ (AREF (vector, i), Qnil)) | 903 | if (NILP (AREF (vector, i))) |
| 904 | { | 904 | { |
| 905 | subprefix_stack[submenu_depth++] = prefix; | 905 | subprefix_stack[submenu_depth++] = prefix; |
| 906 | prefix = entry; | 906 | prefix = entry; |
| @@ -985,7 +985,7 @@ find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data | |||
| 985 | 985 | ||
| 986 | while (i < menu_items_used) | 986 | while (i < menu_items_used) |
| 987 | { | 987 | { |
| 988 | if (EQ (AREF (menu_items, i), Qnil)) | 988 | if (NILP (AREF (menu_items, i))) |
| 989 | { | 989 | { |
| 990 | subprefix_stack[submenu_depth++] = prefix; | 990 | subprefix_stack[submenu_depth++] = prefix; |
| 991 | prefix = entry; | 991 | prefix = entry; |
diff --git a/src/nsfns.m b/src/nsfns.m index 527dd77dc2d..ece21c69bfe 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -363,7 +363,7 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 363 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | 363 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) |
| 364 | return; | 364 | return; |
| 365 | } | 365 | } |
| 366 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | 366 | else if (!STRINGP (oldval) && NILP (oldval) == NILP (arg)) |
| 367 | return; | 367 | return; |
| 368 | 368 | ||
| 369 | fset_icon_name (f, arg); | 369 | fset_icon_name (f, arg); |
| @@ -1291,7 +1291,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, | |||
| 1291 | window_prompting = x_figure_window_size (f, parms, true, &x_width, &x_height); | 1291 | window_prompting = x_figure_window_size (f, parms, true, &x_width, &x_height); |
| 1292 | 1292 | ||
| 1293 | tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); | 1293 | tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); |
| 1294 | f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !EQ (tem, Qnil)); | 1294 | f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !NILP (tem)); |
| 1295 | 1295 | ||
| 1296 | /* NOTE: on other terms, this is done in set_mouse_color, however this | 1296 | /* NOTE: on other terms, this is done in set_mouse_color, however this |
| 1297 | was not getting called under Nextstep. */ | 1297 | was not getting called under Nextstep. */ |
diff --git a/src/nsmenu.m b/src/nsmenu.m index 4e22d7b41bd..7010b773e3c 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -828,7 +828,7 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 828 | i = 0; | 828 | i = 0; |
| 829 | while (i < menu_items_used) | 829 | while (i < menu_items_used) |
| 830 | { | 830 | { |
| 831 | if (EQ (AREF (menu_items, i), Qnil)) | 831 | if (NILP (AREF (menu_items, i))) |
| 832 | { | 832 | { |
| 833 | submenu_stack[submenu_depth++] = save_wv; | 833 | submenu_stack[submenu_depth++] = save_wv; |
| 834 | save_wv = prev_wv; | 834 | save_wv = prev_wv; |
diff --git a/src/nsselect.m b/src/nsselect.m index b7e134b5466..35705bfca0e 100644 --- a/src/nsselect.m +++ b/src/nsselect.m | |||
| @@ -164,7 +164,7 @@ ns_get_our_change_count_for (Lisp_Object selection) | |||
| 164 | static void | 164 | static void |
| 165 | ns_string_to_pasteboard_internal (id pb, Lisp_Object str, NSString *gtype) | 165 | ns_string_to_pasteboard_internal (id pb, Lisp_Object str, NSString *gtype) |
| 166 | { | 166 | { |
| 167 | if (EQ (str, Qnil)) | 167 | if (NILP (str)) |
| 168 | { | 168 | { |
| 169 | [pb declareTypes: [NSArray array] owner: nil]; | 169 | [pb declareTypes: [NSArray array] owner: nil]; |
| 170 | } | 170 | } |
| @@ -399,7 +399,7 @@ these literal upper-case names.) The symbol nil is the same as | |||
| 399 | return Qnil; | 399 | return Qnil; |
| 400 | 400 | ||
| 401 | CHECK_SYMBOL (selection); | 401 | CHECK_SYMBOL (selection); |
| 402 | if (EQ (selection, Qnil)) selection = QPRIMARY; | 402 | if (NILP (selection)) selection = QPRIMARY; |
| 403 | if (EQ (selection, Qt)) selection = QSECONDARY; | 403 | if (EQ (selection, Qt)) selection = QSECONDARY; |
| 404 | pb = ns_symbol_to_pb (selection); | 404 | pb = ns_symbol_to_pb (selection); |
| 405 | if (pb == nil) return Qnil; | 405 | if (pb == nil) return Qnil; |
| @@ -421,7 +421,7 @@ and t is the same as `SECONDARY'. */) | |||
| 421 | { | 421 | { |
| 422 | check_window_system (NULL); | 422 | check_window_system (NULL); |
| 423 | CHECK_SYMBOL (selection); | 423 | CHECK_SYMBOL (selection); |
| 424 | if (EQ (selection, Qnil)) selection = QPRIMARY; | 424 | if (NILP (selection)) selection = QPRIMARY; |
| 425 | if (EQ (selection, Qt)) selection = QSECONDARY; | 425 | if (EQ (selection, Qt)) selection = QSECONDARY; |
| 426 | return ns_get_pb_change_count (selection) | 426 | return ns_get_pb_change_count (selection) |
| 427 | == ns_get_our_change_count_for (selection) | 427 | == ns_get_our_change_count_for (selection) |
diff --git a/src/print.c b/src/print.c index 998ff2dc0c6..3819c505b12 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -38,6 +38,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 38 | #include <c-ctype.h> | 38 | #include <c-ctype.h> |
| 39 | #include <float.h> | 39 | #include <float.h> |
| 40 | #include <ftoastr.h> | 40 | #include <ftoastr.h> |
| 41 | #include <math.h> | ||
| 42 | |||
| 43 | #if IEEE_FLOATING_POINT | ||
| 44 | # include <ieee754.h> | ||
| 45 | #endif | ||
| 41 | 46 | ||
| 42 | #ifdef WINDOWSNT | 47 | #ifdef WINDOWSNT |
| 43 | # include <sys/socket.h> /* for F_DUPFD_CLOEXEC */ | 48 | # include <sys/socket.h> /* for F_DUPFD_CLOEXEC */ |
| @@ -1001,43 +1006,22 @@ float_to_string (char *buf, double data) | |||
| 1001 | int width; | 1006 | int width; |
| 1002 | int len; | 1007 | int len; |
| 1003 | 1008 | ||
| 1004 | /* Check for plus infinity in a way that won't lose | 1009 | if (isinf (data)) |
| 1005 | if there is no plus infinity. */ | ||
| 1006 | if (data == data / 2 && data > 1.0) | ||
| 1007 | { | ||
| 1008 | static char const infinity_string[] = "1.0e+INF"; | ||
| 1009 | strcpy (buf, infinity_string); | ||
| 1010 | return sizeof infinity_string - 1; | ||
| 1011 | } | ||
| 1012 | /* Likewise for minus infinity. */ | ||
| 1013 | if (data == data / 2 && data < -1.0) | ||
| 1014 | { | 1010 | { |
| 1015 | static char const minus_infinity_string[] = "-1.0e+INF"; | 1011 | static char const minus_infinity_string[] = "-1.0e+INF"; |
| 1016 | strcpy (buf, minus_infinity_string); | 1012 | bool positive = 0 < data; |
| 1017 | return sizeof minus_infinity_string - 1; | 1013 | strcpy (buf, minus_infinity_string + positive); |
| 1014 | return sizeof minus_infinity_string - 1 - positive; | ||
| 1018 | } | 1015 | } |
| 1019 | /* Check for NaN in a way that won't fail if there are no NaNs. */ | 1016 | #if IEEE_FLOATING_POINT |
| 1020 | if (! (data * 0.0 >= 0.0)) | 1017 | if (isnan (data)) |
| 1021 | { | 1018 | { |
| 1022 | /* Prepend "-" if the NaN's sign bit is negative. | 1019 | union ieee754_double u = { .d = data }; |
| 1023 | The sign bit of a double is the bit that is 1 in -0.0. */ | 1020 | uprintmax_t hi = u.ieee_nan.mantissa0; |
| 1024 | static char const NaN_string[] = "0.0e+NaN"; | 1021 | return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative], |
| 1025 | int i; | 1022 | (hi << 31 << 1) + u.ieee_nan.mantissa1); |
| 1026 | union { double d; char c[sizeof (double)]; } u_data, u_minus_zero; | ||
| 1027 | bool negative = 0; | ||
| 1028 | u_data.d = data; | ||
| 1029 | u_minus_zero.d = - 0.0; | ||
| 1030 | for (i = 0; i < sizeof (double); i++) | ||
| 1031 | if (u_data.c[i] & u_minus_zero.c[i]) | ||
| 1032 | { | ||
| 1033 | *buf = '-'; | ||
| 1034 | negative = 1; | ||
| 1035 | break; | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | strcpy (buf + negative, NaN_string); | ||
| 1039 | return negative + sizeof NaN_string - 1; | ||
| 1040 | } | 1023 | } |
| 1024 | #endif | ||
| 1041 | 1025 | ||
| 1042 | if (NILP (Vfloat_output_format) | 1026 | if (NILP (Vfloat_output_format) |
| 1043 | || !STRINGP (Vfloat_output_format)) | 1027 | || !STRINGP (Vfloat_output_format)) |
diff --git a/src/process.c b/src/process.c index 698a2c3ac02..c8123be28e8 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -3587,17 +3587,23 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3587 | 3587 | ||
| 3588 | if (s < 0) | 3588 | if (s < 0) |
| 3589 | { | 3589 | { |
| 3590 | const char *err = (p->is_server | ||
| 3591 | ? "make server process failed" | ||
| 3592 | : "make client process failed"); | ||
| 3593 | |||
| 3590 | /* If non-blocking got this far - and failed - assume non-blocking is | 3594 | /* If non-blocking got this far - and failed - assume non-blocking is |
| 3591 | not supported after all. This is probably a wrong assumption, but | 3595 | not supported after all. This is probably a wrong assumption, but |
| 3592 | the normal blocking calls to open-network-stream handles this error | 3596 | the normal blocking calls to open-network-stream handles this error |
| 3593 | better. */ | 3597 | better. */ |
| 3594 | if (p->is_non_blocking_client) | 3598 | if (p->is_non_blocking_client) |
| 3595 | return; | 3599 | { |
| 3600 | Lisp_Object data = get_file_errno_data (err, contact, xerrno); | ||
| 3596 | 3601 | ||
| 3597 | report_file_errno ((p->is_server | 3602 | pset_status (p, list2 (Fcar (data), Fcdr (data))); |
| 3598 | ? "make server process failed" | 3603 | return; |
| 3599 | : "make client process failed"), | 3604 | } |
| 3600 | contact, xerrno); | 3605 | |
| 3606 | report_file_errno (err, contact, xerrno); | ||
| 3601 | } | 3607 | } |
| 3602 | 3608 | ||
| 3603 | inch = s; | 3609 | inch = s; |
| @@ -3905,7 +3911,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3905 | CHECK_STRING (name); | 3911 | CHECK_STRING (name); |
| 3906 | 3912 | ||
| 3907 | /* :local ADDRESS or :remote ADDRESS */ | 3913 | /* :local ADDRESS or :remote ADDRESS */ |
| 3908 | if (!NILP (server)) | 3914 | if (NILP (server)) |
| 3909 | address = Fplist_get (contact, QCremote); | 3915 | address = Fplist_get (contact, QCremote); |
| 3910 | else | 3916 | else |
| 3911 | address = Fplist_get (contact, QClocal); | 3917 | address = Fplist_get (contact, QClocal); |
| @@ -4608,16 +4614,15 @@ is nil, from any process) before the timeout expired. */) | |||
| 4608 | 4614 | ||
| 4609 | /* Can't wait for a process that is dedicated to a different | 4615 | /* Can't wait for a process that is dedicated to a different |
| 4610 | thread. */ | 4616 | thread. */ |
| 4611 | if (!EQ (proc->thread, Qnil) && !EQ (proc->thread, Fcurrent_thread ())) | 4617 | if (!NILP (proc->thread) && !EQ (proc->thread, Fcurrent_thread ())) |
| 4612 | { | 4618 | { |
| 4613 | Lisp_Object proc_thread_name = XTHREAD (proc->thread)->name; | 4619 | Lisp_Object proc_thread_name = XTHREAD (proc->thread)->name; |
| 4614 | 4620 | ||
| 4615 | if (STRINGP (proc_thread_name)) | 4621 | error ("Attempt to accept output from process %s locked to thread %s", |
| 4616 | error ("Attempt to accept output from process %s locked to thread %s", | 4622 | SDATA (proc->name), |
| 4617 | SDATA (proc->name), SDATA (proc_thread_name)); | 4623 | STRINGP (proc_thread_name) |
| 4618 | else | 4624 | ? SDATA (proc_thread_name) |
| 4619 | error ("Attempt to accept output from process %s locked to thread %p", | 4625 | : SDATA (Fprin1_to_string (proc->thread, Qt))); |
| 4620 | SDATA (proc->name), XTHREAD (proc->thread)); | ||
| 4621 | } | 4626 | } |
| 4622 | } | 4627 | } |
| 4623 | else | 4628 | else |
| @@ -5016,7 +5021,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5016 | struct timespec now = invalid_timespec (); | 5021 | struct timespec now = invalid_timespec (); |
| 5017 | 5022 | ||
| 5018 | eassert (wait_proc == NULL | 5023 | eassert (wait_proc == NULL |
| 5019 | || EQ (wait_proc->thread, Qnil) | 5024 | || NILP (wait_proc->thread) |
| 5020 | || XTHREAD (wait_proc->thread) == current_thread); | 5025 | || XTHREAD (wait_proc->thread) == current_thread); |
| 5021 | 5026 | ||
| 5022 | FD_ZERO (&Available); | 5027 | FD_ZERO (&Available); |
diff --git a/src/regex.c b/src/regex-emacs.c index 6ee13c4c99d..d19838a876e 100644 --- a/src/regex.c +++ b/src/regex-emacs.c | |||
| @@ -1,6 +1,4 @@ | |||
| 1 | /* Extended regular expression matching and search library, version | 1 | /* Emacs regular expression matching and search |
| 2 | 0.12. (Implements POSIX draft P1003.2/D11.2, except for some of the | ||
| 3 | internationalization features.) | ||
| 4 | 2 | ||
| 5 | Copyright (C) 1993-2018 Free Software Foundation, Inc. | 3 | Copyright (C) 1993-2018 Free Software Foundation, Inc. |
| 6 | 4 | ||
| @@ -19,166 +17,64 @@ | |||
| 19 | 17 | ||
| 20 | /* TODO: | 18 | /* TODO: |
| 21 | - structure the opcode space into opcode+flag. | 19 | - structure the opcode space into opcode+flag. |
| 22 | - merge with glibc's regex.[ch]. | ||
| 23 | - replace (succeed_n + jump_n + set_number_at) with something that doesn't | 20 | - replace (succeed_n + jump_n + set_number_at) with something that doesn't |
| 24 | need to modify the compiled regexp so that re_match can be reentrant. | 21 | need to modify the compiled regexp so that re_search can be reentrant. |
| 25 | - get rid of on_failure_jump_smart by doing the optimization in re_comp | 22 | - get rid of on_failure_jump_smart by doing the optimization in re_comp |
| 26 | rather than at run-time, so that re_match can be reentrant. | 23 | rather than at run-time, so that re_search can be reentrant. |
| 27 | */ | 24 | */ |
| 28 | 25 | ||
| 29 | /* AIX requires this to be the first thing in the file. */ | ||
| 30 | #if defined _AIX && !defined REGEX_MALLOC | ||
| 31 | #pragma alloca | ||
| 32 | #endif | ||
| 33 | |||
| 34 | /* Ignore some GCC warnings for now. This section should go away | ||
| 35 | once the Emacs and Gnulib regex code is merged. */ | ||
| 36 | #if 4 < __GNUC__ + (5 <= __GNUC_MINOR__) || defined __clang__ | ||
| 37 | # pragma GCC diagnostic ignored "-Wstrict-overflow" | ||
| 38 | # ifndef emacs | ||
| 39 | # pragma GCC diagnostic ignored "-Wunused-function" | ||
| 40 | # pragma GCC diagnostic ignored "-Wunused-macros" | ||
| 41 | # pragma GCC diagnostic ignored "-Wunused-result" | ||
| 42 | # pragma GCC diagnostic ignored "-Wunused-variable" | ||
| 43 | # endif | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) && ! defined __clang__ | ||
| 47 | # pragma GCC diagnostic ignored "-Wunused-but-set-variable" | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #include <config.h> | 26 | #include <config.h> |
| 51 | 27 | ||
| 52 | #include <stddef.h> | 28 | #include "regex-emacs.h" |
| 53 | #include <stdlib.h> | ||
| 54 | |||
| 55 | #ifdef emacs | ||
| 56 | /* We need this for `regex.h', and perhaps for the Emacs include files. */ | ||
| 57 | # include <sys/types.h> | ||
| 58 | #endif | ||
| 59 | |||
| 60 | /* Whether to use ISO C Amendment 1 wide char functions. | ||
| 61 | Those should not be used for Emacs since it uses its own. */ | ||
| 62 | #if defined _LIBC | ||
| 63 | #define WIDE_CHAR_SUPPORT 1 | ||
| 64 | #else | ||
| 65 | #define WIDE_CHAR_SUPPORT \ | ||
| 66 | (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC && !emacs) | ||
| 67 | #endif | ||
| 68 | 29 | ||
| 69 | /* For platform which support the ISO C amendment 1 functionality we | 30 | #include <stdlib.h> |
| 70 | support user defined character classes. */ | ||
| 71 | #if WIDE_CHAR_SUPPORT | ||
| 72 | /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */ | ||
| 73 | # include <wchar.h> | ||
| 74 | # include <wctype.h> | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #ifdef _LIBC | ||
| 78 | /* We have to keep the namespace clean. */ | ||
| 79 | # define regfree(preg) __regfree (preg) | ||
| 80 | # define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef) | ||
| 81 | # define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags) | ||
| 82 | # define regerror(err_code, preg, errbuf, errbuf_size) \ | ||
| 83 | __regerror (err_code, preg, errbuf, errbuf_size) | ||
| 84 | # define re_set_registers(bu, re, nu, st, en) \ | ||
| 85 | __re_set_registers (bu, re, nu, st, en) | ||
| 86 | # define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \ | ||
| 87 | __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) | ||
| 88 | # define re_match(bufp, string, size, pos, regs) \ | ||
| 89 | __re_match (bufp, string, size, pos, regs) | ||
| 90 | # define re_search(bufp, string, size, startpos, range, regs) \ | ||
| 91 | __re_search (bufp, string, size, startpos, range, regs) | ||
| 92 | # define re_compile_pattern(pattern, length, bufp) \ | ||
| 93 | __re_compile_pattern (pattern, length, bufp) | ||
| 94 | # define re_set_syntax(syntax) __re_set_syntax (syntax) | ||
| 95 | # define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \ | ||
| 96 | __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop) | ||
| 97 | # define re_compile_fastmap(bufp) __re_compile_fastmap (bufp) | ||
| 98 | |||
| 99 | /* Make sure we call libc's function even if the user overrides them. */ | ||
| 100 | # define btowc __btowc | ||
| 101 | # define iswctype __iswctype | ||
| 102 | # define wctype __wctype | ||
| 103 | |||
| 104 | # define WEAK_ALIAS(a,b) weak_alias (a, b) | ||
| 105 | |||
| 106 | /* We are also using some library internals. */ | ||
| 107 | # include <locale/localeinfo.h> | ||
| 108 | # include <locale/elem-hash.h> | ||
| 109 | # include <langinfo.h> | ||
| 110 | #else | ||
| 111 | # define WEAK_ALIAS(a,b) | ||
| 112 | #endif | ||
| 113 | |||
| 114 | /* This is for other GNU distributions with internationalized messages. */ | ||
| 115 | #if HAVE_LIBINTL_H || defined _LIBC | ||
| 116 | # include <libintl.h> | ||
| 117 | #else | ||
| 118 | # define gettext(msgid) (msgid) | ||
| 119 | #endif | ||
| 120 | 31 | ||
| 121 | #ifndef gettext_noop | 32 | #include "character.h" |
| 122 | /* This define is so xgettext can find the internationalizable | 33 | #include "buffer.h" |
| 123 | strings. */ | 34 | #include "syntax.h" |
| 124 | # define gettext_noop(String) String | 35 | #include "category.h" |
| 36 | |||
| 37 | /* Maximum number of duplicates an interval can allow. Some systems | ||
| 38 | define this in other header files, but we want our value, so remove | ||
| 39 | any previous define. Repeat counts are stored in opcodes as 2-byte | ||
| 40 | unsigned integers. */ | ||
| 41 | #ifdef RE_DUP_MAX | ||
| 42 | # undef RE_DUP_MAX | ||
| 125 | #endif | 43 | #endif |
| 126 | 44 | #define RE_DUP_MAX (0xffff) | |
| 127 | /* The `emacs' switch turns on certain matching commands | ||
| 128 | that make sense only in Emacs. */ | ||
| 129 | #ifdef emacs | ||
| 130 | |||
| 131 | # include "lisp.h" | ||
| 132 | # include "character.h" | ||
| 133 | # include "buffer.h" | ||
| 134 | |||
| 135 | # include "syntax.h" | ||
| 136 | # include "category.h" | ||
| 137 | 45 | ||
| 138 | /* Make syntax table lookup grant data in gl_state. */ | 46 | /* Make syntax table lookup grant data in gl_state. */ |
| 139 | # define SYNTAX(c) syntax_property (c, 1) | 47 | #define SYNTAX(c) syntax_property (c, 1) |
| 140 | 48 | ||
| 141 | # ifdef malloc | 49 | /* Convert the pointer to the char to BEG-based offset from the start. */ |
| 142 | # undef malloc | 50 | #define PTR_TO_OFFSET(d) POS_AS_IN_BUFFER (POINTER_TO_OFFSET (d)) |
| 143 | # endif | 51 | /* Strings are 0-indexed, buffers are 1-indexed; pun on the boolean |
| 144 | # define malloc xmalloc | ||
| 145 | # ifdef realloc | ||
| 146 | # undef realloc | ||
| 147 | # endif | ||
| 148 | # define realloc xrealloc | ||
| 149 | # ifdef free | ||
| 150 | # undef free | ||
| 151 | # endif | ||
| 152 | # define free xfree | ||
| 153 | |||
| 154 | /* Converts the pointer to the char to BEG-based offset from the start. */ | ||
| 155 | # define PTR_TO_OFFSET(d) POS_AS_IN_BUFFER (POINTER_TO_OFFSET (d)) | ||
| 156 | /* Strings are 0-indexed, buffers are 1-indexed; we pun on the boolean | ||
| 157 | result to get the right base index. */ | 52 | result to get the right base index. */ |
| 158 | # define POS_AS_IN_BUFFER(p) \ | 53 | #define POS_AS_IN_BUFFER(p) \ |
| 159 | ((p) + (NILP (gl_state.object) || BUFFERP (gl_state.object))) | 54 | ((p) + (NILP (gl_state.object) || BUFFERP (gl_state.object))) |
| 160 | 55 | ||
| 161 | # define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) | 56 | #define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) |
| 162 | # define RE_TARGET_MULTIBYTE_P(bufp) ((bufp)->target_multibyte) | 57 | #define RE_TARGET_MULTIBYTE_P(bufp) ((bufp)->target_multibyte) |
| 163 | # define RE_STRING_CHAR(p, multibyte) \ | 58 | #define RE_STRING_CHAR(p, multibyte) \ |
| 164 | (multibyte ? (STRING_CHAR (p)) : (*(p))) | 59 | (multibyte ? STRING_CHAR (p) : *(p)) |
| 165 | # define RE_STRING_CHAR_AND_LENGTH(p, len, multibyte) \ | 60 | #define RE_STRING_CHAR_AND_LENGTH(p, len, multibyte) \ |
| 166 | (multibyte ? (STRING_CHAR_AND_LENGTH (p, len)) : ((len) = 1, *(p))) | 61 | (multibyte ? STRING_CHAR_AND_LENGTH (p, len) : ((len) = 1, *(p))) |
| 167 | 62 | ||
| 168 | # define RE_CHAR_TO_MULTIBYTE(c) UNIBYTE_TO_CHAR (c) | 63 | #define RE_CHAR_TO_MULTIBYTE(c) UNIBYTE_TO_CHAR (c) |
| 169 | 64 | ||
| 170 | # define RE_CHAR_TO_UNIBYTE(c) CHAR_TO_BYTE_SAFE (c) | 65 | #define RE_CHAR_TO_UNIBYTE(c) CHAR_TO_BYTE_SAFE (c) |
| 171 | 66 | ||
| 172 | /* Set C a (possibly converted to multibyte) character before P. P | 67 | /* Set C a (possibly converted to multibyte) character before P. P |
| 173 | points into a string which is the virtual concatenation of STR1 | 68 | points into a string which is the virtual concatenation of STR1 |
| 174 | (which ends at END1) or STR2 (which ends at END2). */ | 69 | (which ends at END1) or STR2 (which ends at END2). */ |
| 175 | # define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ | 70 | #define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ |
| 176 | do { \ | 71 | do { \ |
| 177 | if (target_multibyte) \ | 72 | if (target_multibyte) \ |
| 178 | { \ | 73 | { \ |
| 179 | re_char *dtemp = (p) == (str2) ? (end1) : (p); \ | 74 | re_char *dtemp = (p) == (str2) ? (end1) : (p); \ |
| 180 | re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \ | 75 | re_char *dlimit = (p) > (str2) && (p) <= (end2) ? (str2) : (str1); \ |
| 181 | while (dtemp-- > dlimit && !CHAR_HEAD_P (*dtemp)); \ | 76 | while (dtemp-- > dlimit && !CHAR_HEAD_P (*dtemp)) \ |
| 77 | continue; \ | ||
| 182 | c = STRING_CHAR (dtemp); \ | 78 | c = STRING_CHAR (dtemp); \ |
| 183 | } \ | 79 | } \ |
| 184 | else \ | 80 | else \ |
| @@ -186,11 +82,11 @@ | |||
| 186 | (c = ((p) == (str2) ? (end1) : (p))[-1]); \ | 82 | (c = ((p) == (str2) ? (end1) : (p))[-1]); \ |
| 187 | (c) = RE_CHAR_TO_MULTIBYTE (c); \ | 83 | (c) = RE_CHAR_TO_MULTIBYTE (c); \ |
| 188 | } \ | 84 | } \ |
| 189 | } while (0) | 85 | } while (false) |
| 190 | 86 | ||
| 191 | /* Set C a (possibly converted to multibyte) character at P, and set | 87 | /* Set C a (possibly converted to multibyte) character at P, and set |
| 192 | LEN to the byte length of that character. */ | 88 | LEN to the byte length of that character. */ |
| 193 | # define GET_CHAR_AFTER(c, p, len) \ | 89 | #define GET_CHAR_AFTER(c, p, len) \ |
| 194 | do { \ | 90 | do { \ |
| 195 | if (target_multibyte) \ | 91 | if (target_multibyte) \ |
| 196 | (c) = STRING_CHAR_AND_LENGTH (p, len); \ | 92 | (c) = STRING_CHAR_AND_LENGTH (p, len); \ |
| @@ -200,336 +96,108 @@ | |||
| 200 | len = 1; \ | 96 | len = 1; \ |
| 201 | (c) = RE_CHAR_TO_MULTIBYTE (c); \ | 97 | (c) = RE_CHAR_TO_MULTIBYTE (c); \ |
| 202 | } \ | 98 | } \ |
| 203 | } while (0) | 99 | } while (false) |
| 204 | |||
| 205 | #else /* not emacs */ | ||
| 206 | |||
| 207 | /* If we are not linking with Emacs proper, | ||
| 208 | we can't use the relocating allocator | ||
| 209 | even if config.h says that we can. */ | ||
| 210 | # undef REL_ALLOC | ||
| 211 | |||
| 212 | # include <unistd.h> | ||
| 213 | |||
| 214 | /* When used in Emacs's lib-src, we need xmalloc and xrealloc. */ | ||
| 215 | |||
| 216 | static ATTRIBUTE_MALLOC void * | ||
| 217 | xmalloc (size_t size) | ||
| 218 | { | ||
| 219 | void *val = malloc (size); | ||
| 220 | if (!val && size) | ||
| 221 | { | ||
| 222 | write (STDERR_FILENO, "virtual memory exhausted\n", 25); | ||
| 223 | exit (1); | ||
| 224 | } | ||
| 225 | return val; | ||
| 226 | } | ||
| 227 | |||
| 228 | static void * | ||
| 229 | xrealloc (void *block, size_t size) | ||
| 230 | { | ||
| 231 | void *val; | ||
| 232 | /* We must call malloc explicitly when BLOCK is 0, since some | ||
| 233 | reallocs don't do this. */ | ||
| 234 | if (! block) | ||
| 235 | val = malloc (size); | ||
| 236 | else | ||
| 237 | val = realloc (block, size); | ||
| 238 | if (!val && size) | ||
| 239 | { | ||
| 240 | write (STDERR_FILENO, "virtual memory exhausted\n", 25); | ||
| 241 | exit (1); | ||
| 242 | } | ||
| 243 | return val; | ||
| 244 | } | ||
| 245 | |||
| 246 | # ifdef malloc | ||
| 247 | # undef malloc | ||
| 248 | # endif | ||
| 249 | # define malloc xmalloc | ||
| 250 | # ifdef realloc | ||
| 251 | # undef realloc | ||
| 252 | # endif | ||
| 253 | # define realloc xrealloc | ||
| 254 | |||
| 255 | # include <stdbool.h> | ||
| 256 | # include <string.h> | ||
| 257 | |||
| 258 | /* Define the syntax stuff for \<, \>, etc. */ | ||
| 259 | |||
| 260 | /* Sword must be nonzero for the wordchar pattern commands in re_match_2. */ | ||
| 261 | enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 }; | ||
| 262 | |||
| 263 | /* Dummy macros for non-Emacs environments. */ | ||
| 264 | # define MAX_MULTIBYTE_LENGTH 1 | ||
| 265 | # define RE_MULTIBYTE_P(x) 0 | ||
| 266 | # define RE_TARGET_MULTIBYTE_P(x) 0 | ||
| 267 | # define WORD_BOUNDARY_P(c1, c2) (0) | ||
| 268 | # define BYTES_BY_CHAR_HEAD(p) (1) | ||
| 269 | # define PREV_CHAR_BOUNDARY(p, limit) ((p)--) | ||
| 270 | # define STRING_CHAR(p) (*(p)) | ||
| 271 | # define RE_STRING_CHAR(p, multibyte) STRING_CHAR (p) | ||
| 272 | # define CHAR_STRING(c, s) (*(s) = (c), 1) | ||
| 273 | # define STRING_CHAR_AND_LENGTH(p, actual_len) ((actual_len) = 1, *(p)) | ||
| 274 | # define RE_STRING_CHAR_AND_LENGTH(p, len, multibyte) STRING_CHAR_AND_LENGTH (p, len) | ||
| 275 | # define RE_CHAR_TO_MULTIBYTE(c) (c) | ||
| 276 | # define RE_CHAR_TO_UNIBYTE(c) (c) | ||
| 277 | # define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ | ||
| 278 | (c = ((p) == (str2) ? *((end1) - 1) : *((p) - 1))) | ||
| 279 | # define GET_CHAR_AFTER(c, p, len) \ | ||
| 280 | (c = *p, len = 1) | ||
| 281 | # define CHAR_BYTE8_P(c) (0) | ||
| 282 | # define CHAR_LEADING_CODE(c) (c) | ||
| 283 | |||
| 284 | #endif /* not emacs */ | ||
| 285 | |||
| 286 | #ifndef RE_TRANSLATE | ||
| 287 | # define RE_TRANSLATE(TBL, C) ((unsigned char)(TBL)[C]) | ||
| 288 | # define RE_TRANSLATE_P(TBL) (TBL) | ||
| 289 | #endif | ||
| 290 | 100 | ||
| 291 | /* Get the interface, including the syntax bits. */ | ||
| 292 | #include "regex.h" | ||
| 293 | |||
| 294 | /* isalpha etc. are used for the character classes. */ | ||
| 295 | #include <ctype.h> | ||
| 296 | |||
| 297 | #ifdef emacs | ||
| 298 | |||
| 299 | /* 1 if C is an ASCII character. */ | 101 | /* 1 if C is an ASCII character. */ |
| 300 | # define IS_REAL_ASCII(c) ((c) < 0200) | 102 | #define IS_REAL_ASCII(c) ((c) < 0200) |
| 301 | 103 | ||
| 302 | /* 1 if C is a unibyte character. */ | 104 | /* 1 if C is a unibyte character. */ |
| 303 | # define ISUNIBYTE(c) (SINGLE_BYTE_CHAR_P ((c))) | 105 | #define ISUNIBYTE(c) (SINGLE_BYTE_CHAR_P ((c))) |
| 304 | 106 | ||
| 305 | /* The Emacs definitions should not be directly affected by locales. */ | 107 | /* The Emacs definitions should not be directly affected by locales. */ |
| 306 | 108 | ||
| 307 | /* In Emacs, these are only used for single-byte characters. */ | 109 | /* In Emacs, these are only used for single-byte characters. */ |
| 308 | # define ISDIGIT(c) ((c) >= '0' && (c) <= '9') | 110 | #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') |
| 309 | # define ISCNTRL(c) ((c) < ' ') | 111 | #define ISCNTRL(c) ((c) < ' ') |
| 310 | # define ISXDIGIT(c) (0 <= char_hexdigit (c)) | 112 | #define ISXDIGIT(c) (0 <= char_hexdigit (c)) |
| 311 | 113 | ||
| 312 | /* The rest must handle multibyte characters. */ | 114 | /* The rest must handle multibyte characters. */ |
| 313 | 115 | ||
| 314 | # define ISBLANK(c) (IS_REAL_ASCII (c) \ | 116 | #define ISBLANK(c) (IS_REAL_ASCII (c) \ |
| 315 | ? ((c) == ' ' || (c) == '\t') \ | 117 | ? ((c) == ' ' || (c) == '\t') \ |
| 316 | : blankp (c)) | 118 | : blankp (c)) |
| 317 | 119 | ||
| 318 | # define ISGRAPH(c) (SINGLE_BYTE_CHAR_P (c) \ | 120 | #define ISGRAPH(c) (SINGLE_BYTE_CHAR_P (c) \ |
| 319 | ? (c) > ' ' && !((c) >= 0177 && (c) <= 0240) \ | 121 | ? (c) > ' ' && !((c) >= 0177 && (c) <= 0240) \ |
| 320 | : graphicp (c)) | 122 | : graphicp (c)) |
| 321 | 123 | ||
| 322 | # define ISPRINT(c) (SINGLE_BYTE_CHAR_P (c) \ | 124 | #define ISPRINT(c) (SINGLE_BYTE_CHAR_P (c) \ |
| 323 | ? (c) >= ' ' && !((c) >= 0177 && (c) <= 0237) \ | 125 | ? (c) >= ' ' && !((c) >= 0177 && (c) <= 0237) \ |
| 324 | : printablep (c)) | 126 | : printablep (c)) |
| 325 | 127 | ||
| 326 | # define ISALNUM(c) (IS_REAL_ASCII (c) \ | 128 | #define ISALNUM(c) (IS_REAL_ASCII (c) \ |
| 327 | ? (((c) >= 'a' && (c) <= 'z') \ | 129 | ? (((c) >= 'a' && (c) <= 'z') \ |
| 328 | || ((c) >= 'A' && (c) <= 'Z') \ | 130 | || ((c) >= 'A' && (c) <= 'Z') \ |
| 329 | || ((c) >= '0' && (c) <= '9')) \ | 131 | || ((c) >= '0' && (c) <= '9')) \ |
| 330 | : alphanumericp (c)) | 132 | : alphanumericp (c)) |
| 331 | 133 | ||
| 332 | # define ISALPHA(c) (IS_REAL_ASCII (c) \ | 134 | #define ISALPHA(c) (IS_REAL_ASCII (c) \ |
| 333 | ? (((c) >= 'a' && (c) <= 'z') \ | 135 | ? (((c) >= 'a' && (c) <= 'z') \ |
| 334 | || ((c) >= 'A' && (c) <= 'Z')) \ | 136 | || ((c) >= 'A' && (c) <= 'Z')) \ |
| 335 | : alphabeticp (c)) | 137 | : alphabeticp (c)) |
| 336 | 138 | ||
| 337 | # define ISLOWER(c) lowercasep (c) | 139 | #define ISLOWER(c) lowercasep (c) |
| 338 | 140 | ||
| 339 | # define ISPUNCT(c) (IS_REAL_ASCII (c) \ | 141 | #define ISPUNCT(c) (IS_REAL_ASCII (c) \ |
| 340 | ? ((c) > ' ' && (c) < 0177 \ | 142 | ? ((c) > ' ' && (c) < 0177 \ |
| 341 | && !(((c) >= 'a' && (c) <= 'z') \ | 143 | && !(((c) >= 'a' && (c) <= 'z') \ |
| 342 | || ((c) >= 'A' && (c) <= 'Z') \ | 144 | || ((c) >= 'A' && (c) <= 'Z') \ |
| 343 | || ((c) >= '0' && (c) <= '9'))) \ | 145 | || ((c) >= '0' && (c) <= '9'))) \ |
| 344 | : SYNTAX (c) != Sword) | 146 | : SYNTAX (c) != Sword) |
| 345 | 147 | ||
| 346 | # define ISSPACE(c) (SYNTAX (c) == Swhitespace) | 148 | #define ISSPACE(c) (SYNTAX (c) == Swhitespace) |
| 347 | |||
| 348 | # define ISUPPER(c) uppercasep (c) | ||
| 349 | |||
| 350 | # define ISWORD(c) (SYNTAX (c) == Sword) | ||
| 351 | |||
| 352 | #else /* not emacs */ | ||
| 353 | 149 | ||
| 354 | /* 1 if C is an ASCII character. */ | 150 | #define ISUPPER(c) uppercasep (c) |
| 355 | # define IS_REAL_ASCII(c) ((c) < 0200) | ||
| 356 | |||
| 357 | /* This distinction is not meaningful, except in Emacs. */ | ||
| 358 | # define ISUNIBYTE(c) 1 | ||
| 359 | |||
| 360 | # ifdef isblank | ||
| 361 | # define ISBLANK(c) isblank (c) | ||
| 362 | # else | ||
| 363 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') | ||
| 364 | # endif | ||
| 365 | # ifdef isgraph | ||
| 366 | # define ISGRAPH(c) isgraph (c) | ||
| 367 | # else | ||
| 368 | # define ISGRAPH(c) (isprint (c) && !isspace (c)) | ||
| 369 | # endif | ||
| 370 | |||
| 371 | /* Solaris defines ISPRINT so we must undefine it first. */ | ||
| 372 | # undef ISPRINT | ||
| 373 | # define ISPRINT(c) isprint (c) | ||
| 374 | # define ISDIGIT(c) isdigit (c) | ||
| 375 | # define ISALNUM(c) isalnum (c) | ||
| 376 | # define ISALPHA(c) isalpha (c) | ||
| 377 | # define ISCNTRL(c) iscntrl (c) | ||
| 378 | # define ISLOWER(c) islower (c) | ||
| 379 | # define ISPUNCT(c) ispunct (c) | ||
| 380 | # define ISSPACE(c) isspace (c) | ||
| 381 | # define ISUPPER(c) isupper (c) | ||
| 382 | # define ISXDIGIT(c) isxdigit (c) | ||
| 383 | |||
| 384 | # define ISWORD(c) ISALPHA (c) | ||
| 385 | |||
| 386 | # ifdef _tolower | ||
| 387 | # define TOLOWER(c) _tolower (c) | ||
| 388 | # else | ||
| 389 | # define TOLOWER(c) tolower (c) | ||
| 390 | # endif | ||
| 391 | |||
| 392 | /* How many characters in the character set. */ | ||
| 393 | # define CHAR_SET_SIZE 256 | ||
| 394 | |||
| 395 | # ifdef SYNTAX_TABLE | ||
| 396 | |||
| 397 | extern char *re_syntax_table; | ||
| 398 | |||
| 399 | # else /* not SYNTAX_TABLE */ | ||
| 400 | |||
| 401 | static char re_syntax_table[CHAR_SET_SIZE]; | ||
| 402 | |||
| 403 | static void | ||
| 404 | init_syntax_once (void) | ||
| 405 | { | ||
| 406 | register int c; | ||
| 407 | static int done = 0; | ||
| 408 | |||
| 409 | if (done) | ||
| 410 | return; | ||
| 411 | 151 | ||
| 412 | memset (re_syntax_table, 0, sizeof re_syntax_table); | 152 | #define ISWORD(c) (SYNTAX (c) == Sword) |
| 413 | |||
| 414 | for (c = 0; c < CHAR_SET_SIZE; ++c) | ||
| 415 | if (ISALNUM (c)) | ||
| 416 | re_syntax_table[c] = Sword; | ||
| 417 | |||
| 418 | re_syntax_table['_'] = Ssymbol; | ||
| 419 | |||
| 420 | done = 1; | ||
| 421 | } | ||
| 422 | |||
| 423 | # endif /* not SYNTAX_TABLE */ | ||
| 424 | |||
| 425 | # define SYNTAX(c) re_syntax_table[(c)] | ||
| 426 | |||
| 427 | #endif /* not emacs */ | ||
| 428 | 153 | ||
| 429 | #define SIGN_EXTEND_CHAR(c) ((signed char) (c)) | 154 | #define SIGN_EXTEND_CHAR(c) ((signed char) (c)) |
| 430 | 155 | ||
| 431 | /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we | 156 | /* Use alloca instead of malloc. This is because using malloc in |
| 432 | use `alloca' instead of `malloc'. This is because using malloc in | ||
| 433 | re_search* or re_match* could cause memory leaks when C-g is used | 157 | re_search* or re_match* could cause memory leaks when C-g is used |
| 434 | in Emacs (note that SAFE_ALLOCA could also call malloc, but does so | 158 | in Emacs (note that SAFE_ALLOCA could also call malloc, but does so |
| 435 | via `record_xmalloc' which uses `unwind_protect' to ensure the | 159 | via 'record_xmalloc' which uses 'unwind_protect' to ensure the |
| 436 | memory is freed even in case of non-local exits); also, malloc is | 160 | memory is freed even in case of non-local exits); also, malloc is |
| 437 | slower and causes storage fragmentation. On the other hand, malloc | 161 | slower and causes storage fragmentation. On the other hand, malloc |
| 438 | is more portable, and easier to debug. | 162 | is more portable, and easier to debug. |
| 439 | 163 | ||
| 440 | Because we sometimes use alloca, some routines have to be macros, | 164 | Because we sometimes use alloca, some routines have to be macros, |
| 441 | not functions -- `alloca'-allocated space disappears at the end of the | 165 | not functions -- 'alloca'-allocated space disappears at the end of the |
| 442 | function it is called in. */ | 166 | function it is called in. */ |
| 443 | 167 | ||
| 444 | #ifdef REGEX_MALLOC | ||
| 445 | |||
| 446 | # define REGEX_ALLOCATE malloc | ||
| 447 | # define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) | ||
| 448 | # define REGEX_FREE free | ||
| 449 | |||
| 450 | #else /* not REGEX_MALLOC */ | ||
| 451 | |||
| 452 | # ifdef emacs | ||
| 453 | /* This may be adjusted in main(), if the stack is successfully grown. */ | 168 | /* This may be adjusted in main(), if the stack is successfully grown. */ |
| 454 | ptrdiff_t emacs_re_safe_alloca = MAX_ALLOCA; | 169 | ptrdiff_t emacs_re_safe_alloca = MAX_ALLOCA; |
| 455 | /* Like USE_SAFE_ALLOCA, but use emacs_re_safe_alloca. */ | 170 | /* Like USE_SAFE_ALLOCA, but use emacs_re_safe_alloca. */ |
| 456 | # define REGEX_USE_SAFE_ALLOCA \ | 171 | #define REGEX_USE_SAFE_ALLOCA \ |
| 457 | ptrdiff_t sa_avail = emacs_re_safe_alloca; \ | 172 | USE_SAFE_ALLOCA; sa_avail = emacs_re_safe_alloca |
| 458 | ptrdiff_t sa_count = SPECPDL_INDEX () | ||
| 459 | |||
| 460 | # define REGEX_SAFE_FREE() SAFE_FREE () | ||
| 461 | # define REGEX_ALLOCATE SAFE_ALLOCA | ||
| 462 | # else | ||
| 463 | # include <alloca.h> | ||
| 464 | # define REGEX_ALLOCATE alloca | ||
| 465 | # endif | ||
| 466 | |||
| 467 | /* Assumes a `char *destination' variable. */ | ||
| 468 | # define REGEX_REALLOCATE(source, osize, nsize) \ | ||
| 469 | (destination = REGEX_ALLOCATE (nsize), \ | ||
| 470 | memcpy (destination, source, osize)) | ||
| 471 | |||
| 472 | /* No need to do anything to free, after alloca. */ | ||
| 473 | # define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */ | ||
| 474 | |||
| 475 | #endif /* not REGEX_MALLOC */ | ||
| 476 | |||
| 477 | #ifndef REGEX_USE_SAFE_ALLOCA | ||
| 478 | # define REGEX_USE_SAFE_ALLOCA ((void) 0) | ||
| 479 | # define REGEX_SAFE_FREE() ((void) 0) | ||
| 480 | #endif | ||
| 481 | |||
| 482 | /* Define how to allocate the failure stack. */ | ||
| 483 | |||
| 484 | #if defined REL_ALLOC && defined REGEX_MALLOC | ||
| 485 | |||
| 486 | # define REGEX_ALLOCATE_STACK(size) \ | ||
| 487 | r_alloc (&failure_stack_ptr, (size)) | ||
| 488 | # define REGEX_REALLOCATE_STACK(source, osize, nsize) \ | ||
| 489 | r_re_alloc (&failure_stack_ptr, (nsize)) | ||
| 490 | # define REGEX_FREE_STACK(ptr) \ | ||
| 491 | r_alloc_free (&failure_stack_ptr) | ||
| 492 | |||
| 493 | #else /* not using relocating allocator */ | ||
| 494 | |||
| 495 | # define REGEX_ALLOCATE_STACK(size) REGEX_ALLOCATE (size) | ||
| 496 | # define REGEX_REALLOCATE_STACK(source, o, n) REGEX_REALLOCATE (source, o, n) | ||
| 497 | # define REGEX_FREE_STACK(ptr) REGEX_FREE (ptr) | ||
| 498 | |||
| 499 | #endif /* not using relocating allocator */ | ||
| 500 | 173 | ||
| 174 | /* Assumes a 'char *destination' variable. */ | ||
| 175 | #define REGEX_REALLOCATE(source, osize, nsize) \ | ||
| 176 | (destination = SAFE_ALLOCA (nsize), \ | ||
| 177 | memcpy (destination, source, osize)) | ||
| 501 | 178 | ||
| 502 | /* True if `size1' is non-NULL and PTR is pointing anywhere inside | 179 | /* True if 'size1' is non-NULL and PTR is pointing anywhere inside |
| 503 | `string1' or just past its end. This works if PTR is NULL, which is | 180 | 'string1' or just past its end. This works if PTR is NULL, which is |
| 504 | a good thing. */ | 181 | a good thing. */ |
| 505 | #define FIRST_STRING_P(ptr) \ | 182 | #define FIRST_STRING_P(ptr) \ |
| 506 | (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) | 183 | (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) |
| 507 | 184 | ||
| 508 | /* (Re)Allocate N items of type T using malloc, or fail. */ | 185 | /* (Re)Allocate N items of type T using malloc, or fail. */ |
| 509 | #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) | 186 | #define TALLOC(n, t) ((t *) xmalloc ((n) * sizeof (t))) |
| 510 | #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) | 187 | #define RETALLOC(addr, n, t) ((addr) = (t *) xrealloc (addr, (n) * sizeof (t))) |
| 511 | #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) | ||
| 512 | 188 | ||
| 513 | #define BYTEWIDTH 8 /* In bits. */ | 189 | #define BYTEWIDTH 8 /* In bits. */ |
| 514 | 190 | ||
| 515 | #ifndef emacs | ||
| 516 | # undef max | ||
| 517 | # undef min | ||
| 518 | # define max(a, b) ((a) > (b) ? (a) : (b)) | ||
| 519 | # define min(a, b) ((a) < (b) ? (a) : (b)) | ||
| 520 | #endif | ||
| 521 | |||
| 522 | /* Type of source-pattern and string chars. */ | 191 | /* Type of source-pattern and string chars. */ |
| 523 | typedef const unsigned char re_char; | 192 | typedef const unsigned char re_char; |
| 524 | 193 | ||
| 525 | typedef char boolean; | 194 | static void re_compile_fastmap (struct re_pattern_buffer *); |
| 526 | 195 | static ptrdiff_t re_match_2_internal (struct re_pattern_buffer *bufp, | |
| 527 | static regoff_t re_match_2_internal (struct re_pattern_buffer *bufp, | ||
| 528 | re_char *string1, size_t size1, | 196 | re_char *string1, size_t size1, |
| 529 | re_char *string2, size_t size2, | 197 | re_char *string2, size_t size2, |
| 530 | ssize_t pos, | 198 | ptrdiff_t pos, |
| 531 | struct re_registers *regs, | 199 | struct re_registers *regs, |
| 532 | ssize_t stop); | 200 | ptrdiff_t stop); |
| 533 | 201 | ||
| 534 | /* These are the command codes that appear in compiled regular | 202 | /* These are the command codes that appear in compiled regular |
| 535 | expressions. Some opcodes are followed by argument bytes. A | 203 | expressions. Some opcodes are followed by argument bytes. A |
| @@ -577,7 +245,7 @@ typedef enum | |||
| 577 | 245 | ||
| 578 | /* Stop remembering the text that is matched and store it in a | 246 | /* Stop remembering the text that is matched and store it in a |
| 579 | memory register. Followed by one byte with the register | 247 | memory register. Followed by one byte with the register |
| 580 | number, in the range 0 to one less than `re_nsub' in the | 248 | number, in the range 0 to one less than 're_nsub' in the |
| 581 | pattern buffer. */ | 249 | pattern buffer. */ |
| 582 | stop_memory, | 250 | stop_memory, |
| 583 | 251 | ||
| @@ -591,8 +259,7 @@ typedef enum | |||
| 591 | /* Fail unless at end of line. */ | 259 | /* Fail unless at end of line. */ |
| 592 | endline, | 260 | endline, |
| 593 | 261 | ||
| 594 | /* Succeeds if at beginning of buffer (if emacs) or at beginning | 262 | /* Succeeds if at beginning of buffer. */ |
| 595 | of string to be matched (if not). */ | ||
| 596 | begbuf, | 263 | begbuf, |
| 597 | 264 | ||
| 598 | /* Analogously, for end of buffer/string. */ | 265 | /* Analogously, for end of buffer/string. */ |
| @@ -609,23 +276,23 @@ typedef enum | |||
| 609 | current string position when executed. */ | 276 | current string position when executed. */ |
| 610 | on_failure_keep_string_jump, | 277 | on_failure_keep_string_jump, |
| 611 | 278 | ||
| 612 | /* Just like `on_failure_jump', except that it checks that we | 279 | /* Just like 'on_failure_jump', except that it checks that we |
| 613 | don't get stuck in an infinite loop (matching an empty string | 280 | don't get stuck in an infinite loop (matching an empty string |
| 614 | indefinitely). */ | 281 | indefinitely). */ |
| 615 | on_failure_jump_loop, | 282 | on_failure_jump_loop, |
| 616 | 283 | ||
| 617 | /* Just like `on_failure_jump_loop', except that it checks for | 284 | /* Just like 'on_failure_jump_loop', except that it checks for |
| 618 | a different kind of loop (the kind that shows up with non-greedy | 285 | a different kind of loop (the kind that shows up with non-greedy |
| 619 | operators). This operation has to be immediately preceded | 286 | operators). This operation has to be immediately preceded |
| 620 | by a `no_op'. */ | 287 | by a 'no_op'. */ |
| 621 | on_failure_jump_nastyloop, | 288 | on_failure_jump_nastyloop, |
| 622 | 289 | ||
| 623 | /* A smart `on_failure_jump' used for greedy * and + operators. | 290 | /* A smart 'on_failure_jump' used for greedy * and + operators. |
| 624 | It analyzes the loop before which it is put and if the | 291 | It analyzes the loop before which it is put and if the |
| 625 | loop does not require backtracking, it changes itself to | 292 | loop does not require backtracking, it changes itself to |
| 626 | `on_failure_keep_string_jump' and short-circuits the loop, | 293 | 'on_failure_keep_string_jump' and short-circuits the loop, |
| 627 | else it just defaults to changing itself into `on_failure_jump'. | 294 | else it just defaults to changing itself into 'on_failure_jump'. |
| 628 | It assumes that it is pointing to just past a `jump'. */ | 295 | It assumes that it is pointing to just past a 'jump'. */ |
| 629 | on_failure_jump_smart, | 296 | on_failure_jump_smart, |
| 630 | 297 | ||
| 631 | /* Followed by two-byte relative address and two-byte number n. | 298 | /* Followed by two-byte relative address and two-byte number n. |
| @@ -657,10 +324,9 @@ typedef enum | |||
| 657 | syntaxspec, | 324 | syntaxspec, |
| 658 | 325 | ||
| 659 | /* Matches any character whose syntax is not that specified. */ | 326 | /* Matches any character whose syntax is not that specified. */ |
| 660 | notsyntaxspec | 327 | notsyntaxspec, |
| 661 | 328 | ||
| 662 | #ifdef emacs | 329 | at_dot, /* Succeeds if at point. */ |
| 663 | , at_dot, /* Succeeds if at point. */ | ||
| 664 | 330 | ||
| 665 | /* Matches any character whose category-set contains the specified | 331 | /* Matches any character whose category-set contains the specified |
| 666 | category. The operator is followed by a byte which contains a | 332 | category. The operator is followed by a byte which contains a |
| @@ -671,7 +337,6 @@ typedef enum | |||
| 671 | specified category. The operator is followed by a byte which | 337 | specified category. The operator is followed by a byte which |
| 672 | contains the category code (mnemonic ASCII character). */ | 338 | contains the category code (mnemonic ASCII character). */ |
| 673 | notcategoryspec | 339 | notcategoryspec |
| 674 | #endif /* emacs */ | ||
| 675 | } re_opcode_t; | 340 | } re_opcode_t; |
| 676 | 341 | ||
| 677 | /* Common operations on the compiled pattern. */ | 342 | /* Common operations on the compiled pattern. */ |
| @@ -682,7 +347,7 @@ typedef enum | |||
| 682 | do { \ | 347 | do { \ |
| 683 | (destination)[0] = (number) & 0377; \ | 348 | (destination)[0] = (number) & 0377; \ |
| 684 | (destination)[1] = (number) >> 8; \ | 349 | (destination)[1] = (number) >> 8; \ |
| 685 | } while (0) | 350 | } while (false) |
| 686 | 351 | ||
| 687 | /* Same as STORE_NUMBER, except increment DESTINATION to | 352 | /* Same as STORE_NUMBER, except increment DESTINATION to |
| 688 | the byte after where the number is stored. Therefore, DESTINATION | 353 | the byte after where the number is stored. Therefore, DESTINATION |
| @@ -692,7 +357,7 @@ typedef enum | |||
| 692 | do { \ | 357 | do { \ |
| 693 | STORE_NUMBER (destination, number); \ | 358 | STORE_NUMBER (destination, number); \ |
| 694 | (destination) += 2; \ | 359 | (destination) += 2; \ |
| 695 | } while (0) | 360 | } while (false) |
| 696 | 361 | ||
| 697 | /* Put into DESTINATION a number stored in two contiguous bytes starting | 362 | /* Put into DESTINATION a number stored in two contiguous bytes starting |
| 698 | at SOURCE. */ | 363 | at SOURCE. */ |
| @@ -731,7 +396,7 @@ extract_number_and_incr (re_char **source) | |||
| 731 | (destination)[1] = ((character) >> 8) & 0377; \ | 396 | (destination)[1] = ((character) >> 8) & 0377; \ |
| 732 | (destination)[2] = (character) >> 16; \ | 397 | (destination)[2] = (character) >> 16; \ |
| 733 | (destination) += 3; \ | 398 | (destination) += 3; \ |
| 734 | } while (0) | 399 | } while (false) |
| 735 | 400 | ||
| 736 | /* Put into DESTINATION a character stored in three contiguous bytes | 401 | /* Put into DESTINATION a character stored in three contiguous bytes |
| 737 | starting at SOURCE. */ | 402 | starting at SOURCE. */ |
| @@ -741,7 +406,7 @@ extract_number_and_incr (re_char **source) | |||
| 741 | (destination) = ((source)[0] \ | 406 | (destination) = ((source)[0] \ |
| 742 | | ((source)[1] << 8) \ | 407 | | ((source)[1] << 8) \ |
| 743 | | ((source)[2] << 16)); \ | 408 | | ((source)[2] << 16)); \ |
| 744 | } while (0) | 409 | } while (false) |
| 745 | 410 | ||
| 746 | 411 | ||
| 747 | /* Macros for charset. */ | 412 | /* Macros for charset. */ |
| @@ -755,47 +420,39 @@ extract_number_and_incr (re_char **source) | |||
| 755 | 420 | ||
| 756 | /* Return the address of range table of charset P. But not the start | 421 | /* Return the address of range table of charset P. But not the start |
| 757 | of table itself, but the before where the number of ranges is | 422 | of table itself, but the before where the number of ranges is |
| 758 | stored. `2 +' means to skip re_opcode_t and size of bitmap, | 423 | stored. '2 +' means to skip re_opcode_t and size of bitmap, |
| 759 | and the 2 bytes of flags at the start of the range table. */ | 424 | and the 2 bytes of flags at the start of the range table. */ |
| 760 | #define CHARSET_RANGE_TABLE(p) (&(p)[4 + CHARSET_BITMAP_SIZE (p)]) | 425 | #define CHARSET_RANGE_TABLE(p) (&(p)[4 + CHARSET_BITMAP_SIZE (p)]) |
| 761 | 426 | ||
| 762 | #ifdef emacs | ||
| 763 | /* Extract the bit flags that start a range table. */ | 427 | /* Extract the bit flags that start a range table. */ |
| 764 | #define CHARSET_RANGE_TABLE_BITS(p) \ | 428 | #define CHARSET_RANGE_TABLE_BITS(p) \ |
| 765 | ((p)[2 + CHARSET_BITMAP_SIZE (p)] \ | 429 | ((p)[2 + CHARSET_BITMAP_SIZE (p)] \ |
| 766 | + (p)[3 + CHARSET_BITMAP_SIZE (p)] * 0x100) | 430 | + (p)[3 + CHARSET_BITMAP_SIZE (p)] * 0x100) |
| 767 | #endif | ||
| 768 | 431 | ||
| 769 | /* Return the address of end of RANGE_TABLE. COUNT is number of | 432 | /* Return the address of end of RANGE_TABLE. COUNT is number of |
| 770 | ranges (which is a pair of (start, end)) in the RANGE_TABLE. `* 2' | 433 | ranges (which is a pair of (start, end)) in the RANGE_TABLE. '* 2' |
| 771 | is start of range and end of range. `* 3' is size of each start | 434 | is start of range and end of range. '* 3' is size of each start |
| 772 | and end. */ | 435 | and end. */ |
| 773 | #define CHARSET_RANGE_TABLE_END(range_table, count) \ | 436 | #define CHARSET_RANGE_TABLE_END(range_table, count) \ |
| 774 | ((range_table) + (count) * 2 * 3) | 437 | ((range_table) + (count) * 2 * 3) |
| 775 | 438 | ||
| 776 | /* If DEBUG is defined, Regex prints many voluminous messages about what | 439 | /* If REGEX_EMACS_DEBUG is defined, print many voluminous messages |
| 777 | it is doing (if the variable `debug' is nonzero). If linked with the | 440 | (if the variable regex_emacs_debug is positive). */ |
| 778 | main program in `iregex.c', you can enter patterns and strings | ||
| 779 | interactively. And if linked with the main program in `main.c' and | ||
| 780 | the other test files, you can run the already-written tests. */ | ||
| 781 | 441 | ||
| 782 | #ifdef DEBUG | 442 | #ifdef REGEX_EMACS_DEBUG |
| 783 | 443 | ||
| 784 | /* We use standard I/O for debugging. */ | 444 | /* Use standard I/O for debugging. */ |
| 785 | # include <stdio.h> | 445 | # include <stdio.h> |
| 786 | 446 | ||
| 787 | /* It is useful to test things that ``must'' be true when debugging. */ | 447 | static int regex_emacs_debug = -100000; |
| 788 | # include <assert.h> | ||
| 789 | |||
| 790 | static int debug = -100000; | ||
| 791 | 448 | ||
| 792 | # define DEBUG_STATEMENT(e) e | 449 | # define DEBUG_STATEMENT(e) e |
| 793 | # define DEBUG_PRINT(...) if (debug > 0) printf (__VA_ARGS__) | 450 | # define DEBUG_PRINT(...) if (regex_emacs_debug > 0) printf (__VA_ARGS__) |
| 794 | # define DEBUG_COMPILES_ARGUMENTS | 451 | # define DEBUG_COMPILES_ARGUMENTS |
| 795 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ | 452 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ |
| 796 | if (debug > 0) print_partial_compiled_pattern (s, e) | 453 | if (regex_emacs_debug > 0) print_partial_compiled_pattern (s, e) |
| 797 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ | 454 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ |
| 798 | if (debug > 0) print_double_string (w, s1, sz1, s2, sz2) | 455 | if (regex_emacs_debug > 0) print_double_string (w, s1, sz1, s2, sz2) |
| 799 | 456 | ||
| 800 | 457 | ||
| 801 | /* Print the fastmap in human-readable form. */ | 458 | /* Print the fastmap in human-readable form. */ |
| @@ -1084,7 +741,7 @@ print_compiled_pattern (struct re_pattern_buffer *bufp) | |||
| 1084 | re_char *buffer = bufp->buffer; | 741 | re_char *buffer = bufp->buffer; |
| 1085 | 742 | ||
| 1086 | print_partial_compiled_pattern (buffer, buffer + bufp->used); | 743 | print_partial_compiled_pattern (buffer, buffer + bufp->used); |
| 1087 | printf ("%ld bytes used/%ld bytes allocated.\n", | 744 | printf ("%zu bytes used/%zu bytes allocated.\n", |
| 1088 | bufp->used, bufp->allocated); | 745 | bufp->used, bufp->allocated); |
| 1089 | 746 | ||
| 1090 | if (bufp->fastmap_accurate && bufp->fastmap) | 747 | if (bufp->fastmap_accurate && bufp->fastmap) |
| @@ -1096,9 +753,6 @@ print_compiled_pattern (struct re_pattern_buffer *bufp) | |||
| 1096 | printf ("re_nsub: %zu\t", bufp->re_nsub); | 753 | printf ("re_nsub: %zu\t", bufp->re_nsub); |
| 1097 | printf ("regs_alloc: %d\t", bufp->regs_allocated); | 754 | printf ("regs_alloc: %d\t", bufp->regs_allocated); |
| 1098 | printf ("can_be_null: %d\t", bufp->can_be_null); | 755 | printf ("can_be_null: %d\t", bufp->can_be_null); |
| 1099 | printf ("no_sub: %d\t", bufp->no_sub); | ||
| 1100 | printf ("not_bol: %d\t", bufp->not_bol); | ||
| 1101 | printf ("not_eol: %d\t", bufp->not_eol); | ||
| 1102 | #ifndef emacs | 756 | #ifndef emacs |
| 1103 | printf ("syntax: %lx\n", bufp->syntax); | 757 | printf ("syntax: %lx\n", bufp->syntax); |
| 1104 | #endif | 758 | #endif |
| @@ -1130,151 +784,105 @@ print_double_string (re_char *where, re_char *string1, ssize_t size1, | |||
| 1130 | } | 784 | } |
| 1131 | } | 785 | } |
| 1132 | 786 | ||
| 1133 | #else /* not DEBUG */ | 787 | #else /* not REGEX_EMACS_DEBUG */ |
| 1134 | |||
| 1135 | # undef assert | ||
| 1136 | # define assert(e) | ||
| 1137 | 788 | ||
| 1138 | # define DEBUG_STATEMENT(e) | 789 | # define DEBUG_STATEMENT(e) |
| 1139 | # define DEBUG_PRINT(...) | 790 | # define DEBUG_PRINT(...) |
| 1140 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) | 791 | # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) |
| 1141 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) | 792 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) |
| 1142 | 793 | ||
| 1143 | #endif /* not DEBUG */ | 794 | #endif /* not REGEX_EMACS_DEBUG */ |
| 1144 | 795 | ||
| 1145 | #ifndef emacs | 796 | typedef enum |
| 1146 | |||
| 1147 | /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can | ||
| 1148 | also be assigned to arbitrarily: each pattern buffer stores its own | ||
| 1149 | syntax, so it can be changed between regex compilations. */ | ||
| 1150 | /* This has no initializer because initialized variables in Emacs | ||
| 1151 | become read-only after dumping. */ | ||
| 1152 | reg_syntax_t re_syntax_options; | ||
| 1153 | |||
| 1154 | |||
| 1155 | /* Specify the precise syntax of regexps for compilation. This provides | ||
| 1156 | for compatibility for various utilities which historically have | ||
| 1157 | different, incompatible syntaxes. | ||
| 1158 | |||
| 1159 | The argument SYNTAX is a bit mask comprised of the various bits | ||
| 1160 | defined in regex.h. We return the old syntax. */ | ||
| 1161 | |||
| 1162 | reg_syntax_t | ||
| 1163 | re_set_syntax (reg_syntax_t syntax) | ||
| 1164 | { | 797 | { |
| 1165 | reg_syntax_t ret = re_syntax_options; | 798 | REG_NOERROR = 0, /* Success. */ |
| 1166 | 799 | REG_NOMATCH, /* Didn't find a match (for regexec). */ | |
| 1167 | re_syntax_options = syntax; | 800 | |
| 1168 | return ret; | 801 | /* POSIX regcomp return error codes. (In the order listed in the |
| 1169 | } | 802 | standard.) An older version of this code supported the POSIX |
| 1170 | WEAK_ALIAS (__re_set_syntax, re_set_syntax) | 803 | API; this version continues to use these names internally. */ |
| 1171 | 804 | REG_BADPAT, /* Invalid pattern. */ | |
| 1172 | #endif | 805 | REG_ECOLLATE, /* Not implemented. */ |
| 1173 | 806 | REG_ECTYPE, /* Invalid character class name. */ | |
| 1174 | /* This table gives an error message for each of the error codes listed | 807 | REG_EESCAPE, /* Trailing backslash. */ |
| 1175 | in regex.h. Obviously the order here has to be same as there. | 808 | REG_ESUBREG, /* Invalid back reference. */ |
| 1176 | POSIX doesn't require that we do anything for REG_NOERROR, | 809 | REG_EBRACK, /* Unmatched left bracket. */ |
| 1177 | but why not be nice? */ | 810 | REG_EPAREN, /* Parenthesis imbalance. */ |
| 811 | REG_EBRACE, /* Unmatched \{. */ | ||
| 812 | REG_BADBR, /* Invalid contents of \{\}. */ | ||
| 813 | REG_ERANGE, /* Invalid range end. */ | ||
| 814 | REG_ESPACE, /* Ran out of memory. */ | ||
| 815 | REG_BADRPT, /* No preceding re for repetition op. */ | ||
| 816 | |||
| 817 | /* Error codes we've added. */ | ||
| 818 | REG_EEND, /* Premature end. */ | ||
| 819 | REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ | ||
| 820 | REG_ERPAREN, /* Unmatched ) or \); not returned from regcomp. */ | ||
| 821 | REG_ERANGEX, /* Range striding over charsets. */ | ||
| 822 | REG_ESIZEBR /* n or m too big in \{n,m\} */ | ||
| 823 | } reg_errcode_t; | ||
| 1178 | 824 | ||
| 1179 | static const char *re_error_msgid[] = | 825 | static const char *re_error_msgid[] = |
| 1180 | { | 826 | { |
| 1181 | gettext_noop ("Success"), /* REG_NOERROR */ | 827 | [REG_NOERROR] = "Success", |
| 1182 | gettext_noop ("No match"), /* REG_NOMATCH */ | 828 | [REG_NOMATCH] = "No match", |
| 1183 | gettext_noop ("Invalid regular expression"), /* REG_BADPAT */ | 829 | [REG_BADPAT] = "Invalid regular expression", |
| 1184 | gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */ | 830 | [REG_ECOLLATE] = "Invalid collation character", |
| 1185 | gettext_noop ("Invalid character class name"), /* REG_ECTYPE */ | 831 | [REG_ECTYPE] = "Invalid character class name", |
| 1186 | gettext_noop ("Trailing backslash"), /* REG_EESCAPE */ | 832 | [REG_EESCAPE] = "Trailing backslash", |
| 1187 | gettext_noop ("Invalid back reference"), /* REG_ESUBREG */ | 833 | [REG_ESUBREG] = "Invalid back reference", |
| 1188 | gettext_noop ("Unmatched [ or [^"), /* REG_EBRACK */ | 834 | [REG_EBRACK] = "Unmatched [ or [^", |
| 1189 | gettext_noop ("Unmatched ( or \\("), /* REG_EPAREN */ | 835 | [REG_EPAREN] = "Unmatched ( or \\(", |
| 1190 | gettext_noop ("Unmatched \\{"), /* REG_EBRACE */ | 836 | [REG_EBRACE] = "Unmatched \\{", |
| 1191 | gettext_noop ("Invalid content of \\{\\}"), /* REG_BADBR */ | 837 | [REG_BADBR] = "Invalid content of \\{\\}", |
| 1192 | gettext_noop ("Invalid range end"), /* REG_ERANGE */ | 838 | [REG_ERANGE] = "Invalid range end", |
| 1193 | gettext_noop ("Memory exhausted"), /* REG_ESPACE */ | 839 | [REG_ESPACE] = "Memory exhausted", |
| 1194 | gettext_noop ("Invalid preceding regular expression"), /* REG_BADRPT */ | 840 | [REG_BADRPT] = "Invalid preceding regular expression", |
| 1195 | gettext_noop ("Premature end of regular expression"), /* REG_EEND */ | 841 | [REG_EEND] = "Premature end of regular expression", |
| 1196 | gettext_noop ("Regular expression too big"), /* REG_ESIZE */ | 842 | [REG_ESIZE] = "Regular expression too big", |
| 1197 | gettext_noop ("Unmatched ) or \\)"), /* REG_ERPAREN */ | 843 | [REG_ERPAREN] = "Unmatched ) or \\)", |
| 1198 | gettext_noop ("Range striding over charsets"), /* REG_ERANGEX */ | 844 | [REG_ERANGEX ] = "Range striding over charsets", |
| 1199 | gettext_noop ("Invalid content of \\{\\}, repetitions too big") /* REG_ESIZEBR */ | 845 | [REG_ESIZEBR ] = "Invalid content of \\{\\}", |
| 1200 | }; | 846 | }; |
| 1201 | |||
| 1202 | /* Whether to allocate memory during matching. */ | ||
| 1203 | |||
| 1204 | /* Define MATCH_MAY_ALLOCATE to allow the searching and matching | ||
| 1205 | functions allocate memory for the failure stack and registers. | ||
| 1206 | Normally should be defined, because otherwise searching and | ||
| 1207 | matching routines will have much smaller memory resources at their | ||
| 1208 | disposal, and therefore might fail to handle complex regexps. | ||
| 1209 | Therefore undefine MATCH_MAY_ALLOCATE only in the following | ||
| 1210 | exceptional situations: | ||
| 1211 | |||
| 1212 | . When running on a system where memory is at premium. | ||
| 1213 | . When alloca cannot be used at all, perhaps due to bugs in | ||
| 1214 | its implementation, or its being unavailable, or due to a | ||
| 1215 | very small stack size. This requires to define REGEX_MALLOC | ||
| 1216 | to use malloc instead, which in turn could lead to memory | ||
| 1217 | leaks if search is interrupted by a signal. (For these | ||
| 1218 | reasons, defining REGEX_MALLOC when building Emacs | ||
| 1219 | automatically undefines MATCH_MAY_ALLOCATE, but outside | ||
| 1220 | Emacs you may not care about memory leaks.) If you want to | ||
| 1221 | prevent the memory leaks, undefine MATCH_MAY_ALLOCATE. | ||
| 1222 | . When code that calls the searching and matching functions | ||
| 1223 | cannot allow memory allocation, for whatever reasons. */ | ||
| 1224 | |||
| 1225 | /* Normally, this is fine. */ | ||
| 1226 | #define MATCH_MAY_ALLOCATE | ||
| 1227 | |||
| 1228 | /* The match routines may not allocate if (1) they would do it with malloc | ||
| 1229 | and (2) it's not safe for them to use malloc. | ||
| 1230 | Note that if REL_ALLOC is defined, matching would not use malloc for the | ||
| 1231 | failure stack, but we would still use it for the register vectors; | ||
| 1232 | so REL_ALLOC should not affect this. */ | ||
| 1233 | #if defined REGEX_MALLOC && defined emacs | ||
| 1234 | # undef MATCH_MAY_ALLOCATE | ||
| 1235 | #endif | ||
| 1236 | 847 | ||
| 1237 | /* While regex matching of a single compiled pattern isn't reentrant | 848 | /* For 'regs_allocated'. */ |
| 1238 | (because we compile regexes to bytecode programs, and the bytecode | 849 | enum { REGS_UNALLOCATED, REGS_REALLOCATE, REGS_FIXED }; |
| 1239 | programs are self-modifying), the regex machinery must nevertheless | ||
| 1240 | be reentrant with respect to _different_ patterns, and we do that | ||
| 1241 | by avoiding global variables and using MATCH_MAY_ALLOCATE. */ | ||
| 1242 | #if !defined MATCH_MAY_ALLOCATE && defined emacs | ||
| 1243 | # error "Emacs requires MATCH_MAY_ALLOCATE" | ||
| 1244 | #endif | ||
| 1245 | 850 | ||
| 851 | /* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer, | ||
| 852 | 're_match_2' returns information about at least this many registers | ||
| 853 | the first time a 'regs' structure is passed. */ | ||
| 854 | enum { RE_NREGS = 30 }; | ||
| 1246 | 855 | ||
| 856 | /* The searching and matching functions allocate memory for the | ||
| 857 | failure stack and registers. Otherwise searching and matching | ||
| 858 | routines would have much smaller memory resources at their | ||
| 859 | disposal, and therefore might fail to handle complex regexps. */ | ||
| 860 | |||
| 1247 | /* Failure stack declarations and macros; both re_compile_fastmap and | 861 | /* Failure stack declarations and macros; both re_compile_fastmap and |
| 1248 | re_match_2 use a failure stack. These have to be macros because of | 862 | re_match_2 use a failure stack. These have to be macros because of |
| 1249 | REGEX_ALLOCATE_STACK. */ | 863 | SAFE_ALLOCA. */ |
| 1250 | 864 | ||
| 1251 | 865 | ||
| 1252 | /* Approximate number of failure points for which to initially allocate space | 866 | /* Approximate number of failure points for which to initially allocate space |
| 1253 | when matching. If this number is exceeded, we allocate more | 867 | when matching. If this number is exceeded, we allocate more |
| 1254 | space, so it is not a hard limit. */ | 868 | space, so it is not a hard limit. */ |
| 1255 | #ifndef INIT_FAILURE_ALLOC | 869 | #define INIT_FAILURE_ALLOC 20 |
| 1256 | # define INIT_FAILURE_ALLOC 20 | ||
| 1257 | #endif | ||
| 1258 | 870 | ||
| 1259 | /* Roughly the maximum number of failure points on the stack. Would be | 871 | /* Roughly the maximum number of failure points on the stack. Would be |
| 1260 | exactly that if always used TYPICAL_FAILURE_SIZE items each time we failed. | 872 | exactly that if failure always used TYPICAL_FAILURE_SIZE items. |
| 1261 | This is a variable only so users of regex can assign to it; we never | 873 | This is a variable only so users of regex can assign to it; we never |
| 1262 | change it ourselves. We always multiply it by TYPICAL_FAILURE_SIZE | 874 | change it ourselves. We always multiply it by TYPICAL_FAILURE_SIZE |
| 1263 | before using it, so it should probably be a byte-count instead. */ | 875 | before using it, so it should probably be a byte-count instead. */ |
| 1264 | # if defined MATCH_MAY_ALLOCATE | ||
| 1265 | /* Note that 4400 was enough to cause a crash on Alpha OSF/1, | 876 | /* Note that 4400 was enough to cause a crash on Alpha OSF/1, |
| 1266 | whose default stack limit is 2mb. In order for a larger | 877 | whose default stack limit is 2mb. In order for a larger |
| 1267 | value to work reliably, you have to try to make it accord | 878 | value to work reliably, you have to try to make it accord |
| 1268 | with the process stack limit. */ | 879 | with the process stack limit. */ |
| 1269 | size_t emacs_re_max_failures = 40000; | 880 | size_t emacs_re_max_failures = 40000; |
| 1270 | # else | ||
| 1271 | size_t emacs_re_max_failures = 4000; | ||
| 1272 | # endif | ||
| 1273 | 881 | ||
| 1274 | union fail_stack_elt | 882 | union fail_stack_elt |
| 1275 | { | 883 | { |
| 1276 | re_char *pointer; | 884 | re_char *pointer; |
| 1277 | /* This should be the biggest `int' that's no bigger than a pointer. */ | 885 | /* This should be the biggest 'int' that's no bigger than a pointer. */ |
| 1278 | long integer; | 886 | long integer; |
| 1279 | }; | 887 | }; |
| 1280 | 888 | ||
| @@ -1291,45 +899,28 @@ typedef struct | |||
| 1291 | #define FAIL_STACK_EMPTY() (fail_stack.frame == 0) | 899 | #define FAIL_STACK_EMPTY() (fail_stack.frame == 0) |
| 1292 | 900 | ||
| 1293 | 901 | ||
| 1294 | /* Define macros to initialize and free the failure stack. | 902 | /* Define macros to initialize and free the failure stack. */ |
| 1295 | Do `return -2' if the alloc fails. */ | ||
| 1296 | 903 | ||
| 1297 | #ifdef MATCH_MAY_ALLOCATE | 904 | #define INIT_FAIL_STACK() \ |
| 1298 | # define INIT_FAIL_STACK() \ | ||
| 1299 | do { \ | 905 | do { \ |
| 1300 | fail_stack.stack = \ | 906 | fail_stack.stack = \ |
| 1301 | REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \ | 907 | SAFE_ALLOCA (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \ |
| 1302 | * sizeof (fail_stack_elt_t)); \ | 908 | * sizeof (fail_stack_elt_t)); \ |
| 1303 | \ | ||
| 1304 | if (fail_stack.stack == NULL) \ | ||
| 1305 | return -2; \ | ||
| 1306 | \ | ||
| 1307 | fail_stack.size = INIT_FAILURE_ALLOC; \ | 909 | fail_stack.size = INIT_FAILURE_ALLOC; \ |
| 1308 | fail_stack.avail = 0; \ | 910 | fail_stack.avail = 0; \ |
| 1309 | fail_stack.frame = 0; \ | 911 | fail_stack.frame = 0; \ |
| 1310 | } while (0) | 912 | } while (false) |
| 1311 | #else | ||
| 1312 | # define INIT_FAIL_STACK() \ | ||
| 1313 | do { \ | ||
| 1314 | fail_stack.avail = 0; \ | ||
| 1315 | fail_stack.frame = 0; \ | ||
| 1316 | } while (0) | ||
| 1317 | |||
| 1318 | # define RETALLOC_IF(addr, n, t) \ | ||
| 1319 | if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t) | ||
| 1320 | #endif | ||
| 1321 | 913 | ||
| 1322 | 914 | ||
| 1323 | /* Double the size of FAIL_STACK, up to a limit | 915 | /* Double the size of FAIL_STACK, up to a limit |
| 1324 | which allows approximately `emacs_re_max_failures' items. | 916 | which allows approximately 'emacs_re_max_failures' items. |
| 1325 | 917 | ||
| 1326 | Return 1 if succeeds, and 0 if either ran out of memory | 918 | Return 1 if succeeds, and 0 if either ran out of memory |
| 1327 | allocating space for it or it was already too large. | 919 | allocating space for it or it was already too large. |
| 1328 | 920 | ||
| 1329 | REGEX_REALLOCATE_STACK requires `destination' be declared. */ | 921 | REGEX_REALLOCATE requires 'destination' be declared. */ |
| 1330 | 922 | ||
| 1331 | /* Factor to increase the failure stack size by | 923 | /* Factor to increase the failure stack size by. |
| 1332 | when we increase it. | ||
| 1333 | This used to be 2, but 2 was too wasteful | 924 | This used to be 2, but 2 was too wasteful |
| 1334 | because the old discarded stacks added up to as much space | 925 | because the old discarded stacks added up to as much space |
| 1335 | were as ultimate, maximum-size stack. */ | 926 | were as ultimate, maximum-size stack. */ |
| @@ -1339,34 +930,31 @@ typedef struct | |||
| 1339 | (((fail_stack).size >= emacs_re_max_failures * TYPICAL_FAILURE_SIZE) \ | 930 | (((fail_stack).size >= emacs_re_max_failures * TYPICAL_FAILURE_SIZE) \ |
| 1340 | ? 0 \ | 931 | ? 0 \ |
| 1341 | : ((fail_stack).stack \ | 932 | : ((fail_stack).stack \ |
| 1342 | = REGEX_REALLOCATE_STACK ((fail_stack).stack, \ | 933 | = REGEX_REALLOCATE ((fail_stack).stack, \ |
| 1343 | (fail_stack).size * sizeof (fail_stack_elt_t), \ | 934 | (fail_stack).size * sizeof (fail_stack_elt_t), \ |
| 1344 | min (emacs_re_max_failures * TYPICAL_FAILURE_SIZE, \ | 935 | min (emacs_re_max_failures * TYPICAL_FAILURE_SIZE, \ |
| 1345 | ((fail_stack).size * FAIL_STACK_GROWTH_FACTOR)) \ | 936 | ((fail_stack).size * FAIL_STACK_GROWTH_FACTOR)) \ |
| 1346 | * sizeof (fail_stack_elt_t)), \ | 937 | * sizeof (fail_stack_elt_t)), \ |
| 1347 | \ | 938 | ((fail_stack).size \ |
| 1348 | (fail_stack).stack == NULL \ | 939 | = (min (emacs_re_max_failures * TYPICAL_FAILURE_SIZE, \ |
| 1349 | ? 0 \ | 940 | ((fail_stack).size * FAIL_STACK_GROWTH_FACTOR)))), \ |
| 1350 | : ((fail_stack).size \ | 941 | 1)) |
| 1351 | = (min (emacs_re_max_failures * TYPICAL_FAILURE_SIZE, \ | ||
| 1352 | ((fail_stack).size * FAIL_STACK_GROWTH_FACTOR))), \ | ||
| 1353 | 1))) | ||
| 1354 | 942 | ||
| 1355 | 943 | ||
| 1356 | /* Push a pointer value onto the failure stack. | 944 | /* Push a pointer value onto the failure stack. |
| 1357 | Assumes the variable `fail_stack'. Probably should only | 945 | Assumes the variable 'fail_stack'. Probably should only |
| 1358 | be called from within `PUSH_FAILURE_POINT'. */ | 946 | be called from within 'PUSH_FAILURE_POINT'. */ |
| 1359 | #define PUSH_FAILURE_POINTER(item) \ | 947 | #define PUSH_FAILURE_POINTER(item) \ |
| 1360 | fail_stack.stack[fail_stack.avail++].pointer = (item) | 948 | fail_stack.stack[fail_stack.avail++].pointer = (item) |
| 1361 | 949 | ||
| 1362 | /* This pushes an integer-valued item onto the failure stack. | 950 | /* This pushes an integer-valued item onto the failure stack. |
| 1363 | Assumes the variable `fail_stack'. Probably should only | 951 | Assumes the variable 'fail_stack'. Probably should only |
| 1364 | be called from within `PUSH_FAILURE_POINT'. */ | 952 | be called from within 'PUSH_FAILURE_POINT'. */ |
| 1365 | #define PUSH_FAILURE_INT(item) \ | 953 | #define PUSH_FAILURE_INT(item) \ |
| 1366 | fail_stack.stack[fail_stack.avail++].integer = (item) | 954 | fail_stack.stack[fail_stack.avail++].integer = (item) |
| 1367 | 955 | ||
| 1368 | /* These POP... operations complement the PUSH... operations. | 956 | /* These POP... operations complement the PUSH... operations. |
| 1369 | All assume that `fail_stack' is nonempty. */ | 957 | All assume that 'fail_stack' is nonempty. */ |
| 1370 | #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer | 958 | #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer |
| 1371 | #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer | 959 | #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer |
| 1372 | 960 | ||
| @@ -1384,8 +972,8 @@ typedef struct | |||
| 1384 | while (REMAINING_AVAIL_SLOTS <= space) { \ | 972 | while (REMAINING_AVAIL_SLOTS <= space) { \ |
| 1385 | if (!GROW_FAIL_STACK (fail_stack)) \ | 973 | if (!GROW_FAIL_STACK (fail_stack)) \ |
| 1386 | return -2; \ | 974 | return -2; \ |
| 1387 | DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\ | 975 | DEBUG_PRINT ("\n Doubled stack; size now: %zu\n", (fail_stack).size);\ |
| 1388 | DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\ | 976 | DEBUG_PRINT (" slots available: %zu\n", REMAINING_AVAIL_SLOTS);\ |
| 1389 | } | 977 | } |
| 1390 | 978 | ||
| 1391 | /* Push register NUM onto the stack. */ | 979 | /* Push register NUM onto the stack. */ |
| @@ -1399,7 +987,7 @@ do { \ | |||
| 1399 | PUSH_FAILURE_POINTER (regstart[n]); \ | 987 | PUSH_FAILURE_POINTER (regstart[n]); \ |
| 1400 | PUSH_FAILURE_POINTER (regend[n]); \ | 988 | PUSH_FAILURE_POINTER (regend[n]); \ |
| 1401 | PUSH_FAILURE_INT (n); \ | 989 | PUSH_FAILURE_INT (n); \ |
| 1402 | } while (0) | 990 | } while (false) |
| 1403 | 991 | ||
| 1404 | /* Change the counter's value to VAL, but make sure that it will | 992 | /* Change the counter's value to VAL, but make sure that it will |
| 1405 | be reset when backtracking. */ | 993 | be reset when backtracking. */ |
| @@ -1414,7 +1002,7 @@ do { \ | |||
| 1414 | PUSH_FAILURE_POINTER (ptr); \ | 1002 | PUSH_FAILURE_POINTER (ptr); \ |
| 1415 | PUSH_FAILURE_INT (-1); \ | 1003 | PUSH_FAILURE_INT (-1); \ |
| 1416 | STORE_NUMBER (ptr, val); \ | 1004 | STORE_NUMBER (ptr, val); \ |
| 1417 | } while (0) | 1005 | } while (false) |
| 1418 | 1006 | ||
| 1419 | /* Pop a saved register off the stack. */ | 1007 | /* Pop a saved register off the stack. */ |
| 1420 | #define POP_FAILURE_REG_OR_COUNT() \ | 1008 | #define POP_FAILURE_REG_OR_COUNT() \ |
| @@ -1423,7 +1011,7 @@ do { \ | |||
| 1423 | if (pfreg == -1) \ | 1011 | if (pfreg == -1) \ |
| 1424 | { \ | 1012 | { \ |
| 1425 | /* It's a counter. */ \ | 1013 | /* It's a counter. */ \ |
| 1426 | /* Here, we discard `const', making re_match non-reentrant. */ \ | 1014 | /* Discard 'const', making re_search non-reentrant. */ \ |
| 1427 | unsigned char *ptr = (unsigned char *) POP_FAILURE_POINTER (); \ | 1015 | unsigned char *ptr = (unsigned char *) POP_FAILURE_POINTER (); \ |
| 1428 | pfreg = POP_FAILURE_INT (); \ | 1016 | pfreg = POP_FAILURE_INT (); \ |
| 1429 | STORE_NUMBER (ptr, pfreg); \ | 1017 | STORE_NUMBER (ptr, pfreg); \ |
| @@ -1436,19 +1024,19 @@ do { \ | |||
| 1436 | DEBUG_PRINT (" Pop reg %ld (spanning %p -> %p)\n", \ | 1024 | DEBUG_PRINT (" Pop reg %ld (spanning %p -> %p)\n", \ |
| 1437 | pfreg, regstart[pfreg], regend[pfreg]); \ | 1025 | pfreg, regstart[pfreg], regend[pfreg]); \ |
| 1438 | } \ | 1026 | } \ |
| 1439 | } while (0) | 1027 | } while (false) |
| 1440 | 1028 | ||
| 1441 | /* Check that we are not stuck in an infinite loop. */ | 1029 | /* Check that we are not stuck in an infinite loop. */ |
| 1442 | #define CHECK_INFINITE_LOOP(pat_cur, string_place) \ | 1030 | #define CHECK_INFINITE_LOOP(pat_cur, string_place) \ |
| 1443 | do { \ | 1031 | do { \ |
| 1444 | ssize_t failure = TOP_FAILURE_HANDLE (); \ | 1032 | ptrdiff_t failure = TOP_FAILURE_HANDLE (); \ |
| 1445 | /* Check for infinite matching loops */ \ | 1033 | /* Check for infinite matching loops */ \ |
| 1446 | while (failure > 0 \ | 1034 | while (failure > 0 \ |
| 1447 | && (FAILURE_STR (failure) == string_place \ | 1035 | && (FAILURE_STR (failure) == string_place \ |
| 1448 | || FAILURE_STR (failure) == NULL)) \ | 1036 | || FAILURE_STR (failure) == NULL)) \ |
| 1449 | { \ | 1037 | { \ |
| 1450 | assert (FAILURE_PAT (failure) >= bufp->buffer \ | 1038 | eassert (FAILURE_PAT (failure) >= bufp->buffer \ |
| 1451 | && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \ | 1039 | && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \ |
| 1452 | if (FAILURE_PAT (failure) == pat_cur) \ | 1040 | if (FAILURE_PAT (failure) == pat_cur) \ |
| 1453 | { \ | 1041 | { \ |
| 1454 | cycle = 1; \ | 1042 | cycle = 1; \ |
| @@ -1458,47 +1046,44 @@ do { \ | |||
| 1458 | failure = NEXT_FAILURE_HANDLE(failure); \ | 1046 | failure = NEXT_FAILURE_HANDLE(failure); \ |
| 1459 | } \ | 1047 | } \ |
| 1460 | DEBUG_PRINT (" Other string: %p\n", FAILURE_STR (failure)); \ | 1048 | DEBUG_PRINT (" Other string: %p\n", FAILURE_STR (failure)); \ |
| 1461 | } while (0) | 1049 | } while (false) |
| 1462 | 1050 | ||
| 1463 | /* Push the information about the state we will need | 1051 | /* Push the information about the state we will need |
| 1464 | if we ever fail back to it. | 1052 | if we ever fail back to it. |
| 1465 | 1053 | ||
| 1466 | Requires variables fail_stack, regstart, regend and | 1054 | Requires variables fail_stack, regstart, regend and |
| 1467 | num_regs be declared. GROW_FAIL_STACK requires `destination' be | 1055 | num_regs be declared. GROW_FAIL_STACK requires 'destination' be |
| 1468 | declared. | 1056 | declared. |
| 1469 | 1057 | ||
| 1470 | Does `return FAILURE_CODE' if runs out of memory. */ | 1058 | Does 'return FAILURE_CODE' if runs out of memory. */ |
| 1471 | 1059 | ||
| 1472 | #define PUSH_FAILURE_POINT(pattern, string_place) \ | 1060 | #define PUSH_FAILURE_POINT(pattern, string_place) \ |
| 1473 | do { \ | 1061 | do { \ |
| 1474 | char *destination; \ | 1062 | char *destination; \ |
| 1475 | /* Must be int, so when we don't save any registers, the arithmetic \ | ||
| 1476 | of 0 + -1 isn't done as unsigned. */ \ | ||
| 1477 | \ | ||
| 1478 | DEBUG_STATEMENT (nfailure_points_pushed++); \ | 1063 | DEBUG_STATEMENT (nfailure_points_pushed++); \ |
| 1479 | DEBUG_PRINT ("\nPUSH_FAILURE_POINT:\n"); \ | 1064 | DEBUG_PRINT ("\nPUSH_FAILURE_POINT:\n"); \ |
| 1480 | DEBUG_PRINT (" Before push, next avail: %zd\n", (fail_stack).avail); \ | 1065 | DEBUG_PRINT (" Before push, next avail: %zu\n", (fail_stack).avail); \ |
| 1481 | DEBUG_PRINT (" size: %zd\n", (fail_stack).size);\ | 1066 | DEBUG_PRINT (" size: %zu\n", (fail_stack).size);\ |
| 1482 | \ | 1067 | \ |
| 1483 | ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \ | 1068 | ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \ |
| 1484 | \ | 1069 | \ |
| 1485 | DEBUG_PRINT ("\n"); \ | 1070 | DEBUG_PRINT ("\n"); \ |
| 1486 | \ | 1071 | \ |
| 1487 | DEBUG_PRINT (" Push frame index: %zd\n", fail_stack.frame); \ | 1072 | DEBUG_PRINT (" Push frame index: %zu\n", fail_stack.frame); \ |
| 1488 | PUSH_FAILURE_INT (fail_stack.frame); \ | 1073 | PUSH_FAILURE_INT (fail_stack.frame); \ |
| 1489 | \ | 1074 | \ |
| 1490 | DEBUG_PRINT (" Push string %p: \"", string_place); \ | 1075 | DEBUG_PRINT (" Push string %p: \"", string_place); \ |
| 1491 | DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\ | 1076 | DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\ |
| 1492 | DEBUG_PRINT ("\"\n"); \ | 1077 | DEBUG_PRINT ("\"\n"); \ |
| 1493 | PUSH_FAILURE_POINTER (string_place); \ | 1078 | PUSH_FAILURE_POINTER (string_place); \ |
| 1494 | \ | 1079 | \ |
| 1495 | DEBUG_PRINT (" Push pattern %p: ", pattern); \ | 1080 | DEBUG_PRINT (" Push pattern %p: ", pattern); \ |
| 1496 | DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \ | 1081 | DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \ |
| 1497 | PUSH_FAILURE_POINTER (pattern); \ | 1082 | PUSH_FAILURE_POINTER (pattern); \ |
| 1498 | \ | 1083 | \ |
| 1499 | /* Close the frame by moving the frame pointer past it. */ \ | 1084 | /* Close the frame by moving the frame pointer past it. */ \ |
| 1500 | fail_stack.frame = fail_stack.avail; \ | 1085 | fail_stack.frame = fail_stack.avail; \ |
| 1501 | } while (0) | 1086 | } while (false) |
| 1502 | 1087 | ||
| 1503 | /* Estimate the size of data pushed by a typical failure stack entry. | 1088 | /* Estimate the size of data pushed by a typical failure stack entry. |
| 1504 | An estimate is all we need, because all we use this for | 1089 | An estimate is all we need, because all we use this for |
| @@ -1510,24 +1095,24 @@ do { \ | |||
| 1510 | #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) | 1095 | #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) |
| 1511 | 1096 | ||
| 1512 | 1097 | ||
| 1513 | /* Pops what PUSH_FAIL_STACK pushes. | 1098 | /* Pop what PUSH_FAIL_STACK pushes. |
| 1514 | 1099 | ||
| 1515 | We restore into the parameters, all of which should be lvalues: | 1100 | Restore into the parameters, all of which should be lvalues: |
| 1516 | STR -- the saved data position. | 1101 | STR -- the saved data position. |
| 1517 | PAT -- the saved pattern position. | 1102 | PAT -- the saved pattern position. |
| 1518 | REGSTART, REGEND -- arrays of string positions. | 1103 | REGSTART, REGEND -- arrays of string positions. |
| 1519 | 1104 | ||
| 1520 | Also assumes the variables `fail_stack' and (if debugging), `bufp', | 1105 | Also assume the variables FAIL_STACK and (if debugging) BUFP, PEND, |
| 1521 | `pend', `string1', `size1', `string2', and `size2'. */ | 1106 | STRING1, SIZE1, STRING2, and SIZE2. */ |
| 1522 | 1107 | ||
| 1523 | #define POP_FAILURE_POINT(str, pat) \ | 1108 | #define POP_FAILURE_POINT(str, pat) \ |
| 1524 | do { \ | 1109 | do { \ |
| 1525 | assert (!FAIL_STACK_EMPTY ()); \ | 1110 | eassert (!FAIL_STACK_EMPTY ()); \ |
| 1526 | \ | 1111 | \ |
| 1527 | /* Remove failure points and point to how many regs pushed. */ \ | 1112 | /* Remove failure points and point to how many regs pushed. */ \ |
| 1528 | DEBUG_PRINT ("POP_FAILURE_POINT:\n"); \ | 1113 | DEBUG_PRINT ("POP_FAILURE_POINT:\n"); \ |
| 1529 | DEBUG_PRINT (" Before pop, next avail: %zd\n", fail_stack.avail); \ | 1114 | DEBUG_PRINT (" Before pop, next avail: %zu\n", fail_stack.avail); \ |
| 1530 | DEBUG_PRINT (" size: %zd\n", fail_stack.size); \ | 1115 | DEBUG_PRINT (" size: %zu\n", fail_stack.size); \ |
| 1531 | \ | 1116 | \ |
| 1532 | /* Pop the saved registers. */ \ | 1117 | /* Pop the saved registers. */ \ |
| 1533 | while (fail_stack.frame < fail_stack.avail) \ | 1118 | while (fail_stack.frame < fail_stack.avail) \ |
| @@ -1546,13 +1131,13 @@ do { \ | |||
| 1546 | DEBUG_PRINT ("\"\n"); \ | 1131 | DEBUG_PRINT ("\"\n"); \ |
| 1547 | \ | 1132 | \ |
| 1548 | fail_stack.frame = POP_FAILURE_INT (); \ | 1133 | fail_stack.frame = POP_FAILURE_INT (); \ |
| 1549 | DEBUG_PRINT (" Popping frame index: %zd\n", fail_stack.frame); \ | 1134 | DEBUG_PRINT (" Popping frame index: %zu\n", fail_stack.frame); \ |
| 1550 | \ | 1135 | \ |
| 1551 | assert (fail_stack.avail >= 0); \ | 1136 | eassert (fail_stack.avail >= 0); \ |
| 1552 | assert (fail_stack.frame <= fail_stack.avail); \ | 1137 | eassert (fail_stack.frame <= fail_stack.avail); \ |
| 1553 | \ | 1138 | \ |
| 1554 | DEBUG_STATEMENT (nfailure_points_popped++); \ | 1139 | DEBUG_STATEMENT (nfailure_points_popped++); \ |
| 1555 | } while (0) /* POP_FAILURE_POINT */ | 1140 | } while (false) /* POP_FAILURE_POINT */ |
| 1556 | 1141 | ||
| 1557 | 1142 | ||
| 1558 | 1143 | ||
| @@ -1562,12 +1147,8 @@ do { \ | |||
| 1562 | /* Subroutine declarations and macros for regex_compile. */ | 1147 | /* Subroutine declarations and macros for regex_compile. */ |
| 1563 | 1148 | ||
| 1564 | static reg_errcode_t regex_compile (re_char *pattern, size_t size, | 1149 | static reg_errcode_t regex_compile (re_char *pattern, size_t size, |
| 1565 | #ifdef emacs | ||
| 1566 | bool posix_backtracking, | 1150 | bool posix_backtracking, |
| 1567 | const char *whitespace_regexp, | 1151 | const char *whitespace_regexp, |
| 1568 | #else | ||
| 1569 | reg_syntax_t syntax, | ||
| 1570 | #endif | ||
| 1571 | struct re_pattern_buffer *bufp); | 1152 | struct re_pattern_buffer *bufp); |
| 1572 | static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); | 1153 | static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); |
| 1573 | static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); | 1154 | static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); |
| @@ -1575,10 +1156,8 @@ static void insert_op1 (re_opcode_t op, unsigned char *loc, | |||
| 1575 | int arg, unsigned char *end); | 1156 | int arg, unsigned char *end); |
| 1576 | static void insert_op2 (re_opcode_t op, unsigned char *loc, | 1157 | static void insert_op2 (re_opcode_t op, unsigned char *loc, |
| 1577 | int arg1, int arg2, unsigned char *end); | 1158 | int arg1, int arg2, unsigned char *end); |
| 1578 | static boolean at_begline_loc_p (re_char *pattern, re_char *p, | 1159 | static bool at_begline_loc_p (re_char *pattern, re_char *p); |
| 1579 | reg_syntax_t syntax); | 1160 | static bool at_endline_loc_p (re_char *p, re_char *pend); |
| 1580 | static boolean at_endline_loc_p (re_char *p, re_char *pend, | ||
| 1581 | reg_syntax_t syntax); | ||
| 1582 | static re_char *skip_one_char (re_char *p); | 1161 | static re_char *skip_one_char (re_char *p); |
| 1583 | static int analyze_first (re_char *p, re_char *pend, | 1162 | static int analyze_first (re_char *p, re_char *pend, |
| 1584 | char *fastmap, const int multibyte); | 1163 | char *fastmap, const int multibyte); |
| @@ -1591,35 +1170,28 @@ static int analyze_first (re_char *p, re_char *pend, | |||
| 1591 | if (p == pend) return REG_EEND; \ | 1170 | if (p == pend) return REG_EEND; \ |
| 1592 | c = RE_STRING_CHAR_AND_LENGTH (p, len, multibyte); \ | 1171 | c = RE_STRING_CHAR_AND_LENGTH (p, len, multibyte); \ |
| 1593 | p += len; \ | 1172 | p += len; \ |
| 1594 | } while (0) | 1173 | } while (false) |
| 1595 | |||
| 1596 | 1174 | ||
| 1597 | /* If `translate' is non-null, return translate[D], else just D. We | ||
| 1598 | cast the subscript to translate because some data is declared as | ||
| 1599 | `char *', to avoid warnings when a string constant is passed. But | ||
| 1600 | when we use a character as a subscript we must make it unsigned. */ | ||
| 1601 | #ifndef TRANSLATE | ||
| 1602 | # define TRANSLATE(d) \ | ||
| 1603 | (RE_TRANSLATE_P (translate) ? RE_TRANSLATE (translate, (d)) : (d)) | ||
| 1604 | #endif | ||
| 1605 | 1175 | ||
| 1176 | #define RE_TRANSLATE(TBL, C) char_table_translate (TBL, C) | ||
| 1177 | #define TRANSLATE(d) (!NILP (translate) ? RE_TRANSLATE (translate, d) : (d)) | ||
| 1606 | 1178 | ||
| 1607 | /* Macros for outputting the compiled pattern into `buffer'. */ | 1179 | /* Macros for outputting the compiled pattern into 'buffer'. */ |
| 1608 | 1180 | ||
| 1609 | /* If the buffer isn't allocated when it comes in, use this. */ | 1181 | /* If the buffer isn't allocated when it comes in, use this. */ |
| 1610 | #define INIT_BUF_SIZE 32 | 1182 | #define INIT_BUF_SIZE 32 |
| 1611 | 1183 | ||
| 1612 | /* Make sure we have at least N more bytes of space in buffer. */ | 1184 | /* Ensure at least N more bytes of space in buffer. */ |
| 1613 | #define GET_BUFFER_SPACE(n) \ | 1185 | #define GET_BUFFER_SPACE(n) \ |
| 1614 | while ((size_t) (b - bufp->buffer + (n)) > bufp->allocated) \ | 1186 | while ((size_t) (b - bufp->buffer + (n)) > bufp->allocated) \ |
| 1615 | EXTEND_BUFFER () | 1187 | EXTEND_BUFFER () |
| 1616 | 1188 | ||
| 1617 | /* Make sure we have one more byte of buffer space and then add C to it. */ | 1189 | /* Ensure one more byte of buffer space and then add C to it. */ |
| 1618 | #define BUF_PUSH(c) \ | 1190 | #define BUF_PUSH(c) \ |
| 1619 | do { \ | 1191 | do { \ |
| 1620 | GET_BUFFER_SPACE (1); \ | 1192 | GET_BUFFER_SPACE (1); \ |
| 1621 | *b++ = (unsigned char) (c); \ | 1193 | *b++ = (unsigned char) (c); \ |
| 1622 | } while (0) | 1194 | } while (false) |
| 1623 | 1195 | ||
| 1624 | 1196 | ||
| 1625 | /* Ensure we have two more bytes of buffer space and then append C1 and C2. */ | 1197 | /* Ensure we have two more bytes of buffer space and then append C1 and C2. */ |
| @@ -1628,10 +1200,10 @@ static int analyze_first (re_char *p, re_char *pend, | |||
| 1628 | GET_BUFFER_SPACE (2); \ | 1200 | GET_BUFFER_SPACE (2); \ |
| 1629 | *b++ = (unsigned char) (c1); \ | 1201 | *b++ = (unsigned char) (c1); \ |
| 1630 | *b++ = (unsigned char) (c2); \ | 1202 | *b++ = (unsigned char) (c2); \ |
| 1631 | } while (0) | 1203 | } while (false) |
| 1632 | 1204 | ||
| 1633 | 1205 | ||
| 1634 | /* Store a jump with opcode OP at LOC to location TO. We store a | 1206 | /* Store a jump with opcode OP at LOC to location TO. Store a |
| 1635 | relative address offset by the three bytes the jump itself occupies. */ | 1207 | relative address offset by the three bytes the jump itself occupies. */ |
| 1636 | #define STORE_JUMP(op, loc, to) \ | 1208 | #define STORE_JUMP(op, loc, to) \ |
| 1637 | store_op1 (op, loc, (to) - (loc) - 3) | 1209 | store_op1 (op, loc, (to) - (loc) - 3) |
| @@ -1640,11 +1212,11 @@ static int analyze_first (re_char *p, re_char *pend, | |||
| 1640 | #define STORE_JUMP2(op, loc, to, arg) \ | 1212 | #define STORE_JUMP2(op, loc, to, arg) \ |
| 1641 | store_op2 (op, loc, (to) - (loc) - 3, arg) | 1213 | store_op2 (op, loc, (to) - (loc) - 3, arg) |
| 1642 | 1214 | ||
| 1643 | /* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ | 1215 | /* Like 'STORE_JUMP', but for inserting. Assume B is the buffer end. */ |
| 1644 | #define INSERT_JUMP(op, loc, to) \ | 1216 | #define INSERT_JUMP(op, loc, to) \ |
| 1645 | insert_op1 (op, loc, (to) - (loc) - 3, b) | 1217 | insert_op1 (op, loc, (to) - (loc) - 3, b) |
| 1646 | 1218 | ||
| 1647 | /* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ | 1219 | /* Like 'STORE_JUMP2', but for inserting. Assume B is the buffer end. */ |
| 1648 | #define INSERT_JUMP2(op, loc, to, arg) \ | 1220 | #define INSERT_JUMP2(op, loc, to, arg) \ |
| 1649 | insert_op2 (op, loc, (to) - (loc) - 3, arg, b) | 1221 | insert_op2 (op, loc, (to) - (loc) - 3, arg, b) |
| 1650 | 1222 | ||
| @@ -1652,7 +1224,7 @@ static int analyze_first (re_char *p, re_char *pend, | |||
| 1652 | /* This is not an arbitrary limit: the arguments which represent offsets | 1224 | /* This is not an arbitrary limit: the arguments which represent offsets |
| 1653 | into the pattern are two bytes long. So if 2^15 bytes turns out to | 1225 | into the pattern are two bytes long. So if 2^15 bytes turns out to |
| 1654 | be too small, many things would have to change. */ | 1226 | be too small, many things would have to change. */ |
| 1655 | # define MAX_BUF_SIZE (1L << 15) | 1227 | # define MAX_BUF_SIZE (1 << 15) |
| 1656 | 1228 | ||
| 1657 | /* Extend the buffer by twice its current size via realloc and | 1229 | /* Extend the buffer by twice its current size via realloc and |
| 1658 | reset the pointers that pointed into the old block to point to the | 1230 | reset the pointers that pointed into the old block to point to the |
| @@ -1676,15 +1248,13 @@ static int analyze_first (re_char *p, re_char *pend, | |||
| 1676 | if (laststart_set) laststart_off = laststart - old_buffer; \ | 1248 | if (laststart_set) laststart_off = laststart - old_buffer; \ |
| 1677 | if (pending_exact_set) pending_exact_off = pending_exact - old_buffer; \ | 1249 | if (pending_exact_set) pending_exact_off = pending_exact - old_buffer; \ |
| 1678 | RETALLOC (bufp->buffer, bufp->allocated, unsigned char); \ | 1250 | RETALLOC (bufp->buffer, bufp->allocated, unsigned char); \ |
| 1679 | if (bufp->buffer == NULL) \ | ||
| 1680 | return REG_ESPACE; \ | ||
| 1681 | unsigned char *new_buffer = bufp->buffer; \ | 1251 | unsigned char *new_buffer = bufp->buffer; \ |
| 1682 | b = new_buffer + b_off; \ | 1252 | b = new_buffer + b_off; \ |
| 1683 | begalt = new_buffer + begalt_off; \ | 1253 | begalt = new_buffer + begalt_off; \ |
| 1684 | if (fixup_alt_jump_set) fixup_alt_jump = new_buffer + fixup_alt_jump_off; \ | 1254 | if (fixup_alt_jump_set) fixup_alt_jump = new_buffer + fixup_alt_jump_off; \ |
| 1685 | if (laststart_set) laststart = new_buffer + laststart_off; \ | 1255 | if (laststart_set) laststart = new_buffer + laststart_off; \ |
| 1686 | if (pending_exact_set) pending_exact = new_buffer + pending_exact_off; \ | 1256 | if (pending_exact_set) pending_exact = new_buffer + pending_exact_off; \ |
| 1687 | } while (0) | 1257 | } while (false) |
| 1688 | 1258 | ||
| 1689 | 1259 | ||
| 1690 | /* Since we have one byte reserved for the register number argument to | 1260 | /* Since we have one byte reserved for the register number argument to |
| @@ -1692,7 +1262,7 @@ static int analyze_first (re_char *p, re_char *pend, | |||
| 1692 | things about is what fits in that byte. */ | 1262 | things about is what fits in that byte. */ |
| 1693 | #define MAX_REGNUM 255 | 1263 | #define MAX_REGNUM 255 |
| 1694 | 1264 | ||
| 1695 | /* But patterns can have more than `MAX_REGNUM' registers. We just | 1265 | /* But patterns can have more than 'MAX_REGNUM' registers. Just |
| 1696 | ignore the excess. */ | 1266 | ignore the excess. */ |
| 1697 | typedef int regnum_t; | 1267 | typedef int regnum_t; |
| 1698 | 1268 | ||
| @@ -1701,7 +1271,6 @@ typedef int regnum_t; | |||
| 1701 | 1271 | ||
| 1702 | /* Since offsets can go either forwards or backwards, this type needs to | 1272 | /* Since offsets can go either forwards or backwards, this type needs to |
| 1703 | be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ | 1273 | be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ |
| 1704 | /* int may be not enough when sizeof(int) == 2. */ | ||
| 1705 | typedef long pattern_offset_t; | 1274 | typedef long pattern_offset_t; |
| 1706 | 1275 | ||
| 1707 | typedef struct | 1276 | typedef struct |
| @@ -1728,12 +1297,6 @@ typedef struct | |||
| 1728 | 1297 | ||
| 1729 | /* The next available element. */ | 1298 | /* The next available element. */ |
| 1730 | #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) | 1299 | #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) |
| 1731 | |||
| 1732 | /* Explicit quit checking is needed for Emacs, which uses polling to | ||
| 1733 | process input events. */ | ||
| 1734 | #ifndef emacs | ||
| 1735 | static void maybe_quit (void) {} | ||
| 1736 | #endif | ||
| 1737 | 1300 | ||
| 1738 | /* Structure to manage work area for range table. */ | 1301 | /* Structure to manage work area for range table. */ |
| 1739 | struct range_table_work_area | 1302 | struct range_table_work_area |
| @@ -1744,8 +1307,6 @@ struct range_table_work_area | |||
| 1744 | int bits; /* flag to record character classes */ | 1307 | int bits; /* flag to record character classes */ |
| 1745 | }; | 1308 | }; |
| 1746 | 1309 | ||
| 1747 | #ifdef emacs | ||
| 1748 | |||
| 1749 | /* Make sure that WORK_AREA can hold more N multibyte characters. | 1310 | /* Make sure that WORK_AREA can hold more N multibyte characters. |
| 1750 | This is used only in set_image_of_range and set_image_of_range_1. | 1311 | This is used only in set_image_of_range and set_image_of_range_1. |
| 1751 | It expects WORK_AREA to be a pointer. | 1312 | It expects WORK_AREA to be a pointer. |
| @@ -1759,7 +1320,7 @@ struct range_table_work_area | |||
| 1759 | if ((work_area).table == 0) \ | 1320 | if ((work_area).table == 0) \ |
| 1760 | return (REG_ESPACE); \ | 1321 | return (REG_ESPACE); \ |
| 1761 | } \ | 1322 | } \ |
| 1762 | } while (0) | 1323 | } while (false) |
| 1763 | 1324 | ||
| 1764 | #define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit) \ | 1325 | #define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit) \ |
| 1765 | (work_area).bits |= (bit) | 1326 | (work_area).bits |= (bit) |
| @@ -1770,18 +1331,17 @@ struct range_table_work_area | |||
| 1770 | EXTEND_RANGE_TABLE ((work_area), 2); \ | 1331 | EXTEND_RANGE_TABLE ((work_area), 2); \ |
| 1771 | (work_area).table[(work_area).used++] = (range_start); \ | 1332 | (work_area).table[(work_area).used++] = (range_start); \ |
| 1772 | (work_area).table[(work_area).used++] = (range_end); \ | 1333 | (work_area).table[(work_area).used++] = (range_end); \ |
| 1773 | } while (0) | 1334 | } while (false) |
| 1774 | |||
| 1775 | #endif /* emacs */ | ||
| 1776 | 1335 | ||
| 1777 | /* Free allocated memory for WORK_AREA. */ | 1336 | /* Free allocated memory for WORK_AREA. */ |
| 1778 | #define FREE_RANGE_TABLE_WORK_AREA(work_area) \ | 1337 | #define FREE_RANGE_TABLE_WORK_AREA(work_area) \ |
| 1779 | do { \ | 1338 | do { \ |
| 1780 | if ((work_area).table) \ | 1339 | if ((work_area).table) \ |
| 1781 | free ((work_area).table); \ | 1340 | xfree ((work_area).table); \ |
| 1782 | } while (0) | 1341 | } while (false) |
| 1783 | 1342 | ||
| 1784 | #define CLEAR_RANGE_TABLE_WORK_USED(work_area) ((work_area).used = 0, (work_area).bits = 0) | 1343 | #define CLEAR_RANGE_TABLE_WORK_USED(work_area) \ |
| 1344 | ((work_area).used = 0, (work_area).bits = 0) | ||
| 1785 | #define RANGE_TABLE_WORK_USED(work_area) ((work_area).used) | 1345 | #define RANGE_TABLE_WORK_USED(work_area) ((work_area).used) |
| 1786 | #define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits) | 1346 | #define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits) |
| 1787 | #define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i]) | 1347 | #define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i]) |
| @@ -1806,8 +1366,6 @@ struct range_table_work_area | |||
| 1806 | #define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH)) | 1366 | #define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH)) |
| 1807 | 1367 | ||
| 1808 | 1368 | ||
| 1809 | #ifdef emacs | ||
| 1810 | |||
| 1811 | /* Store characters in the range FROM to TO in the bitmap at B (for | 1369 | /* Store characters in the range FROM to TO in the bitmap at B (for |
| 1812 | ASCII and unibyte characters) and WORK_AREA (for multibyte | 1370 | ASCII and unibyte characters) and WORK_AREA (for multibyte |
| 1813 | characters) while translating them and paying attention to the | 1371 | characters) while translating them and paying attention to the |
| @@ -1822,7 +1380,7 @@ struct range_table_work_area | |||
| 1822 | #define SETUP_ASCII_RANGE(work_area, FROM, TO) \ | 1380 | #define SETUP_ASCII_RANGE(work_area, FROM, TO) \ |
| 1823 | do { \ | 1381 | do { \ |
| 1824 | int C0, C1; \ | 1382 | int C0, C1; \ |
| 1825 | \ | 1383 | \ |
| 1826 | for (C0 = (FROM); C0 <= (TO); C0++) \ | 1384 | for (C0 = (FROM); C0 <= (TO); C0++) \ |
| 1827 | { \ | 1385 | { \ |
| 1828 | C1 = TRANSLATE (C0); \ | 1386 | C1 = TRANSLATE (C0); \ |
| @@ -1834,7 +1392,7 @@ struct range_table_work_area | |||
| 1834 | } \ | 1392 | } \ |
| 1835 | SET_LIST_BIT (C1); \ | 1393 | SET_LIST_BIT (C1); \ |
| 1836 | } \ | 1394 | } \ |
| 1837 | } while (0) | 1395 | } while (false) |
| 1838 | 1396 | ||
| 1839 | 1397 | ||
| 1840 | /* Both FROM and TO are unibyte characters (0x80..0xFF). */ | 1398 | /* Both FROM and TO are unibyte characters (0x80..0xFF). */ |
| @@ -1843,7 +1401,7 @@ struct range_table_work_area | |||
| 1843 | do { \ | 1401 | do { \ |
| 1844 | int C0, C1, C2, I; \ | 1402 | int C0, C1, C2, I; \ |
| 1845 | int USED = RANGE_TABLE_WORK_USED (work_area); \ | 1403 | int USED = RANGE_TABLE_WORK_USED (work_area); \ |
| 1846 | \ | 1404 | \ |
| 1847 | for (C0 = (FROM); C0 <= (TO); C0++) \ | 1405 | for (C0 = (FROM); C0 <= (TO); C0++) \ |
| 1848 | { \ | 1406 | { \ |
| 1849 | C1 = RE_CHAR_TO_MULTIBYTE (C0); \ | 1407 | C1 = RE_CHAR_TO_MULTIBYTE (C0); \ |
| @@ -1874,7 +1432,7 @@ struct range_table_work_area | |||
| 1874 | SET_RANGE_TABLE_WORK_AREA ((work_area), C2, C2); \ | 1432 | SET_RANGE_TABLE_WORK_AREA ((work_area), C2, C2); \ |
| 1875 | } \ | 1433 | } \ |
| 1876 | } \ | 1434 | } \ |
| 1877 | } while (0) | 1435 | } while (false) |
| 1878 | 1436 | ||
| 1879 | 1437 | ||
| 1880 | /* Both FROM and TO are multibyte characters. */ | 1438 | /* Both FROM and TO are multibyte characters. */ |
| @@ -1882,7 +1440,7 @@ struct range_table_work_area | |||
| 1882 | #define SETUP_MULTIBYTE_RANGE(work_area, FROM, TO) \ | 1440 | #define SETUP_MULTIBYTE_RANGE(work_area, FROM, TO) \ |
| 1883 | do { \ | 1441 | do { \ |
| 1884 | int C0, C1, C2, I, USED = RANGE_TABLE_WORK_USED (work_area); \ | 1442 | int C0, C1, C2, I, USED = RANGE_TABLE_WORK_USED (work_area); \ |
| 1885 | \ | 1443 | \ |
| 1886 | SET_RANGE_TABLE_WORK_AREA ((work_area), (FROM), (TO)); \ | 1444 | SET_RANGE_TABLE_WORK_AREA ((work_area), (FROM), (TO)); \ |
| 1887 | for (C0 = (FROM); C0 <= (TO); C0++) \ | 1445 | for (C0 = (FROM); C0 <= (TO); C0++) \ |
| 1888 | { \ | 1446 | { \ |
| @@ -1896,7 +1454,7 @@ struct range_table_work_area | |||
| 1896 | { \ | 1454 | { \ |
| 1897 | int from = RANGE_TABLE_WORK_ELT (work_area, I); \ | 1455 | int from = RANGE_TABLE_WORK_ELT (work_area, I); \ |
| 1898 | int to = RANGE_TABLE_WORK_ELT (work_area, I + 1); \ | 1456 | int to = RANGE_TABLE_WORK_ELT (work_area, I + 1); \ |
| 1899 | \ | 1457 | \ |
| 1900 | if (C1 >= from - 1 && C1 <= to + 1) \ | 1458 | if (C1 >= from - 1 && C1 <= to + 1) \ |
| 1901 | { \ | 1459 | { \ |
| 1902 | if (C1 == from - 1) \ | 1460 | if (C1 == from - 1) \ |
| @@ -1909,9 +1467,7 @@ struct range_table_work_area | |||
| 1909 | if (I < USED) \ | 1467 | if (I < USED) \ |
| 1910 | SET_RANGE_TABLE_WORK_AREA ((work_area), C1, C1); \ | 1468 | SET_RANGE_TABLE_WORK_AREA ((work_area), C1, C1); \ |
| 1911 | } \ | 1469 | } \ |
| 1912 | } while (0) | 1470 | } while (false) |
| 1913 | |||
| 1914 | #endif /* emacs */ | ||
| 1915 | 1471 | ||
| 1916 | /* Get the next unsigned number in the uncompiled pattern. */ | 1472 | /* Get the next unsigned number in the uncompiled pattern. */ |
| 1917 | #define GET_INTERVAL_COUNT(num) \ | 1473 | #define GET_INTERVAL_COUNT(num) \ |
| @@ -1933,10 +1489,8 @@ struct range_table_work_area | |||
| 1933 | PATFETCH (c); \ | 1489 | PATFETCH (c); \ |
| 1934 | } \ | 1490 | } \ |
| 1935 | } \ | 1491 | } \ |
| 1936 | } while (0) | 1492 | } while (false) |
| 1937 | 1493 | ||
| 1938 | #if ! WIDE_CHAR_SUPPORT | ||
| 1939 | |||
| 1940 | /* Parse a character class, i.e. string such as "[:name:]". *strp | 1494 | /* Parse a character class, i.e. string such as "[:name:]". *strp |
| 1941 | points to the string to be parsed and limit is length, in bytes, of | 1495 | points to the string to be parsed and limit is length, in bytes, of |
| 1942 | that string. | 1496 | that string. |
| @@ -2030,7 +1584,7 @@ re_wctype_parse (const unsigned char **strp, unsigned limit) | |||
| 2030 | } | 1584 | } |
| 2031 | 1585 | ||
| 2032 | /* True if CH is in the char class CC. */ | 1586 | /* True if CH is in the char class CC. */ |
| 2033 | boolean | 1587 | bool |
| 2034 | re_iswctype (int ch, re_wctype_t cc) | 1588 | re_iswctype (int ch, re_wctype_t cc) |
| 2035 | { | 1589 | { |
| 2036 | switch (cc) | 1590 | switch (cc) |
| @@ -2083,7 +1637,6 @@ re_wctype_to_bit (re_wctype_t cc) | |||
| 2083 | abort (); | 1637 | abort (); |
| 2084 | } | 1638 | } |
| 2085 | } | 1639 | } |
| 2086 | #endif | ||
| 2087 | 1640 | ||
| 2088 | /* Filling in the work area of a range. */ | 1641 | /* Filling in the work area of a range. */ |
| 2089 | 1642 | ||
| @@ -2093,357 +1646,75 @@ static void | |||
| 2093 | extend_range_table_work_area (struct range_table_work_area *work_area) | 1646 | extend_range_table_work_area (struct range_table_work_area *work_area) |
| 2094 | { | 1647 | { |
| 2095 | work_area->allocated += 16 * sizeof (int); | 1648 | work_area->allocated += 16 * sizeof (int); |
| 2096 | work_area->table = realloc (work_area->table, work_area->allocated); | 1649 | work_area->table = xrealloc (work_area->table, work_area->allocated); |
| 2097 | } | 1650 | } |
| 2098 | |||
| 2099 | #if 0 | ||
| 2100 | #ifdef emacs | ||
| 2101 | |||
| 2102 | /* Carefully find the ranges of codes that are equivalent | ||
| 2103 | under case conversion to the range start..end when passed through | ||
| 2104 | TRANSLATE. Handle the case where non-letters can come in between | ||
| 2105 | two upper-case letters (which happens in Latin-1). | ||
| 2106 | Also handle the case of groups of more than 2 case-equivalent chars. | ||
| 2107 | |||
| 2108 | The basic method is to look at consecutive characters and see | ||
| 2109 | if they can form a run that can be handled as one. | ||
| 2110 | |||
| 2111 | Returns -1 if successful, REG_ESPACE if ran out of space. */ | ||
| 2112 | |||
| 2113 | static int | ||
| 2114 | set_image_of_range_1 (struct range_table_work_area *work_area, | ||
| 2115 | re_wchar_t start, re_wchar_t end, | ||
| 2116 | RE_TRANSLATE_TYPE translate) | ||
| 2117 | { | ||
| 2118 | /* `one_case' indicates a character, or a run of characters, | ||
| 2119 | each of which is an isolate (no case-equivalents). | ||
| 2120 | This includes all ASCII non-letters. | ||
| 2121 | |||
| 2122 | `two_case' indicates a character, or a run of characters, | ||
| 2123 | each of which has two case-equivalent forms. | ||
| 2124 | This includes all ASCII letters. | ||
| 2125 | |||
| 2126 | `strange' indicates a character that has more than one | ||
| 2127 | case-equivalent. */ | ||
| 2128 | |||
| 2129 | enum case_type {one_case, two_case, strange}; | ||
| 2130 | |||
| 2131 | /* Describe the run that is in progress, | ||
| 2132 | which the next character can try to extend. | ||
| 2133 | If run_type is strange, that means there really is no run. | ||
| 2134 | If run_type is one_case, then run_start...run_end is the run. | ||
| 2135 | If run_type is two_case, then the run is run_start...run_end, | ||
| 2136 | and the case-equivalents end at run_eqv_end. */ | ||
| 2137 | |||
| 2138 | enum case_type run_type = strange; | ||
| 2139 | int run_start, run_end, run_eqv_end; | ||
| 2140 | |||
| 2141 | Lisp_Object eqv_table; | ||
| 2142 | |||
| 2143 | if (!RE_TRANSLATE_P (translate)) | ||
| 2144 | { | ||
| 2145 | EXTEND_RANGE_TABLE (work_area, 2); | ||
| 2146 | work_area->table[work_area->used++] = (start); | ||
| 2147 | work_area->table[work_area->used++] = (end); | ||
| 2148 | return -1; | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | eqv_table = XCHAR_TABLE (translate)->extras[2]; | ||
| 2152 | |||
| 2153 | for (; start <= end; start++) | ||
| 2154 | { | ||
| 2155 | enum case_type this_type; | ||
| 2156 | int eqv = RE_TRANSLATE (eqv_table, start); | ||
| 2157 | int minchar, maxchar; | ||
| 2158 | |||
| 2159 | /* Classify this character */ | ||
| 2160 | if (eqv == start) | ||
| 2161 | this_type = one_case; | ||
| 2162 | else if (RE_TRANSLATE (eqv_table, eqv) == start) | ||
| 2163 | this_type = two_case; | ||
| 2164 | else | ||
| 2165 | this_type = strange; | ||
| 2166 | |||
| 2167 | if (start < eqv) | ||
| 2168 | minchar = start, maxchar = eqv; | ||
| 2169 | else | ||
| 2170 | minchar = eqv, maxchar = start; | ||
| 2171 | |||
| 2172 | /* Can this character extend the run in progress? */ | ||
| 2173 | if (this_type == strange || this_type != run_type | ||
| 2174 | || !(minchar == run_end + 1 | ||
| 2175 | && (run_type == two_case | ||
| 2176 | ? maxchar == run_eqv_end + 1 : 1))) | ||
| 2177 | { | ||
| 2178 | /* No, end the run. | ||
| 2179 | Record each of its equivalent ranges. */ | ||
| 2180 | if (run_type == one_case) | ||
| 2181 | { | ||
| 2182 | EXTEND_RANGE_TABLE (work_area, 2); | ||
| 2183 | work_area->table[work_area->used++] = run_start; | ||
| 2184 | work_area->table[work_area->used++] = run_end; | ||
| 2185 | } | ||
| 2186 | else if (run_type == two_case) | ||
| 2187 | { | ||
| 2188 | EXTEND_RANGE_TABLE (work_area, 4); | ||
| 2189 | work_area->table[work_area->used++] = run_start; | ||
| 2190 | work_area->table[work_area->used++] = run_end; | ||
| 2191 | work_area->table[work_area->used++] | ||
| 2192 | = RE_TRANSLATE (eqv_table, run_start); | ||
| 2193 | work_area->table[work_area->used++] | ||
| 2194 | = RE_TRANSLATE (eqv_table, run_end); | ||
| 2195 | } | ||
| 2196 | run_type = strange; | ||
| 2197 | } | ||
| 2198 | |||
| 2199 | if (this_type == strange) | ||
| 2200 | { | ||
| 2201 | /* For a strange character, add each of its equivalents, one | ||
| 2202 | by one. Don't start a range. */ | ||
| 2203 | do | ||
| 2204 | { | ||
| 2205 | EXTEND_RANGE_TABLE (work_area, 2); | ||
| 2206 | work_area->table[work_area->used++] = eqv; | ||
| 2207 | work_area->table[work_area->used++] = eqv; | ||
| 2208 | eqv = RE_TRANSLATE (eqv_table, eqv); | ||
| 2209 | } | ||
| 2210 | while (eqv != start); | ||
| 2211 | } | ||
| 2212 | |||
| 2213 | /* Add this char to the run, or start a new run. */ | ||
| 2214 | else if (run_type == strange) | ||
| 2215 | { | ||
| 2216 | /* Initialize a new range. */ | ||
| 2217 | run_type = this_type; | ||
| 2218 | run_start = start; | ||
| 2219 | run_end = start; | ||
| 2220 | run_eqv_end = RE_TRANSLATE (eqv_table, run_end); | ||
| 2221 | } | ||
| 2222 | else | ||
| 2223 | { | ||
| 2224 | /* Extend a running range. */ | ||
| 2225 | run_end = minchar; | ||
| 2226 | run_eqv_end = RE_TRANSLATE (eqv_table, run_end); | ||
| 2227 | } | ||
| 2228 | } | ||
| 2229 | |||
| 2230 | /* If a run is still in progress at the end, finish it now | ||
| 2231 | by recording its equivalent ranges. */ | ||
| 2232 | if (run_type == one_case) | ||
| 2233 | { | ||
| 2234 | EXTEND_RANGE_TABLE (work_area, 2); | ||
| 2235 | work_area->table[work_area->used++] = run_start; | ||
| 2236 | work_area->table[work_area->used++] = run_end; | ||
| 2237 | } | ||
| 2238 | else if (run_type == two_case) | ||
| 2239 | { | ||
| 2240 | EXTEND_RANGE_TABLE (work_area, 4); | ||
| 2241 | work_area->table[work_area->used++] = run_start; | ||
| 2242 | work_area->table[work_area->used++] = run_end; | ||
| 2243 | work_area->table[work_area->used++] | ||
| 2244 | = RE_TRANSLATE (eqv_table, run_start); | ||
| 2245 | work_area->table[work_area->used++] | ||
| 2246 | = RE_TRANSLATE (eqv_table, run_end); | ||
| 2247 | } | ||
| 2248 | |||
| 2249 | return -1; | ||
| 2250 | } | ||
| 2251 | |||
| 2252 | #endif /* emacs */ | ||
| 2253 | |||
| 2254 | /* Record the image of the range start..end when passed through | ||
| 2255 | TRANSLATE. This is not necessarily TRANSLATE(start)..TRANSLATE(end) | ||
| 2256 | and is not even necessarily contiguous. | ||
| 2257 | Normally we approximate it with the smallest contiguous range that contains | ||
| 2258 | all the chars we need. However, for Latin-1 we go to extra effort | ||
| 2259 | to do a better job. | ||
| 2260 | |||
| 2261 | This function is not called for ASCII ranges. | ||
| 2262 | |||
| 2263 | Returns -1 if successful, REG_ESPACE if ran out of space. */ | ||
| 2264 | |||
| 2265 | static int | ||
| 2266 | set_image_of_range (struct range_table_work_area *work_area, | ||
| 2267 | re_wchar_t start, re_wchar_t end, | ||
| 2268 | RE_TRANSLATE_TYPE translate) | ||
| 2269 | { | ||
| 2270 | re_wchar_t cmin, cmax; | ||
| 2271 | |||
| 2272 | #ifdef emacs | ||
| 2273 | /* For Latin-1 ranges, use set_image_of_range_1 | ||
| 2274 | to get proper handling of ranges that include letters and nonletters. | ||
| 2275 | For a range that includes the whole of Latin-1, this is not necessary. | ||
| 2276 | For other character sets, we don't bother to get this right. */ | ||
| 2277 | if (RE_TRANSLATE_P (translate) && start < 04400 | ||
| 2278 | && !(start < 04200 && end >= 04377)) | ||
| 2279 | { | ||
| 2280 | int newend; | ||
| 2281 | int tem; | ||
| 2282 | newend = end; | ||
| 2283 | if (newend > 04377) | ||
| 2284 | newend = 04377; | ||
| 2285 | tem = set_image_of_range_1 (work_area, start, newend, translate); | ||
| 2286 | if (tem > 0) | ||
| 2287 | return tem; | ||
| 2288 | |||
| 2289 | start = 04400; | ||
| 2290 | if (end < 04400) | ||
| 2291 | return -1; | ||
| 2292 | } | ||
| 2293 | #endif | ||
| 2294 | |||
| 2295 | EXTEND_RANGE_TABLE (work_area, 2); | ||
| 2296 | work_area->table[work_area->used++] = (start); | ||
| 2297 | work_area->table[work_area->used++] = (end); | ||
| 2298 | |||
| 2299 | cmin = -1, cmax = -1; | ||
| 2300 | |||
| 2301 | if (RE_TRANSLATE_P (translate)) | ||
| 2302 | { | ||
| 2303 | int ch; | ||
| 2304 | |||
| 2305 | for (ch = start; ch <= end; ch++) | ||
| 2306 | { | ||
| 2307 | re_wchar_t c = TRANSLATE (ch); | ||
| 2308 | if (! (start <= c && c <= end)) | ||
| 2309 | { | ||
| 2310 | if (cmin == -1) | ||
| 2311 | cmin = c, cmax = c; | ||
| 2312 | else | ||
| 2313 | { | ||
| 2314 | cmin = min (cmin, c); | ||
| 2315 | cmax = max (cmax, c); | ||
| 2316 | } | ||
| 2317 | } | ||
| 2318 | } | ||
| 2319 | |||
| 2320 | if (cmin != -1) | ||
| 2321 | { | ||
| 2322 | EXTEND_RANGE_TABLE (work_area, 2); | ||
| 2323 | work_area->table[work_area->used++] = (cmin); | ||
| 2324 | work_area->table[work_area->used++] = (cmax); | ||
| 2325 | } | ||
| 2326 | } | ||
| 2327 | |||
| 2328 | return -1; | ||
| 2329 | } | ||
| 2330 | #endif /* 0 */ | ||
| 2331 | |||
| 2332 | #ifndef MATCH_MAY_ALLOCATE | ||
| 2333 | |||
| 2334 | /* If we cannot allocate large objects within re_match_2_internal, | ||
| 2335 | we make the fail stack and register vectors global. | ||
| 2336 | The fail stack, we grow to the maximum size when a regexp | ||
| 2337 | is compiled. | ||
| 2338 | The register vectors, we adjust in size each time we | ||
| 2339 | compile a regexp, according to the number of registers it needs. */ | ||
| 2340 | |||
| 2341 | static fail_stack_type fail_stack; | ||
| 2342 | |||
| 2343 | /* Size with which the following vectors are currently allocated. | ||
| 2344 | That is so we can make them bigger as needed, | ||
| 2345 | but never make them smaller. */ | ||
| 2346 | static int regs_allocated_size; | ||
| 2347 | |||
| 2348 | static re_char ** regstart, ** regend; | ||
| 2349 | static re_char **best_regstart, **best_regend; | ||
| 2350 | |||
| 2351 | /* Make the register vectors big enough for NUM_REGS registers, | ||
| 2352 | but don't make them smaller. */ | ||
| 2353 | |||
| 2354 | static | ||
| 2355 | regex_grow_registers (int num_regs) | ||
| 2356 | { | ||
| 2357 | if (num_regs > regs_allocated_size) | ||
| 2358 | { | ||
| 2359 | RETALLOC_IF (regstart, num_regs, re_char *); | ||
| 2360 | RETALLOC_IF (regend, num_regs, re_char *); | ||
| 2361 | RETALLOC_IF (best_regstart, num_regs, re_char *); | ||
| 2362 | RETALLOC_IF (best_regend, num_regs, re_char *); | ||
| 2363 | |||
| 2364 | regs_allocated_size = num_regs; | ||
| 2365 | } | ||
| 2366 | } | ||
| 2367 | |||
| 2368 | #endif /* not MATCH_MAY_ALLOCATE */ | ||
| 2369 | 1651 | ||
| 2370 | static boolean group_in_compile_stack (compile_stack_type compile_stack, | 1652 | /* regex_compile and helpers. */ |
| 2371 | regnum_t regnum); | ||
| 2372 | |||
| 2373 | /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. | ||
| 2374 | Returns one of error codes defined in `regex.h', or zero for success. | ||
| 2375 | |||
| 2376 | If WHITESPACE_REGEXP is given (only #ifdef emacs), it is used instead of | ||
| 2377 | a space character in PATTERN. | ||
| 2378 | |||
| 2379 | Assumes the `allocated' (and perhaps `buffer') and `translate' | ||
| 2380 | fields are set in BUFP on entry. | ||
| 2381 | 1653 | ||
| 2382 | If it succeeds, results are put in BUFP (if it returns an error, the | 1654 | static bool group_in_compile_stack (compile_stack_type, regnum_t); |
| 2383 | contents of BUFP are undefined): | ||
| 2384 | `buffer' is the compiled pattern; | ||
| 2385 | `syntax' is set to SYNTAX; | ||
| 2386 | `used' is set to the length of the compiled pattern; | ||
| 2387 | `fastmap_accurate' is zero; | ||
| 2388 | `re_nsub' is the number of subexpressions in PATTERN; | ||
| 2389 | `not_bol' and `not_eol' are zero; | ||
| 2390 | 1655 | ||
| 2391 | The `fastmap' field is neither examined nor set. */ | 1656 | /* Insert the 'jump' from the end of last alternative to "here". |
| 2392 | |||
| 2393 | /* Insert the `jump' from the end of last alternative to "here". | ||
| 2394 | The space for the jump has already been allocated. */ | 1657 | The space for the jump has already been allocated. */ |
| 2395 | #define FIXUP_ALT_JUMP() \ | 1658 | #define FIXUP_ALT_JUMP() \ |
| 2396 | do { \ | 1659 | do { \ |
| 2397 | if (fixup_alt_jump) \ | 1660 | if (fixup_alt_jump) \ |
| 2398 | STORE_JUMP (jump, fixup_alt_jump, b); \ | 1661 | STORE_JUMP (jump, fixup_alt_jump, b); \ |
| 2399 | } while (0) | 1662 | } while (false) |
| 2400 | 1663 | ||
| 2401 | 1664 | ||
| 2402 | /* Return, freeing storage we allocated. */ | 1665 | /* Return, freeing storage we allocated. */ |
| 2403 | #define FREE_STACK_RETURN(value) \ | 1666 | #define FREE_STACK_RETURN(value) \ |
| 2404 | do { \ | 1667 | do { \ |
| 2405 | FREE_RANGE_TABLE_WORK_AREA (range_table_work); \ | 1668 | FREE_RANGE_TABLE_WORK_AREA (range_table_work); \ |
| 2406 | free (compile_stack.stack); \ | 1669 | xfree (compile_stack.stack); \ |
| 2407 | return value; \ | 1670 | return value; \ |
| 2408 | } while (0) | 1671 | } while (false) |
| 1672 | |||
| 1673 | /* Compile PATTERN (of length SIZE) according to SYNTAX. | ||
| 1674 | Return a nonzero error code on failure, or zero for success. | ||
| 1675 | |||
| 1676 | If WHITESPACE_REGEXP is given, use it instead of a space | ||
| 1677 | character in PATTERN. | ||
| 1678 | |||
| 1679 | Assume the 'allocated' (and perhaps 'buffer') and 'translate' | ||
| 1680 | fields are set in BUFP on entry. | ||
| 1681 | |||
| 1682 | If successful, put results in *BUFP (otherwise the | ||
| 1683 | contents of *BUFP are undefined): | ||
| 1684 | 'buffer' is the compiled pattern; | ||
| 1685 | 'syntax' is set to SYNTAX; | ||
| 1686 | 'used' is set to the length of the compiled pattern; | ||
| 1687 | 'fastmap_accurate' is zero; | ||
| 1688 | 're_nsub' is the number of subexpressions in PATTERN; | ||
| 1689 | |||
| 1690 | The 'fastmap' field is neither examined nor set. */ | ||
| 2409 | 1691 | ||
| 2410 | static reg_errcode_t | 1692 | static reg_errcode_t |
| 2411 | regex_compile (re_char *pattern, size_t size, | 1693 | regex_compile (re_char *pattern, size_t size, |
| 2412 | #ifdef emacs | ||
| 2413 | # define syntax RE_SYNTAX_EMACS | ||
| 2414 | bool posix_backtracking, | 1694 | bool posix_backtracking, |
| 2415 | const char *whitespace_regexp, | 1695 | const char *whitespace_regexp, |
| 2416 | #else | ||
| 2417 | reg_syntax_t syntax, | ||
| 2418 | # define posix_backtracking (!(syntax & RE_NO_POSIX_BACKTRACKING)) | ||
| 2419 | #endif | ||
| 2420 | struct re_pattern_buffer *bufp) | 1696 | struct re_pattern_buffer *bufp) |
| 2421 | { | 1697 | { |
| 2422 | /* We fetch characters from PATTERN here. */ | 1698 | /* Fetch characters from PATTERN here. */ |
| 2423 | register re_wchar_t c, c1; | 1699 | int c, c1; |
| 2424 | 1700 | ||
| 2425 | /* Points to the end of the buffer, where we should append. */ | 1701 | /* Points to the end of the buffer, where we should append. */ |
| 2426 | register unsigned char *b; | 1702 | unsigned char *b; |
| 2427 | 1703 | ||
| 2428 | /* Keeps track of unclosed groups. */ | 1704 | /* Keeps track of unclosed groups. */ |
| 2429 | compile_stack_type compile_stack; | 1705 | compile_stack_type compile_stack; |
| 2430 | 1706 | ||
| 2431 | /* Points to the current (ending) position in the pattern. */ | 1707 | /* Points to the current (ending) position in the pattern. */ |
| 2432 | #ifdef AIX | ||
| 2433 | /* `const' makes AIX compiler fail. */ | ||
| 2434 | unsigned char *p = pattern; | ||
| 2435 | #else | ||
| 2436 | re_char *p = pattern; | 1708 | re_char *p = pattern; |
| 2437 | #endif | ||
| 2438 | re_char *pend = pattern + size; | 1709 | re_char *pend = pattern + size; |
| 2439 | 1710 | ||
| 2440 | /* How to translate the characters in the pattern. */ | 1711 | /* How to translate the characters in the pattern. */ |
| 2441 | RE_TRANSLATE_TYPE translate = bufp->translate; | 1712 | Lisp_Object translate = bufp->translate; |
| 2442 | 1713 | ||
| 2443 | /* Address of the count-byte of the most recently inserted `exactn' | 1714 | /* Address of the count-byte of the most recently inserted 'exactn' |
| 2444 | command. This makes it possible to tell if a new exact-match | 1715 | command. This makes it possible to tell if a new exact-match |
| 2445 | character can be added to that command or if the character requires | 1716 | character can be added to that command or if the character requires |
| 2446 | a new `exactn' command. */ | 1717 | a new 'exactn' command. */ |
| 2447 | unsigned char *pending_exact = 0; | 1718 | unsigned char *pending_exact = 0; |
| 2448 | 1719 | ||
| 2449 | /* Address of start of the most recently finished expression. | 1720 | /* Address of start of the most recently finished expression. |
| @@ -2459,7 +1730,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2459 | re_char *beg_interval; | 1730 | re_char *beg_interval; |
| 2460 | 1731 | ||
| 2461 | /* Address of the place where a forward jump should go to the end of | 1732 | /* Address of the place where a forward jump should go to the end of |
| 2462 | the containing expression. Each alternative of an `or' -- except the | 1733 | the containing expression. Each alternative of an 'or' -- except the |
| 2463 | last -- ends with a forward jump of this sort. */ | 1734 | last -- ends with a forward jump of this sort. */ |
| 2464 | unsigned char *fixup_alt_jump = 0; | 1735 | unsigned char *fixup_alt_jump = 0; |
| 2465 | 1736 | ||
| @@ -2467,9 +1738,8 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2467 | struct range_table_work_area range_table_work; | 1738 | struct range_table_work_area range_table_work; |
| 2468 | 1739 | ||
| 2469 | /* If the object matched can contain multibyte characters. */ | 1740 | /* If the object matched can contain multibyte characters. */ |
| 2470 | const boolean multibyte = RE_MULTIBYTE_P (bufp); | 1741 | bool multibyte = RE_MULTIBYTE_P (bufp); |
| 2471 | 1742 | ||
| 2472 | #ifdef emacs | ||
| 2473 | /* Nonzero if we have pushed down into a subpattern. */ | 1743 | /* Nonzero if we have pushed down into a subpattern. */ |
| 2474 | int in_subpattern = 0; | 1744 | int in_subpattern = 0; |
| 2475 | 1745 | ||
| @@ -2478,26 +1748,22 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2478 | re_char *main_p; | 1748 | re_char *main_p; |
| 2479 | re_char *main_pattern; | 1749 | re_char *main_pattern; |
| 2480 | re_char *main_pend; | 1750 | re_char *main_pend; |
| 2481 | #endif | ||
| 2482 | 1751 | ||
| 2483 | #ifdef DEBUG | 1752 | #ifdef REGEX_EMACS_DEBUG |
| 2484 | debug++; | 1753 | regex_emacs_debug++; |
| 2485 | DEBUG_PRINT ("\nCompiling pattern: "); | 1754 | DEBUG_PRINT ("\nCompiling pattern: "); |
| 2486 | if (debug > 0) | 1755 | if (regex_emacs_debug > 0) |
| 2487 | { | 1756 | { |
| 2488 | unsigned debug_count; | 1757 | size_t debug_count; |
| 2489 | 1758 | ||
| 2490 | for (debug_count = 0; debug_count < size; debug_count++) | 1759 | for (debug_count = 0; debug_count < size; debug_count++) |
| 2491 | putchar (pattern[debug_count]); | 1760 | putchar (pattern[debug_count]); |
| 2492 | putchar ('\n'); | 1761 | putchar ('\n'); |
| 2493 | } | 1762 | } |
| 2494 | #endif /* DEBUG */ | 1763 | #endif |
| 2495 | 1764 | ||
| 2496 | /* Initialize the compile stack. */ | 1765 | /* Initialize the compile stack. */ |
| 2497 | compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); | 1766 | compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); |
| 2498 | if (compile_stack.stack == NULL) | ||
| 2499 | return REG_ESPACE; | ||
| 2500 | |||
| 2501 | compile_stack.size = INIT_COMPILE_STACK_SIZE; | 1767 | compile_stack.size = INIT_COMPILE_STACK_SIZE; |
| 2502 | compile_stack.avail = 0; | 1768 | compile_stack.avail = 0; |
| 2503 | 1769 | ||
| @@ -2505,26 +1771,16 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2505 | range_table_work.allocated = 0; | 1771 | range_table_work.allocated = 0; |
| 2506 | 1772 | ||
| 2507 | /* Initialize the pattern buffer. */ | 1773 | /* Initialize the pattern buffer. */ |
| 2508 | #ifndef emacs | ||
| 2509 | bufp->syntax = syntax; | ||
| 2510 | #endif | ||
| 2511 | bufp->fastmap_accurate = 0; | 1774 | bufp->fastmap_accurate = 0; |
| 2512 | bufp->not_bol = bufp->not_eol = 0; | ||
| 2513 | bufp->used_syntax = 0; | 1775 | bufp->used_syntax = 0; |
| 2514 | 1776 | ||
| 2515 | /* Set `used' to zero, so that if we return an error, the pattern | 1777 | /* Set 'used' to zero, so that if we return an error, the pattern |
| 2516 | printer (for debugging) will think there's no pattern. We reset it | 1778 | printer (for debugging) will think there's no pattern. We reset it |
| 2517 | at the end. */ | 1779 | at the end. */ |
| 2518 | bufp->used = 0; | 1780 | bufp->used = 0; |
| 2519 | 1781 | ||
| 2520 | /* Always count groups, whether or not bufp->no_sub is set. */ | ||
| 2521 | bufp->re_nsub = 0; | 1782 | bufp->re_nsub = 0; |
| 2522 | 1783 | ||
| 2523 | #if !defined emacs && !defined SYNTAX_TABLE | ||
| 2524 | /* Initialize the syntax table. */ | ||
| 2525 | init_syntax_once (); | ||
| 2526 | #endif | ||
| 2527 | |||
| 2528 | if (bufp->allocated == 0) | 1784 | if (bufp->allocated == 0) |
| 2529 | { | 1785 | { |
| 2530 | if (bufp->buffer) | 1786 | if (bufp->buffer) |
| @@ -2537,8 +1793,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2537 | { /* Caller did not allocate a buffer. Do it for them. */ | 1793 | { /* Caller did not allocate a buffer. Do it for them. */ |
| 2538 | bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); | 1794 | bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); |
| 2539 | } | 1795 | } |
| 2540 | if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE); | ||
| 2541 | |||
| 2542 | bufp->allocated = INIT_BUF_SIZE; | 1796 | bufp->allocated = INIT_BUF_SIZE; |
| 2543 | } | 1797 | } |
| 2544 | 1798 | ||
| @@ -2549,7 +1803,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2549 | { | 1803 | { |
| 2550 | if (p == pend) | 1804 | if (p == pend) |
| 2551 | { | 1805 | { |
| 2552 | #ifdef emacs | ||
| 2553 | /* If this is the end of an included regexp, | 1806 | /* If this is the end of an included regexp, |
| 2554 | pop back to the main regexp and try again. */ | 1807 | pop back to the main regexp and try again. */ |
| 2555 | if (in_subpattern) | 1808 | if (in_subpattern) |
| @@ -2560,7 +1813,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2560 | pend = main_pend; | 1813 | pend = main_pend; |
| 2561 | continue; | 1814 | continue; |
| 2562 | } | 1815 | } |
| 2563 | #endif | ||
| 2564 | /* If this is the end of the main regexp, we are done. */ | 1816 | /* If this is the end of the main regexp, we are done. */ |
| 2565 | break; | 1817 | break; |
| 2566 | } | 1818 | } |
| @@ -2569,7 +1821,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2569 | 1821 | ||
| 2570 | switch (c) | 1822 | switch (c) |
| 2571 | { | 1823 | { |
| 2572 | #ifdef emacs | ||
| 2573 | case ' ': | 1824 | case ' ': |
| 2574 | { | 1825 | { |
| 2575 | re_char *p1 = p; | 1826 | re_char *p1 = p; |
| @@ -2602,95 +1853,51 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2602 | pend = p + strlen (whitespace_regexp); | 1853 | pend = p + strlen (whitespace_regexp); |
| 2603 | break; | 1854 | break; |
| 2604 | } | 1855 | } |
| 2605 | #endif | ||
| 2606 | 1856 | ||
| 2607 | case '^': | 1857 | case '^': |
| 2608 | { | 1858 | if (! (p == pattern + 1 || at_begline_loc_p (pattern, p))) |
| 2609 | if ( /* If at start of pattern, it's an operator. */ | 1859 | goto normal_char; |
| 2610 | p == pattern + 1 | 1860 | BUF_PUSH (begline); |
| 2611 | /* If context independent, it's an operator. */ | ||
| 2612 | || syntax & RE_CONTEXT_INDEP_ANCHORS | ||
| 2613 | /* Otherwise, depends on what's come before. */ | ||
| 2614 | || at_begline_loc_p (pattern, p, syntax)) | ||
| 2615 | BUF_PUSH ((syntax & RE_NO_NEWLINE_ANCHOR) ? begbuf : begline); | ||
| 2616 | else | ||
| 2617 | goto normal_char; | ||
| 2618 | } | ||
| 2619 | break; | 1861 | break; |
| 2620 | 1862 | ||
| 2621 | |||
| 2622 | case '$': | 1863 | case '$': |
| 2623 | { | 1864 | if (! (p == pend || at_endline_loc_p (p, pend))) |
| 2624 | if ( /* If at end of pattern, it's an operator. */ | 1865 | goto normal_char; |
| 2625 | p == pend | 1866 | BUF_PUSH (endline); |
| 2626 | /* If context independent, it's an operator. */ | 1867 | break; |
| 2627 | || syntax & RE_CONTEXT_INDEP_ANCHORS | ||
| 2628 | /* Otherwise, depends on what's next. */ | ||
| 2629 | || at_endline_loc_p (p, pend, syntax)) | ||
| 2630 | BUF_PUSH ((syntax & RE_NO_NEWLINE_ANCHOR) ? endbuf : endline); | ||
| 2631 | else | ||
| 2632 | goto normal_char; | ||
| 2633 | } | ||
| 2634 | break; | ||
| 2635 | 1868 | ||
| 2636 | 1869 | ||
| 2637 | case '+': | 1870 | case '+': |
| 2638 | case '?': | 1871 | case '?': |
| 2639 | if ((syntax & RE_BK_PLUS_QM) | ||
| 2640 | || (syntax & RE_LIMITED_OPS)) | ||
| 2641 | goto normal_char; | ||
| 2642 | FALLTHROUGH; | ||
| 2643 | case '*': | 1872 | case '*': |
| 2644 | handle_plus: | ||
| 2645 | /* If there is no previous pattern... */ | 1873 | /* If there is no previous pattern... */ |
| 2646 | if (!laststart) | 1874 | if (!laststart) |
| 2647 | { | 1875 | goto normal_char; |
| 2648 | if (syntax & RE_CONTEXT_INVALID_OPS) | ||
| 2649 | FREE_STACK_RETURN (REG_BADRPT); | ||
| 2650 | else if (!(syntax & RE_CONTEXT_INDEP_OPS)) | ||
| 2651 | goto normal_char; | ||
| 2652 | } | ||
| 2653 | 1876 | ||
| 2654 | { | 1877 | { |
| 2655 | /* 1 means zero (many) matches is allowed. */ | 1878 | /* 1 means zero (many) matches is allowed. */ |
| 2656 | boolean zero_times_ok = 0, many_times_ok = 0; | 1879 | bool zero_times_ok = false, many_times_ok = false; |
| 2657 | boolean greedy = 1; | 1880 | bool greedy = true; |
| 2658 | 1881 | ||
| 2659 | /* If there is a sequence of repetition chars, collapse it | 1882 | /* If there is a sequence of repetition chars, collapse it |
| 2660 | down to just one (the right one). We can't combine | 1883 | down to just one (the right one). We can't combine |
| 2661 | interval operators with these because of, e.g., `a{2}*', | 1884 | interval operators with these because of, e.g., 'a{2}*', |
| 2662 | which should only match an even number of `a's. */ | 1885 | which should only match an even number of 'a's. */ |
| 2663 | 1886 | ||
| 2664 | for (;;) | 1887 | for (;;) |
| 2665 | { | 1888 | { |
| 2666 | if ((syntax & RE_FRUGAL) | 1889 | if (c == '?' && (zero_times_ok || many_times_ok)) |
| 2667 | && c == '?' && (zero_times_ok || many_times_ok)) | 1890 | greedy = false; |
| 2668 | greedy = 0; | ||
| 2669 | else | 1891 | else |
| 2670 | { | 1892 | { |
| 2671 | zero_times_ok |= c != '+'; | 1893 | zero_times_ok |= c != '+'; |
| 2672 | many_times_ok |= c != '?'; | 1894 | many_times_ok |= c != '?'; |
| 2673 | } | 1895 | } |
| 2674 | 1896 | ||
| 2675 | if (p == pend) | 1897 | if (! (p < pend && (*p == '*' || *p == '+' || *p == '?'))) |
| 2676 | break; | ||
| 2677 | else if (*p == '*' | ||
| 2678 | || (!(syntax & RE_BK_PLUS_QM) | ||
| 2679 | && (*p == '+' || *p == '?'))) | ||
| 2680 | ; | ||
| 2681 | else if (syntax & RE_BK_PLUS_QM && *p == '\\') | ||
| 2682 | { | ||
| 2683 | if (p+1 == pend) | ||
| 2684 | FREE_STACK_RETURN (REG_EESCAPE); | ||
| 2685 | if (p[1] == '+' || p[1] == '?') | ||
| 2686 | PATFETCH (c); /* Gobble up the backslash. */ | ||
| 2687 | else | ||
| 2688 | break; | ||
| 2689 | } | ||
| 2690 | else | ||
| 2691 | break; | 1898 | break; |
| 2692 | /* If we get here, we found another repeat character. */ | 1899 | /* If we get here, we found another repeat character. */ |
| 2693 | PATFETCH (c); | 1900 | c = *p++; |
| 2694 | } | 1901 | } |
| 2695 | 1902 | ||
| 2696 | /* Star, etc. applied to an empty pattern is equivalent | 1903 | /* Star, etc. applied to an empty pattern is equivalent |
| @@ -2704,25 +1911,25 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2704 | { | 1911 | { |
| 2705 | if (many_times_ok) | 1912 | if (many_times_ok) |
| 2706 | { | 1913 | { |
| 2707 | boolean simple = skip_one_char (laststart) == b; | 1914 | bool simple = skip_one_char (laststart) == b; |
| 2708 | size_t startoffset = 0; | 1915 | size_t startoffset = 0; |
| 2709 | re_opcode_t ofj = | 1916 | re_opcode_t ofj = |
| 2710 | /* Check if the loop can match the empty string. */ | 1917 | /* Check if the loop can match the empty string. */ |
| 2711 | (simple || !analyze_first (laststart, b, NULL, 0)) | 1918 | (simple || !analyze_first (laststart, b, NULL, 0)) |
| 2712 | ? on_failure_jump : on_failure_jump_loop; | 1919 | ? on_failure_jump : on_failure_jump_loop; |
| 2713 | assert (skip_one_char (laststart) <= b); | 1920 | eassert (skip_one_char (laststart) <= b); |
| 2714 | 1921 | ||
| 2715 | if (!zero_times_ok && simple) | 1922 | if (!zero_times_ok && simple) |
| 2716 | { /* Since simple * loops can be made faster by using | 1923 | { /* Since simple * loops can be made faster by using |
| 2717 | on_failure_keep_string_jump, we turn simple P+ | 1924 | on_failure_keep_string_jump, we turn simple P+ |
| 2718 | into PP* if P is simple. */ | 1925 | into PP* if P is simple. */ |
| 2719 | unsigned char *p1, *p2; | 1926 | unsigned char *p1, *p2; |
| 2720 | startoffset = b - laststart; | 1927 | startoffset = b - laststart; |
| 2721 | GET_BUFFER_SPACE (startoffset); | 1928 | GET_BUFFER_SPACE (startoffset); |
| 2722 | p1 = b; p2 = laststart; | 1929 | p1 = b; p2 = laststart; |
| 2723 | while (p2 < p1) | 1930 | while (p2 < p1) |
| 2724 | *b++ = *p2++; | 1931 | *b++ = *p2++; |
| 2725 | zero_times_ok = 1; | 1932 | zero_times_ok = 1; |
| 2726 | } | 1933 | } |
| 2727 | 1934 | ||
| 2728 | GET_BUFFER_SPACE (6); | 1935 | GET_BUFFER_SPACE (6); |
| @@ -2743,7 +1950,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2743 | else | 1950 | else |
| 2744 | { | 1951 | { |
| 2745 | /* A simple ? pattern. */ | 1952 | /* A simple ? pattern. */ |
| 2746 | assert (zero_times_ok); | 1953 | eassert (zero_times_ok); |
| 2747 | GET_BUFFER_SPACE (3); | 1954 | GET_BUFFER_SPACE (3); |
| 2748 | INSERT_JUMP (on_failure_jump, laststart, b + 3); | 1955 | INSERT_JUMP (on_failure_jump, laststart, b + 3); |
| 2749 | b += 3; | 1956 | b += 3; |
| @@ -2755,7 +1962,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2755 | GET_BUFFER_SPACE (7); /* We might use less. */ | 1962 | GET_BUFFER_SPACE (7); /* We might use less. */ |
| 2756 | if (many_times_ok) | 1963 | if (many_times_ok) |
| 2757 | { | 1964 | { |
| 2758 | boolean emptyp = analyze_first (laststart, b, NULL, 0); | 1965 | bool emptyp = analyze_first (laststart, b, NULL, 0); |
| 2759 | 1966 | ||
| 2760 | /* The non-greedy multiple match looks like | 1967 | /* The non-greedy multiple match looks like |
| 2761 | a repeat..until: we only need a conditional jump | 1968 | a repeat..until: we only need a conditional jump |
| @@ -2807,8 +2014,8 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2807 | 2014 | ||
| 2808 | laststart = b; | 2015 | laststart = b; |
| 2809 | 2016 | ||
| 2810 | /* We test `*p == '^' twice, instead of using an if | 2017 | /* Test '*p == '^' twice, instead of using an if |
| 2811 | statement, so we only need one BUF_PUSH. */ | 2018 | statement, so we need only one BUF_PUSH. */ |
| 2812 | BUF_PUSH (*p == '^' ? charset_not : charset); | 2019 | BUF_PUSH (*p == '^' ? charset_not : charset); |
| 2813 | if (*p == '^') | 2020 | if (*p == '^') |
| 2814 | p++; | 2021 | p++; |
| @@ -2822,25 +2029,18 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2822 | /* Clear the whole map. */ | 2029 | /* Clear the whole map. */ |
| 2823 | memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH); | 2030 | memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH); |
| 2824 | 2031 | ||
| 2825 | /* charset_not matches newline according to a syntax bit. */ | ||
| 2826 | if ((re_opcode_t) b[-2] == charset_not | ||
| 2827 | && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) | ||
| 2828 | SET_LIST_BIT ('\n'); | ||
| 2829 | |||
| 2830 | /* Read in characters and ranges, setting map bits. */ | 2032 | /* Read in characters and ranges, setting map bits. */ |
| 2831 | for (;;) | 2033 | for (;;) |
| 2832 | { | 2034 | { |
| 2833 | boolean escaped_char = false; | ||
| 2834 | const unsigned char *p2 = p; | 2035 | const unsigned char *p2 = p; |
| 2835 | re_wctype_t cc; | 2036 | int ch; |
| 2836 | re_wchar_t ch; | ||
| 2837 | 2037 | ||
| 2838 | if (p == pend) FREE_STACK_RETURN (REG_EBRACK); | 2038 | if (p == pend) FREE_STACK_RETURN (REG_EBRACK); |
| 2839 | 2039 | ||
| 2840 | /* See if we're at the beginning of a possible character | 2040 | /* See if we're at the beginning of a possible character |
| 2841 | class. */ | 2041 | class. */ |
| 2842 | if (syntax & RE_CHAR_CLASSES && | 2042 | re_wctype_t cc = re_wctype_parse (&p, pend - p); |
| 2843 | (cc = re_wctype_parse(&p, pend - p)) != -1) | 2043 | if (cc != -1) |
| 2844 | { | 2044 | { |
| 2845 | if (cc == 0) | 2045 | if (cc == 0) |
| 2846 | FREE_STACK_RETURN (REG_ECTYPE); | 2046 | FREE_STACK_RETURN (REG_ECTYPE); |
| @@ -2848,15 +2048,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2848 | if (p == pend) | 2048 | if (p == pend) |
| 2849 | FREE_STACK_RETURN (REG_EBRACK); | 2049 | FREE_STACK_RETURN (REG_EBRACK); |
| 2850 | 2050 | ||
| 2851 | #ifndef emacs | ||
| 2852 | for (ch = 0; ch < (1 << BYTEWIDTH); ++ch) | ||
| 2853 | if (re_iswctype (btowc (ch), cc)) | ||
| 2854 | { | ||
| 2855 | c = TRANSLATE (ch); | ||
| 2856 | if (c < (1 << BYTEWIDTH)) | ||
| 2857 | SET_LIST_BIT (c); | ||
| 2858 | } | ||
| 2859 | #else /* emacs */ | ||
| 2860 | /* Most character classes in a multibyte match just set | 2051 | /* Most character classes in a multibyte match just set |
| 2861 | a flag. Exceptions are is_blank, is_digit, is_cntrl, and | 2052 | a flag. Exceptions are is_blank, is_digit, is_cntrl, and |
| 2862 | is_xdigit, since they can only match ASCII characters. | 2053 | is_xdigit, since they can only match ASCII characters. |
| @@ -2883,7 +2074,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2883 | } | 2074 | } |
| 2884 | SET_RANGE_TABLE_WORK_AREA_BIT | 2075 | SET_RANGE_TABLE_WORK_AREA_BIT |
| 2885 | (range_table_work, re_wctype_to_bit (cc)); | 2076 | (range_table_work, re_wctype_to_bit (cc)); |
| 2886 | #endif /* emacs */ | 2077 | |
| 2887 | /* In most cases the matching rule for char classes only | 2078 | /* In most cases the matching rule for char classes only |
| 2888 | uses the syntax table for multibyte chars, so that the | 2079 | uses the syntax table for multibyte chars, so that the |
| 2889 | content of the syntax-table is not hardcoded in the | 2080 | content of the syntax-table is not hardcoded in the |
| @@ -2901,60 +2092,33 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2901 | (let ((case-fold-search t)) (string-match "[A-_]" "A")) */ | 2092 | (let ((case-fold-search t)) (string-match "[A-_]" "A")) */ |
| 2902 | PATFETCH (c); | 2093 | PATFETCH (c); |
| 2903 | 2094 | ||
| 2904 | /* \ might escape characters inside [...] and [^...]. */ | 2095 | /* Could be the end of the bracket expression. If it's |
| 2905 | if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') | 2096 | not (i.e., when the bracket expression is '[]' so |
| 2906 | { | 2097 | far), the ']' character bit gets set way below. */ |
| 2907 | if (p == pend) FREE_STACK_RETURN (REG_EESCAPE); | 2098 | if (c == ']' && p2 != p1) |
| 2908 | 2099 | break; | |
| 2909 | PATFETCH (c); | ||
| 2910 | escaped_char = true; | ||
| 2911 | } | ||
| 2912 | else | ||
| 2913 | { | ||
| 2914 | /* Could be the end of the bracket expression. If it's | ||
| 2915 | not (i.e., when the bracket expression is `[]' so | ||
| 2916 | far), the ']' character bit gets set way below. */ | ||
| 2917 | if (c == ']' && p2 != p1) | ||
| 2918 | break; | ||
| 2919 | } | ||
| 2920 | 2100 | ||
| 2921 | if (p < pend && p[0] == '-' && p[1] != ']') | 2101 | if (p < pend && p[0] == '-' && p[1] != ']') |
| 2922 | { | 2102 | { |
| 2923 | 2103 | ||
| 2924 | /* Discard the `-'. */ | 2104 | /* Discard the '-'. */ |
| 2925 | PATFETCH (c1); | 2105 | PATFETCH (c1); |
| 2926 | 2106 | ||
| 2927 | /* Fetch the character which ends the range. */ | 2107 | /* Fetch the character which ends the range. */ |
| 2928 | PATFETCH (c1); | 2108 | PATFETCH (c1); |
| 2929 | #ifdef emacs | 2109 | |
| 2930 | if (CHAR_BYTE8_P (c1) | 2110 | if (CHAR_BYTE8_P (c1) |
| 2931 | && ! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) | 2111 | && ! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) |
| 2932 | /* Treat the range from a multibyte character to | 2112 | /* Treat the range from a multibyte character to |
| 2933 | raw-byte character as empty. */ | 2113 | raw-byte character as empty. */ |
| 2934 | c = c1 + 1; | 2114 | c = c1 + 1; |
| 2935 | #endif /* emacs */ | ||
| 2936 | } | 2115 | } |
| 2937 | else | 2116 | else |
| 2938 | /* Range from C to C. */ | 2117 | /* Range from C to C. */ |
| 2939 | c1 = c; | 2118 | c1 = c; |
| 2940 | 2119 | ||
| 2941 | if (c > c1) | 2120 | if (c <= c1) |
| 2942 | { | 2121 | { |
| 2943 | if (syntax & RE_NO_EMPTY_RANGES) | ||
| 2944 | FREE_STACK_RETURN (REG_ERANGEX); | ||
| 2945 | /* Else, repeat the loop. */ | ||
| 2946 | } | ||
| 2947 | else | ||
| 2948 | { | ||
| 2949 | #ifndef emacs | ||
| 2950 | /* Set the range into bitmap */ | ||
| 2951 | for (; c <= c1; c++) | ||
| 2952 | { | ||
| 2953 | ch = TRANSLATE (c); | ||
| 2954 | if (ch < (1 << BYTEWIDTH)) | ||
| 2955 | SET_LIST_BIT (ch); | ||
| 2956 | } | ||
| 2957 | #else /* emacs */ | ||
| 2958 | if (c < 128) | 2122 | if (c < 128) |
| 2959 | { | 2123 | { |
| 2960 | ch = min (127, c1); | 2124 | ch = min (127, c1); |
| @@ -2963,25 +2127,17 @@ regex_compile (re_char *pattern, size_t size, | |||
| 2963 | if (CHAR_BYTE8_P (c1)) | 2127 | if (CHAR_BYTE8_P (c1)) |
| 2964 | c = BYTE8_TO_CHAR (128); | 2128 | c = BYTE8_TO_CHAR (128); |
| 2965 | } | 2129 | } |
| 2966 | if (c <= c1) | 2130 | if (CHAR_BYTE8_P (c)) |
| 2967 | { | 2131 | { |
| 2968 | if (CHAR_BYTE8_P (c)) | 2132 | c = CHAR_TO_BYTE8 (c); |
| 2969 | { | 2133 | c1 = CHAR_TO_BYTE8 (c1); |
| 2970 | c = CHAR_TO_BYTE8 (c); | 2134 | for (; c <= c1; c++) |
| 2971 | c1 = CHAR_TO_BYTE8 (c1); | 2135 | SET_LIST_BIT (c); |
| 2972 | for (; c <= c1; c++) | ||
| 2973 | SET_LIST_BIT (c); | ||
| 2974 | } | ||
| 2975 | else if (multibyte) | ||
| 2976 | { | ||
| 2977 | SETUP_MULTIBYTE_RANGE (range_table_work, c, c1); | ||
| 2978 | } | ||
| 2979 | else | ||
| 2980 | { | ||
| 2981 | SETUP_UNIBYTE_RANGE (range_table_work, c, c1); | ||
| 2982 | } | ||
| 2983 | } | 2136 | } |
| 2984 | #endif /* emacs */ | 2137 | else if (multibyte) |
| 2138 | SETUP_MULTIBYTE_RANGE (range_table_work, c, c1); | ||
| 2139 | else | ||
| 2140 | SETUP_UNIBYTE_RANGE (range_table_work, c, c1); | ||
| 2985 | } | 2141 | } |
| 2986 | } | 2142 | } |
| 2987 | 2143 | ||
| @@ -3006,8 +2162,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3006 | /* Indicate the existence of range table. */ | 2162 | /* Indicate the existence of range table. */ |
| 3007 | laststart[1] |= 0x80; | 2163 | laststart[1] |= 0x80; |
| 3008 | 2164 | ||
| 3009 | /* Store the character class flag bits into the range table. | 2165 | /* Store the character class flag bits into the range table. */ |
| 3010 | If not in emacs, these flag bits are always 0. */ | ||
| 3011 | *b++ = RANGE_TABLE_WORK_BITS (range_table_work) & 0xff; | 2166 | *b++ = RANGE_TABLE_WORK_BITS (range_table_work) & 0xff; |
| 3012 | *b++ = RANGE_TABLE_WORK_BITS (range_table_work) >> 8; | 2167 | *b++ = RANGE_TABLE_WORK_BITS (range_table_work) >> 8; |
| 3013 | 2168 | ||
| @@ -3020,41 +2175,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3020 | break; | 2175 | break; |
| 3021 | 2176 | ||
| 3022 | 2177 | ||
| 3023 | case '(': | ||
| 3024 | if (syntax & RE_NO_BK_PARENS) | ||
| 3025 | goto handle_open; | ||
| 3026 | else | ||
| 3027 | goto normal_char; | ||
| 3028 | |||
| 3029 | |||
| 3030 | case ')': | ||
| 3031 | if (syntax & RE_NO_BK_PARENS) | ||
| 3032 | goto handle_close; | ||
| 3033 | else | ||
| 3034 | goto normal_char; | ||
| 3035 | |||
| 3036 | |||
| 3037 | case '\n': | ||
| 3038 | if (syntax & RE_NEWLINE_ALT) | ||
| 3039 | goto handle_alt; | ||
| 3040 | else | ||
| 3041 | goto normal_char; | ||
| 3042 | |||
| 3043 | |||
| 3044 | case '|': | ||
| 3045 | if (syntax & RE_NO_BK_VBAR) | ||
| 3046 | goto handle_alt; | ||
| 3047 | else | ||
| 3048 | goto normal_char; | ||
| 3049 | |||
| 3050 | |||
| 3051 | case '{': | ||
| 3052 | if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) | ||
| 3053 | goto handle_interval; | ||
| 3054 | else | ||
| 3055 | goto normal_char; | ||
| 3056 | |||
| 3057 | |||
| 3058 | case '\\': | 2178 | case '\\': |
| 3059 | if (p == pend) FREE_STACK_RETURN (REG_EESCAPE); | 2179 | if (p == pend) FREE_STACK_RETURN (REG_EESCAPE); |
| 3060 | 2180 | ||
| @@ -3066,17 +2186,13 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3066 | switch (c) | 2186 | switch (c) |
| 3067 | { | 2187 | { |
| 3068 | case '(': | 2188 | case '(': |
| 3069 | if (syntax & RE_NO_BK_PARENS) | ||
| 3070 | goto normal_backslash; | ||
| 3071 | |||
| 3072 | handle_open: | ||
| 3073 | { | 2189 | { |
| 3074 | int shy = 0; | 2190 | int shy = 0; |
| 3075 | regnum_t regnum = 0; | 2191 | regnum_t regnum = 0; |
| 3076 | if (p+1 < pend) | 2192 | if (p+1 < pend) |
| 3077 | { | 2193 | { |
| 3078 | /* Look for a special (?...) construct */ | 2194 | /* Look for a special (?...) construct */ |
| 3079 | if ((syntax & RE_SHY_GROUPS) && *p == '?') | 2195 | if (*p == '?') |
| 3080 | { | 2196 | { |
| 3081 | PATFETCH (c); /* Gobble up the '?'. */ | 2197 | PATFETCH (c); /* Gobble up the '?'. */ |
| 3082 | while (!shy) | 2198 | while (!shy) |
| @@ -3126,8 +2242,6 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3126 | { | 2242 | { |
| 3127 | RETALLOC (compile_stack.stack, compile_stack.size << 1, | 2243 | RETALLOC (compile_stack.stack, compile_stack.size << 1, |
| 3128 | compile_stack_elt_t); | 2244 | compile_stack_elt_t); |
| 3129 | if (compile_stack.stack == NULL) return REG_ESPACE; | ||
| 3130 | |||
| 3131 | compile_stack.size <<= 1; | 2245 | compile_stack.size <<= 1; |
| 3132 | } | 2246 | } |
| 3133 | 2247 | ||
| @@ -3159,35 +2273,22 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3159 | } | 2273 | } |
| 3160 | 2274 | ||
| 3161 | case ')': | 2275 | case ')': |
| 3162 | if (syntax & RE_NO_BK_PARENS) goto normal_backslash; | ||
| 3163 | |||
| 3164 | if (COMPILE_STACK_EMPTY) | 2276 | if (COMPILE_STACK_EMPTY) |
| 3165 | { | 2277 | FREE_STACK_RETURN (REG_ERPAREN); |
| 3166 | if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) | ||
| 3167 | goto normal_backslash; | ||
| 3168 | else | ||
| 3169 | FREE_STACK_RETURN (REG_ERPAREN); | ||
| 3170 | } | ||
| 3171 | 2278 | ||
| 3172 | handle_close: | ||
| 3173 | FIXUP_ALT_JUMP (); | 2279 | FIXUP_ALT_JUMP (); |
| 3174 | 2280 | ||
| 3175 | /* See similar code for backslashed left paren above. */ | 2281 | /* See similar code for backslashed left paren above. */ |
| 3176 | if (COMPILE_STACK_EMPTY) | 2282 | if (COMPILE_STACK_EMPTY) |
| 3177 | { | 2283 | FREE_STACK_RETURN (REG_ERPAREN); |
| 3178 | if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) | ||
| 3179 | goto normal_char; | ||
| 3180 | else | ||
| 3181 | FREE_STACK_RETURN (REG_ERPAREN); | ||
| 3182 | } | ||
| 3183 | 2284 | ||
| 3184 | /* Since we just checked for an empty stack above, this | 2285 | /* Since we just checked for an empty stack above, this |
| 3185 | ``can't happen''. */ | 2286 | "can't happen". */ |
| 3186 | assert (compile_stack.avail != 0); | 2287 | eassert (compile_stack.avail != 0); |
| 3187 | { | 2288 | { |
| 3188 | /* We don't just want to restore into `regnum', because | 2289 | /* We don't just want to restore into 'regnum', because |
| 3189 | later groups should continue to be numbered higher, | 2290 | later groups should continue to be numbered higher, |
| 3190 | as in `(ab)c(de)' -- the second group is #2. */ | 2291 | as in '(ab)c(de)' -- the second group is #2. */ |
| 3191 | regnum_t regnum; | 2292 | regnum_t regnum; |
| 3192 | 2293 | ||
| 3193 | compile_stack.avail--; | 2294 | compile_stack.avail--; |
| @@ -3211,13 +2312,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3211 | break; | 2312 | break; |
| 3212 | 2313 | ||
| 3213 | 2314 | ||
| 3214 | case '|': /* `\|'. */ | 2315 | case '|': /* '\|'. */ |
| 3215 | if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) | ||
| 3216 | goto normal_backslash; | ||
| 3217 | handle_alt: | ||
| 3218 | if (syntax & RE_LIMITED_OPS) | ||
| 3219 | goto normal_char; | ||
| 3220 | |||
| 3221 | /* Insert before the previous alternative a jump which | 2316 | /* Insert before the previous alternative a jump which |
| 3222 | jumps to this alternative if the former fails. */ | 2317 | jumps to this alternative if the former fails. */ |
| 3223 | GET_BUFFER_SPACE (3); | 2318 | GET_BUFFER_SPACE (3); |
| @@ -3234,12 +2329,12 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3234 | _____ _____ | 2329 | _____ _____ |
| 3235 | | | | | | 2330 | | | | | |
| 3236 | | v | v | 2331 | | v | v |
| 3237 | a | b | c | 2332 | A | B | C |
| 3238 | 2333 | ||
| 3239 | If we are at `b', then fixup_alt_jump right now points to a | 2334 | If we are at B, then fixup_alt_jump right now points to a |
| 3240 | three-byte space after `a'. We'll put in the jump, set | 2335 | three-byte space after A. We'll put in the jump, set |
| 3241 | fixup_alt_jump to right after `b', and leave behind three | 2336 | fixup_alt_jump to right after B, and leave behind three |
| 3242 | bytes which we'll fill in when we get to after `c'. */ | 2337 | bytes which we'll fill in when we get to after C. */ |
| 3243 | 2338 | ||
| 3244 | FIXUP_ALT_JUMP (); | 2339 | FIXUP_ALT_JUMP (); |
| 3245 | 2340 | ||
| @@ -3256,17 +2351,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3256 | 2351 | ||
| 3257 | 2352 | ||
| 3258 | case '{': | 2353 | case '{': |
| 3259 | /* If \{ is a literal. */ | ||
| 3260 | if (!(syntax & RE_INTERVALS) | ||
| 3261 | /* If we're at `\{' and it's not the open-interval | ||
| 3262 | operator. */ | ||
| 3263 | || (syntax & RE_NO_BK_BRACES)) | ||
| 3264 | goto normal_backslash; | ||
| 3265 | |||
| 3266 | handle_interval: | ||
| 3267 | { | 2354 | { |
| 3268 | /* If got here, then the syntax allows intervals. */ | ||
| 3269 | |||
| 3270 | /* At least (most) this many matches must be made. */ | 2355 | /* At least (most) this many matches must be made. */ |
| 3271 | int lower_bound = 0, upper_bound = -1; | 2356 | int lower_bound = 0, upper_bound = -1; |
| 3272 | 2357 | ||
| @@ -3277,37 +2362,23 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3277 | if (c == ',') | 2362 | if (c == ',') |
| 3278 | GET_INTERVAL_COUNT (upper_bound); | 2363 | GET_INTERVAL_COUNT (upper_bound); |
| 3279 | else | 2364 | else |
| 3280 | /* Interval such as `{1}' => match exactly once. */ | 2365 | /* Interval such as '{1}' => match exactly once. */ |
| 3281 | upper_bound = lower_bound; | 2366 | upper_bound = lower_bound; |
| 3282 | 2367 | ||
| 3283 | if (lower_bound < 0 | 2368 | if (lower_bound < 0 |
| 3284 | || (0 <= upper_bound && upper_bound < lower_bound)) | 2369 | || (0 <= upper_bound && upper_bound < lower_bound) |
| 2370 | || c != '\\') | ||
| 3285 | FREE_STACK_RETURN (REG_BADBR); | 2371 | FREE_STACK_RETURN (REG_BADBR); |
| 3286 | 2372 | if (p == pend) | |
| 3287 | if (!(syntax & RE_NO_BK_BRACES)) | 2373 | FREE_STACK_RETURN (REG_EESCAPE); |
| 3288 | { | 2374 | if (*p++ != '}') |
| 3289 | if (c != '\\') | ||
| 3290 | FREE_STACK_RETURN (REG_BADBR); | ||
| 3291 | if (p == pend) | ||
| 3292 | FREE_STACK_RETURN (REG_EESCAPE); | ||
| 3293 | PATFETCH (c); | ||
| 3294 | } | ||
| 3295 | |||
| 3296 | if (c != '}') | ||
| 3297 | FREE_STACK_RETURN (REG_BADBR); | 2375 | FREE_STACK_RETURN (REG_BADBR); |
| 3298 | 2376 | ||
| 3299 | /* We just parsed a valid interval. */ | 2377 | /* We just parsed a valid interval. */ |
| 3300 | 2378 | ||
| 3301 | /* If it's invalid to have no preceding re. */ | 2379 | /* If it's invalid to have no preceding re. */ |
| 3302 | if (!laststart) | 2380 | if (!laststart) |
| 3303 | { | 2381 | goto unfetch_interval; |
| 3304 | if (syntax & RE_CONTEXT_INVALID_OPS) | ||
| 3305 | FREE_STACK_RETURN (REG_BADRPT); | ||
| 3306 | else if (syntax & RE_CONTEXT_INDEP_OPS) | ||
| 3307 | laststart = b; | ||
| 3308 | else | ||
| 3309 | goto unfetch_interval; | ||
| 3310 | } | ||
| 3311 | 2382 | ||
| 3312 | if (upper_bound == 0) | 2383 | if (upper_bound == 0) |
| 3313 | /* If the upper bound is zero, just drop the sub pattern | 2384 | /* If the upper bound is zero, just drop the sub pattern |
| @@ -3324,8 +2395,8 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3324 | succeed_n <after jump addr> <succeed_n count> | 2395 | succeed_n <after jump addr> <succeed_n count> |
| 3325 | <body of loop> | 2396 | <body of loop> |
| 3326 | jump_n <succeed_n addr> <jump count> | 2397 | jump_n <succeed_n addr> <jump count> |
| 3327 | (The upper bound and `jump_n' are omitted if | 2398 | (The upper bound and 'jump_n' are omitted if |
| 3328 | `upper_bound' is 1, though.) */ | 2399 | 'upper_bound' is 1, though.) */ |
| 3329 | else | 2400 | else |
| 3330 | { /* If the upper bound is > 1, we need to insert | 2401 | { /* If the upper bound is > 1, we need to insert |
| 3331 | more at the end of the loop. */ | 2402 | more at the end of the loop. */ |
| @@ -3345,21 +2416,22 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3345 | } | 2416 | } |
| 3346 | else | 2417 | else |
| 3347 | { | 2418 | { |
| 3348 | /* Initialize lower bound of the `succeed_n', even | 2419 | /* Initialize lower bound of the 'succeed_n', even |
| 3349 | though it will be set during matching by its | 2420 | though it will be set during matching by its |
| 3350 | attendant `set_number_at' (inserted next), | 2421 | attendant 'set_number_at' (inserted next), |
| 3351 | because `re_compile_fastmap' needs to know. | 2422 | because 're_compile_fastmap' needs to know. |
| 3352 | Jump to the `jump_n' we might insert below. */ | 2423 | Jump to the 'jump_n' we might insert below. */ |
| 3353 | INSERT_JUMP2 (succeed_n, laststart, | 2424 | INSERT_JUMP2 (succeed_n, laststart, |
| 3354 | b + 5 + nbytes, | 2425 | b + 5 + nbytes, |
| 3355 | lower_bound); | 2426 | lower_bound); |
| 3356 | b += 5; | 2427 | b += 5; |
| 3357 | 2428 | ||
| 3358 | /* Code to initialize the lower bound. Insert | 2429 | /* Code to initialize the lower bound. Insert |
| 3359 | before the `succeed_n'. The `5' is the last two | 2430 | before the 'succeed_n'. The '5' is the last two |
| 3360 | bytes of this `set_number_at', plus 3 bytes of | 2431 | bytes of this 'set_number_at', plus 3 bytes of |
| 3361 | the following `succeed_n'. */ | 2432 | the following 'succeed_n'. */ |
| 3362 | insert_op2 (set_number_at, laststart, 5, lower_bound, b); | 2433 | insert_op2 (set_number_at, laststart, 5, |
| 2434 | lower_bound, b); | ||
| 3363 | b += 5; | 2435 | b += 5; |
| 3364 | startoffset += 5; | 2436 | startoffset += 5; |
| 3365 | } | 2437 | } |
| @@ -3373,28 +2445,28 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3373 | } | 2445 | } |
| 3374 | else if (upper_bound > 1) | 2446 | else if (upper_bound > 1) |
| 3375 | { /* More than one repetition is allowed, so | 2447 | { /* More than one repetition is allowed, so |
| 3376 | append a backward jump to the `succeed_n' | 2448 | append a backward jump to the 'succeed_n' |
| 3377 | that starts this interval. | 2449 | that starts this interval. |
| 3378 | 2450 | ||
| 3379 | When we've reached this during matching, | 2451 | When we've reached this during matching, |
| 3380 | we'll have matched the interval once, so | 2452 | we'll have matched the interval once, so |
| 3381 | jump back only `upper_bound - 1' times. */ | 2453 | jump back only 'upper_bound - 1' times. */ |
| 3382 | STORE_JUMP2 (jump_n, b, laststart + startoffset, | 2454 | STORE_JUMP2 (jump_n, b, laststart + startoffset, |
| 3383 | upper_bound - 1); | 2455 | upper_bound - 1); |
| 3384 | b += 5; | 2456 | b += 5; |
| 3385 | 2457 | ||
| 3386 | /* The location we want to set is the second | 2458 | /* The location we want to set is the second |
| 3387 | parameter of the `jump_n'; that is `b-2' as | 2459 | parameter of the 'jump_n'; that is 'b-2' as |
| 3388 | an absolute address. `laststart' will be | 2460 | an absolute address. 'laststart' will be |
| 3389 | the `set_number_at' we're about to insert; | 2461 | the 'set_number_at' we're about to insert; |
| 3390 | `laststart+3' the number to set, the source | 2462 | 'laststart+3' the number to set, the source |
| 3391 | for the relative address. But we are | 2463 | for the relative address. But we are |
| 3392 | inserting into the middle of the pattern -- | 2464 | inserting into the middle of the pattern -- |
| 3393 | so everything is getting moved up by 5. | 2465 | so everything is getting moved up by 5. |
| 3394 | Conclusion: (b - 2) - (laststart + 3) + 5, | 2466 | Conclusion: (b - 2) - (laststart + 3) + 5, |
| 3395 | i.e., b - laststart. | 2467 | i.e., b - laststart. |
| 3396 | 2468 | ||
| 3397 | We insert this at the beginning of the loop | 2469 | Insert this at the beginning of the loop |
| 3398 | so that if we fail during matching, we'll | 2470 | so that if we fail during matching, we'll |
| 3399 | reinitialize the bounds. */ | 2471 | reinitialize the bounds. */ |
| 3400 | insert_op2 (set_number_at, laststart, b - laststart, | 2472 | insert_op2 (set_number_at, laststart, b - laststart, |
| @@ -3409,22 +2481,13 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3409 | 2481 | ||
| 3410 | unfetch_interval: | 2482 | unfetch_interval: |
| 3411 | /* If an invalid interval, match the characters as literals. */ | 2483 | /* If an invalid interval, match the characters as literals. */ |
| 3412 | assert (beg_interval); | 2484 | eassert (beg_interval); |
| 3413 | p = beg_interval; | 2485 | p = beg_interval; |
| 3414 | beg_interval = NULL; | 2486 | beg_interval = NULL; |
| 3415 | 2487 | eassert (p > pattern && p[-1] == '\\'); | |
| 3416 | /* normal_char and normal_backslash need `c'. */ | ||
| 3417 | c = '{'; | 2488 | c = '{'; |
| 2489 | goto normal_char; | ||
| 3418 | 2490 | ||
| 3419 | if (!(syntax & RE_NO_BK_BRACES)) | ||
| 3420 | { | ||
| 3421 | assert (p > pattern && p[-1] == '\\'); | ||
| 3422 | goto normal_backslash; | ||
| 3423 | } | ||
| 3424 | else | ||
| 3425 | goto normal_char; | ||
| 3426 | |||
| 3427 | #ifdef emacs | ||
| 3428 | case '=': | 2491 | case '=': |
| 3429 | laststart = b; | 2492 | laststart = b; |
| 3430 | BUF_PUSH (at_dot); | 2493 | BUF_PUSH (at_dot); |
| @@ -3453,42 +2516,30 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3453 | PATFETCH (c); | 2516 | PATFETCH (c); |
| 3454 | BUF_PUSH_2 (notcategoryspec, c); | 2517 | BUF_PUSH_2 (notcategoryspec, c); |
| 3455 | break; | 2518 | break; |
| 3456 | #endif /* emacs */ | ||
| 3457 | |||
| 3458 | 2519 | ||
| 3459 | case 'w': | 2520 | case 'w': |
| 3460 | if (syntax & RE_NO_GNU_OPS) | ||
| 3461 | goto normal_char; | ||
| 3462 | laststart = b; | 2521 | laststart = b; |
| 3463 | BUF_PUSH_2 (syntaxspec, Sword); | 2522 | BUF_PUSH_2 (syntaxspec, Sword); |
| 3464 | break; | 2523 | break; |
| 3465 | 2524 | ||
| 3466 | 2525 | ||
| 3467 | case 'W': | 2526 | case 'W': |
| 3468 | if (syntax & RE_NO_GNU_OPS) | ||
| 3469 | goto normal_char; | ||
| 3470 | laststart = b; | 2527 | laststart = b; |
| 3471 | BUF_PUSH_2 (notsyntaxspec, Sword); | 2528 | BUF_PUSH_2 (notsyntaxspec, Sword); |
| 3472 | break; | 2529 | break; |
| 3473 | 2530 | ||
| 3474 | 2531 | ||
| 3475 | case '<': | 2532 | case '<': |
| 3476 | if (syntax & RE_NO_GNU_OPS) | ||
| 3477 | goto normal_char; | ||
| 3478 | laststart = b; | 2533 | laststart = b; |
| 3479 | BUF_PUSH (wordbeg); | 2534 | BUF_PUSH (wordbeg); |
| 3480 | break; | 2535 | break; |
| 3481 | 2536 | ||
| 3482 | case '>': | 2537 | case '>': |
| 3483 | if (syntax & RE_NO_GNU_OPS) | ||
| 3484 | goto normal_char; | ||
| 3485 | laststart = b; | 2538 | laststart = b; |
| 3486 | BUF_PUSH (wordend); | 2539 | BUF_PUSH (wordend); |
| 3487 | break; | 2540 | break; |
| 3488 | 2541 | ||
| 3489 | case '_': | 2542 | case '_': |
| 3490 | if (syntax & RE_NO_GNU_OPS) | ||
| 3491 | goto normal_char; | ||
| 3492 | laststart = b; | 2543 | laststart = b; |
| 3493 | PATFETCH (c); | 2544 | PATFETCH (c); |
| 3494 | if (c == '<') | 2545 | if (c == '<') |
| @@ -3500,38 +2551,25 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3500 | break; | 2551 | break; |
| 3501 | 2552 | ||
| 3502 | case 'b': | 2553 | case 'b': |
| 3503 | if (syntax & RE_NO_GNU_OPS) | ||
| 3504 | goto normal_char; | ||
| 3505 | BUF_PUSH (wordbound); | 2554 | BUF_PUSH (wordbound); |
| 3506 | break; | 2555 | break; |
| 3507 | 2556 | ||
| 3508 | case 'B': | 2557 | case 'B': |
| 3509 | if (syntax & RE_NO_GNU_OPS) | ||
| 3510 | goto normal_char; | ||
| 3511 | BUF_PUSH (notwordbound); | 2558 | BUF_PUSH (notwordbound); |
| 3512 | break; | 2559 | break; |
| 3513 | 2560 | ||
| 3514 | case '`': | 2561 | case '`': |
| 3515 | if (syntax & RE_NO_GNU_OPS) | ||
| 3516 | goto normal_char; | ||
| 3517 | BUF_PUSH (begbuf); | 2562 | BUF_PUSH (begbuf); |
| 3518 | break; | 2563 | break; |
| 3519 | 2564 | ||
| 3520 | case '\'': | 2565 | case '\'': |
| 3521 | if (syntax & RE_NO_GNU_OPS) | ||
| 3522 | goto normal_char; | ||
| 3523 | BUF_PUSH (endbuf); | 2566 | BUF_PUSH (endbuf); |
| 3524 | break; | 2567 | break; |
| 3525 | 2568 | ||
| 3526 | case '1': case '2': case '3': case '4': case '5': | 2569 | case '1': case '2': case '3': case '4': case '5': |
| 3527 | case '6': case '7': case '8': case '9': | 2570 | case '6': case '7': case '8': case '9': |
| 3528 | { | 2571 | { |
| 3529 | regnum_t reg; | 2572 | regnum_t reg = c - '0'; |
| 3530 | |||
| 3531 | if (syntax & RE_NO_BK_REFS) | ||
| 3532 | goto normal_backslash; | ||
| 3533 | |||
| 3534 | reg = c - '0'; | ||
| 3535 | 2573 | ||
| 3536 | if (reg > bufp->re_nsub || reg < 1 | 2574 | if (reg > bufp->re_nsub || reg < 1 |
| 3537 | /* Can't back reference to a subexp before its end. */ | 2575 | /* Can't back reference to a subexp before its end. */ |
| @@ -3543,16 +2581,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3543 | } | 2581 | } |
| 3544 | break; | 2582 | break; |
| 3545 | 2583 | ||
| 3546 | |||
| 3547 | case '+': | ||
| 3548 | case '?': | ||
| 3549 | if (syntax & RE_BK_PLUS_QM) | ||
| 3550 | goto handle_plus; | ||
| 3551 | else | ||
| 3552 | goto normal_backslash; | ||
| 3553 | |||
| 3554 | default: | 2584 | default: |
| 3555 | normal_backslash: | ||
| 3556 | /* You might think it would be useful for \ to mean | 2585 | /* You might think it would be useful for \ to mean |
| 3557 | not to translate; but if we don't translate it | 2586 | not to translate; but if we don't translate it |
| 3558 | it will never match anything. */ | 2587 | it will never match anything. */ |
| @@ -3562,7 +2591,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3562 | 2591 | ||
| 3563 | 2592 | ||
| 3564 | default: | 2593 | default: |
| 3565 | /* Expects the character in `c'. */ | 2594 | /* Expects the character in C. */ |
| 3566 | normal_char: | 2595 | normal_char: |
| 3567 | /* If no exactn currently being built. */ | 2596 | /* If no exactn currently being built. */ |
| 3568 | if (!pending_exact | 2597 | if (!pending_exact |
| @@ -3570,18 +2599,13 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3570 | /* If last exactn not at current position. */ | 2599 | /* If last exactn not at current position. */ |
| 3571 | || pending_exact + *pending_exact + 1 != b | 2600 | || pending_exact + *pending_exact + 1 != b |
| 3572 | 2601 | ||
| 3573 | /* We have only one byte following the exactn for the count. */ | 2602 | /* Only one byte follows the exactn for the count. */ |
| 3574 | || *pending_exact >= (1 << BYTEWIDTH) - MAX_MULTIBYTE_LENGTH | 2603 | || *pending_exact >= (1 << BYTEWIDTH) - MAX_MULTIBYTE_LENGTH |
| 3575 | 2604 | ||
| 3576 | /* If followed by a repetition operator. */ | 2605 | /* If followed by a repetition operator. */ |
| 3577 | || (p != pend && (*p == '*' || *p == '^')) | 2606 | || (p != pend |
| 3578 | || ((syntax & RE_BK_PLUS_QM) | 2607 | && (*p == '*' || *p == '+' || *p == '?' || *p == '^')) |
| 3579 | ? p + 1 < pend && *p == '\\' && (p[1] == '+' || p[1] == '?') | 2608 | || (p + 1 < pend && p[0] == '\\' && p[1] == '{')) |
| 3580 | : p != pend && (*p == '+' || *p == '?')) | ||
| 3581 | || ((syntax & RE_INTERVALS) | ||
| 3582 | && ((syntax & RE_NO_BK_BRACES) | ||
| 3583 | ? p != pend && *p == '{' | ||
| 3584 | : p + 1 < pend && p[0] == '\\' && p[1] == '{'))) | ||
| 3585 | { | 2609 | { |
| 3586 | /* Start building a new exactn. */ | 2610 | /* Start building a new exactn. */ |
| 3587 | 2611 | ||
| @@ -3606,7 +2630,7 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3606 | c1 = RE_CHAR_TO_MULTIBYTE (c); | 2630 | c1 = RE_CHAR_TO_MULTIBYTE (c); |
| 3607 | if (! CHAR_BYTE8_P (c1)) | 2631 | if (! CHAR_BYTE8_P (c1)) |
| 3608 | { | 2632 | { |
| 3609 | re_wchar_t c2 = TRANSLATE (c1); | 2633 | int c2 = TRANSLATE (c1); |
| 3610 | 2634 | ||
| 3611 | if (c1 != c2 && (c1 = RE_CHAR_TO_UNIBYTE (c2)) >= 0) | 2635 | if (c1 != c2 && (c1 = RE_CHAR_TO_UNIBYTE (c2)) >= 0) |
| 3612 | c = c1; | 2636 | c = c1; |
| @@ -3634,47 +2658,24 @@ regex_compile (re_char *pattern, size_t size, | |||
| 3634 | if (!posix_backtracking) | 2658 | if (!posix_backtracking) |
| 3635 | BUF_PUSH (succeed); | 2659 | BUF_PUSH (succeed); |
| 3636 | 2660 | ||
| 3637 | /* We have succeeded; set the length of the buffer. */ | 2661 | /* Success; set the length of the buffer. */ |
| 3638 | bufp->used = b - bufp->buffer; | 2662 | bufp->used = b - bufp->buffer; |
| 3639 | 2663 | ||
| 3640 | #ifdef DEBUG | 2664 | #ifdef REGEX_EMACS_DEBUG |
| 3641 | if (debug > 0) | 2665 | if (regex_emacs_debug > 0) |
| 3642 | { | 2666 | { |
| 3643 | re_compile_fastmap (bufp); | 2667 | re_compile_fastmap (bufp); |
| 3644 | DEBUG_PRINT ("\nCompiled pattern: \n"); | 2668 | DEBUG_PRINT ("\nCompiled pattern: \n"); |
| 3645 | print_compiled_pattern (bufp); | 2669 | print_compiled_pattern (bufp); |
| 3646 | } | 2670 | } |
| 3647 | debug--; | 2671 | regex_emacs_debug--; |
| 3648 | #endif /* DEBUG */ | 2672 | #endif |
| 3649 | |||
| 3650 | #ifndef MATCH_MAY_ALLOCATE | ||
| 3651 | /* Initialize the failure stack to the largest possible stack. This | ||
| 3652 | isn't necessary unless we're trying to avoid calling alloca in | ||
| 3653 | the search and match routines. */ | ||
| 3654 | { | ||
| 3655 | int num_regs = bufp->re_nsub + 1; | ||
| 3656 | |||
| 3657 | if (fail_stack.size < emacs_re_max_failures * TYPICAL_FAILURE_SIZE) | ||
| 3658 | { | ||
| 3659 | fail_stack.size = emacs_re_max_failures * TYPICAL_FAILURE_SIZE; | ||
| 3660 | falk_stack.stack = realloc (fail_stack.stack, | ||
| 3661 | fail_stack.size * sizeof *falk_stack.stack); | ||
| 3662 | } | ||
| 3663 | |||
| 3664 | regex_grow_registers (num_regs); | ||
| 3665 | } | ||
| 3666 | #endif /* not MATCH_MAY_ALLOCATE */ | ||
| 3667 | 2673 | ||
| 3668 | FREE_STACK_RETURN (REG_NOERROR); | 2674 | FREE_STACK_RETURN (REG_NOERROR); |
| 3669 | 2675 | ||
| 3670 | #ifdef emacs | ||
| 3671 | # undef syntax | ||
| 3672 | #else | ||
| 3673 | # undef posix_backtracking | ||
| 3674 | #endif | ||
| 3675 | } /* regex_compile */ | 2676 | } /* regex_compile */ |
| 3676 | 2677 | ||
| 3677 | /* Subroutines for `regex_compile'. */ | 2678 | /* Subroutines for 'regex_compile'. */ |
| 3678 | 2679 | ||
| 3679 | /* Store OP at LOC followed by two-byte integer parameter ARG. */ | 2680 | /* Store OP at LOC followed by two-byte integer parameter ARG. */ |
| 3680 | 2681 | ||
| @@ -3686,7 +2687,7 @@ store_op1 (re_opcode_t op, unsigned char *loc, int arg) | |||
| 3686 | } | 2687 | } |
| 3687 | 2688 | ||
| 3688 | 2689 | ||
| 3689 | /* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */ | 2690 | /* Like 'store_op1', but for two two-byte parameters ARG1 and ARG2. */ |
| 3690 | 2691 | ||
| 3691 | static void | 2692 | static void |
| 3692 | store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2) | 2693 | store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2) |
| @@ -3713,10 +2714,11 @@ insert_op1 (re_opcode_t op, unsigned char *loc, int arg, unsigned char *end) | |||
| 3713 | } | 2714 | } |
| 3714 | 2715 | ||
| 3715 | 2716 | ||
| 3716 | /* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */ | 2717 | /* Like 'insert_op1', but for two two-byte parameters ARG1 and ARG2. */ |
| 3717 | 2718 | ||
| 3718 | static void | 2719 | static void |
| 3719 | insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2, unsigned char *end) | 2720 | insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2, |
| 2721 | unsigned char *end) | ||
| 3720 | { | 2722 | { |
| 3721 | register unsigned char *pfrom = end; | 2723 | register unsigned char *pfrom = end; |
| 3722 | register unsigned char *pto = end + 5; | 2724 | register unsigned char *pto = end + 5; |
| @@ -3729,74 +2731,60 @@ insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2, unsigned cha | |||
| 3729 | 2731 | ||
| 3730 | 2732 | ||
| 3731 | /* P points to just after a ^ in PATTERN. Return true if that ^ comes | 2733 | /* P points to just after a ^ in PATTERN. Return true if that ^ comes |
| 3732 | after an alternative or a begin-subexpression. We assume there is at | 2734 | after an alternative or a begin-subexpression. Assume there is at |
| 3733 | least one character before the ^. */ | 2735 | least one character before the ^. */ |
| 3734 | 2736 | ||
| 3735 | static boolean | 2737 | static bool |
| 3736 | at_begline_loc_p (re_char *pattern, re_char *p, reg_syntax_t syntax) | 2738 | at_begline_loc_p (re_char *pattern, re_char *p) |
| 3737 | { | 2739 | { |
| 3738 | re_char *prev = p - 2; | 2740 | re_char *prev = p - 2; |
| 3739 | boolean odd_backslashes; | ||
| 3740 | |||
| 3741 | /* After a subexpression? */ | ||
| 3742 | if (*prev == '(') | ||
| 3743 | odd_backslashes = (syntax & RE_NO_BK_PARENS) == 0; | ||
| 3744 | 2741 | ||
| 3745 | /* After an alternative? */ | 2742 | switch (*prev) |
| 3746 | else if (*prev == '|') | ||
| 3747 | odd_backslashes = (syntax & RE_NO_BK_VBAR) == 0; | ||
| 3748 | |||
| 3749 | /* After a shy subexpression? */ | ||
| 3750 | else if (*prev == ':' && (syntax & RE_SHY_GROUPS)) | ||
| 3751 | { | 2743 | { |
| 2744 | case '(': /* After a subexpression. */ | ||
| 2745 | case '|': /* After an alternative. */ | ||
| 2746 | break; | ||
| 2747 | |||
| 2748 | case ':': /* After a shy subexpression. */ | ||
| 3752 | /* Skip over optional regnum. */ | 2749 | /* Skip over optional regnum. */ |
| 3753 | while (prev - 1 >= pattern && prev[-1] >= '0' && prev[-1] <= '9') | 2750 | while (prev > pattern && '0' <= prev[-1] && prev[-1] <= '9') |
| 3754 | --prev; | 2751 | --prev; |
| 3755 | 2752 | ||
| 3756 | if (!(prev - 2 >= pattern | 2753 | if (! (prev > pattern + 1 && prev[-1] == '?' && prev[-2] == '(')) |
| 3757 | && prev[-1] == '?' && prev[-2] == '(')) | ||
| 3758 | return false; | 2754 | return false; |
| 3759 | prev -= 2; | 2755 | prev -= 2; |
| 3760 | odd_backslashes = (syntax & RE_NO_BK_PARENS) == 0; | 2756 | break; |
| 2757 | |||
| 2758 | default: | ||
| 2759 | return false; | ||
| 3761 | } | 2760 | } |
| 3762 | else | ||
| 3763 | return false; | ||
| 3764 | 2761 | ||
| 3765 | /* Count the number of preceding backslashes. */ | 2762 | /* Count the number of preceding backslashes. */ |
| 3766 | p = prev; | 2763 | p = prev; |
| 3767 | while (prev - 1 >= pattern && prev[-1] == '\\') | 2764 | while (prev > pattern && prev[-1] == '\\') |
| 3768 | --prev; | 2765 | --prev; |
| 3769 | return (p - prev) & odd_backslashes; | 2766 | return (p - prev) & 1; |
| 3770 | } | 2767 | } |
| 3771 | 2768 | ||
| 3772 | 2769 | ||
| 3773 | /* The dual of at_begline_loc_p. This one is for $. We assume there is | 2770 | /* The dual of at_begline_loc_p. This one is for $. Assume there is |
| 3774 | at least one character after the $, i.e., `P < PEND'. */ | 2771 | at least one character after the $, i.e., 'P < PEND'. */ |
| 3775 | 2772 | ||
| 3776 | static boolean | 2773 | static bool |
| 3777 | at_endline_loc_p (re_char *p, re_char *pend, reg_syntax_t syntax) | 2774 | at_endline_loc_p (re_char *p, re_char *pend) |
| 3778 | { | 2775 | { |
| 3779 | re_char *next = p; | 2776 | /* Before a subexpression or an alternative? */ |
| 3780 | boolean next_backslash = *next == '\\'; | 2777 | return *p == '\\' && p + 1 < pend && (p[1] == ')' || p[1] == '|'); |
| 3781 | re_char *next_next = p + 1 < pend ? p + 1 : 0; | ||
| 3782 | |||
| 3783 | return | ||
| 3784 | /* Before a subexpression? */ | ||
| 3785 | (syntax & RE_NO_BK_PARENS ? *next == ')' | ||
| 3786 | : next_backslash && next_next && *next_next == ')') | ||
| 3787 | /* Before an alternative? */ | ||
| 3788 | || (syntax & RE_NO_BK_VBAR ? *next == '|' | ||
| 3789 | : next_backslash && next_next && *next_next == '|'); | ||
| 3790 | } | 2778 | } |
| 3791 | 2779 | ||
| 3792 | 2780 | ||
| 3793 | /* Returns true if REGNUM is in one of COMPILE_STACK's elements and | 2781 | /* Returns true if REGNUM is in one of COMPILE_STACK's elements and |
| 3794 | false if it's not. */ | 2782 | false if it's not. */ |
| 3795 | 2783 | ||
| 3796 | static boolean | 2784 | static bool |
| 3797 | group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum) | 2785 | group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum) |
| 3798 | { | 2786 | { |
| 3799 | ssize_t this_element; | 2787 | ptrdiff_t this_element; |
| 3800 | 2788 | ||
| 3801 | for (this_element = compile_stack.avail - 1; | 2789 | for (this_element = compile_stack.avail - 1; |
| 3802 | this_element >= 0; | 2790 | this_element >= 0; |
| @@ -3822,35 +2810,35 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 3822 | const int multibyte) | 2810 | const int multibyte) |
| 3823 | { | 2811 | { |
| 3824 | int j, k; | 2812 | int j, k; |
| 3825 | boolean not; | 2813 | bool not; |
| 3826 | 2814 | ||
| 3827 | /* If all elements for base leading-codes in fastmap is set, this | 2815 | /* If all elements for base leading-codes in fastmap is set, this |
| 3828 | flag is set true. */ | 2816 | flag is set true. */ |
| 3829 | boolean match_any_multibyte_characters = false; | 2817 | bool match_any_multibyte_characters = false; |
| 3830 | 2818 | ||
| 3831 | assert (p); | 2819 | eassert (p); |
| 3832 | 2820 | ||
| 3833 | /* The loop below works as follows: | 2821 | /* The loop below works as follows: |
| 3834 | - It has a working-list kept in the PATTERN_STACK and which basically | 2822 | - It has a working-list kept in the PATTERN_STACK and which basically |
| 3835 | starts by only containing a pointer to the first operation. | 2823 | starts by only containing a pointer to the first operation. |
| 3836 | - If the opcode we're looking at is a match against some set of | 2824 | - If the opcode we're looking at is a match against some set of |
| 3837 | chars, then we add those chars to the fastmap and go on to the | 2825 | chars, then we add those chars to the fastmap and go on to the |
| 3838 | next work element from the worklist (done via `break'). | 2826 | next work element from the worklist (done via 'break'). |
| 3839 | - If the opcode is a control operator on the other hand, we either | 2827 | - If the opcode is a control operator on the other hand, we either |
| 3840 | ignore it (if it's meaningless at this point, such as `start_memory') | 2828 | ignore it (if it's meaningless at this point, such as 'start_memory') |
| 3841 | or execute it (if it's a jump). If the jump has several destinations | 2829 | or execute it (if it's a jump). If the jump has several destinations |
| 3842 | (i.e. `on_failure_jump'), then we push the other destination onto the | 2830 | (i.e. 'on_failure_jump'), then we push the other destination onto the |
| 3843 | worklist. | 2831 | worklist. |
| 3844 | We guarantee termination by ignoring backward jumps (more or less), | 2832 | We guarantee termination by ignoring backward jumps (more or less), |
| 3845 | so that `p' is monotonically increasing. More to the point, we | 2833 | so that P is monotonically increasing. More to the point, we |
| 3846 | never set `p' (or push) anything `<= p1'. */ | 2834 | never set P (or push) anything '<= p1'. */ |
| 3847 | 2835 | ||
| 3848 | while (p < pend) | 2836 | while (p < pend) |
| 3849 | { | 2837 | { |
| 3850 | /* `p1' is used as a marker of how far back a `on_failure_jump' | 2838 | /* P1 is used as a marker of how far back a 'on_failure_jump' |
| 3851 | can go without being ignored. It is normally equal to `p' | 2839 | can go without being ignored. It is normally equal to P |
| 3852 | (which prevents any backward `on_failure_jump') except right | 2840 | (which prevents any backward 'on_failure_jump') except right |
| 3853 | after a plain `jump', to allow patterns such as: | 2841 | after a plain 'jump', to allow patterns such as: |
| 3854 | 0: jump 10 | 2842 | 0: jump 10 |
| 3855 | 3..9: <body> | 2843 | 3..9: <body> |
| 3856 | 10: on_failure_jump 3 | 2844 | 10: on_failure_jump 3 |
| @@ -3872,7 +2860,7 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 3872 | 2860 | ||
| 3873 | 2861 | ||
| 3874 | /* Following are the cases which match a character. These end | 2862 | /* Following are the cases which match a character. These end |
| 3875 | with `break'. */ | 2863 | with 'break'. */ |
| 3876 | 2864 | ||
| 3877 | case exactn: | 2865 | case exactn: |
| 3878 | if (fastmap) | 2866 | if (fastmap) |
| @@ -3919,7 +2907,6 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 3919 | if (!!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) ^ not) | 2907 | if (!!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) ^ not) |
| 3920 | fastmap[j] = 1; | 2908 | fastmap[j] = 1; |
| 3921 | 2909 | ||
| 3922 | #ifdef emacs | ||
| 3923 | if (/* Any leading code can possibly start a character | 2910 | if (/* Any leading code can possibly start a character |
| 3924 | which doesn't match the specified set of characters. */ | 2911 | which doesn't match the specified set of characters. */ |
| 3925 | not | 2912 | not |
| @@ -3947,7 +2934,7 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 3947 | int c, count; | 2934 | int c, count; |
| 3948 | unsigned char lc1, lc2; | 2935 | unsigned char lc1, lc2; |
| 3949 | 2936 | ||
| 3950 | /* Make P points the range table. `+ 2' is to skip flag | 2937 | /* Make P points the range table. '+ 2' is to skip flag |
| 3951 | bits for a character class. */ | 2938 | bits for a character class. */ |
| 3952 | p += CHARSET_BITMAP_SIZE (&p[-2]) + 2; | 2939 | p += CHARSET_BITMAP_SIZE (&p[-2]) + 2; |
| 3953 | 2940 | ||
| @@ -3965,20 +2952,11 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 3965 | fastmap[j] = 1; | 2952 | fastmap[j] = 1; |
| 3966 | } | 2953 | } |
| 3967 | } | 2954 | } |
| 3968 | #endif | ||
| 3969 | break; | 2955 | break; |
| 3970 | 2956 | ||
| 3971 | case syntaxspec: | 2957 | case syntaxspec: |
| 3972 | case notsyntaxspec: | 2958 | case notsyntaxspec: |
| 3973 | if (!fastmap) break; | 2959 | if (!fastmap) break; |
| 3974 | #ifndef emacs | ||
| 3975 | not = (re_opcode_t)p[-1] == notsyntaxspec; | ||
| 3976 | k = *p++; | ||
| 3977 | for (j = 0; j < (1 << BYTEWIDTH); j++) | ||
| 3978 | if ((SYNTAX (j) == (enum syntaxcode) k) ^ not) | ||
| 3979 | fastmap[j] = 1; | ||
| 3980 | break; | ||
| 3981 | #else /* emacs */ | ||
| 3982 | /* This match depends on text properties. These end with | 2960 | /* This match depends on text properties. These end with |
| 3983 | aborting optimizations. */ | 2961 | aborting optimizations. */ |
| 3984 | return -1; | 2962 | return -1; |
| @@ -4004,10 +2982,9 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4004 | break; | 2982 | break; |
| 4005 | 2983 | ||
| 4006 | /* All cases after this match the empty string. These end with | 2984 | /* All cases after this match the empty string. These end with |
| 4007 | `continue'. */ | 2985 | 'continue'. */ |
| 4008 | 2986 | ||
| 4009 | case at_dot: | 2987 | case at_dot: |
| 4010 | #endif /* !emacs */ | ||
| 4011 | case no_op: | 2988 | case no_op: |
| 4012 | case begline: | 2989 | case begline: |
| 4013 | case endline: | 2990 | case endline: |
| @@ -4026,7 +3003,7 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4026 | EXTRACT_NUMBER_AND_INCR (j, p); | 3003 | EXTRACT_NUMBER_AND_INCR (j, p); |
| 4027 | if (j < 0) | 3004 | if (j < 0) |
| 4028 | /* Backward jumps can only go back to code that we've already | 3005 | /* Backward jumps can only go back to code that we've already |
| 4029 | visited. `re_compile' should make sure this is true. */ | 3006 | visited. 're_compile' should make sure this is true. */ |
| 4030 | break; | 3007 | break; |
| 4031 | p += j; | 3008 | p += j; |
| 4032 | switch (*p) | 3009 | switch (*p) |
| @@ -4041,7 +3018,7 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4041 | default: | 3018 | default: |
| 4042 | continue; | 3019 | continue; |
| 4043 | }; | 3020 | }; |
| 4044 | /* Keep `p1' to allow the `on_failure_jump' we are jumping to | 3021 | /* Keep P1 to allow the 'on_failure_jump' we are jumping to |
| 4045 | to jump back to "just after here". */ | 3022 | to jump back to "just after here". */ |
| 4046 | FALLTHROUGH; | 3023 | FALLTHROUGH; |
| 4047 | case on_failure_jump: | 3024 | case on_failure_jump: |
| @@ -4065,7 +3042,7 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4065 | 3042 | ||
| 4066 | case jump_n: | 3043 | case jump_n: |
| 4067 | /* This code simply does not properly handle forward jump_n. */ | 3044 | /* This code simply does not properly handle forward jump_n. */ |
| 4068 | DEBUG_STATEMENT (EXTRACT_NUMBER (j, p); assert (j < 0)); | 3045 | DEBUG_STATEMENT (EXTRACT_NUMBER (j, p); eassert (j < 0)); |
| 4069 | p += 4; | 3046 | p += 4; |
| 4070 | /* jump_n can either jump or fall through. The (backward) jump | 3047 | /* jump_n can either jump or fall through. The (backward) jump |
| 4071 | case has already been handled, so we only need to look at the | 3048 | case has already been handled, so we only need to look at the |
| @@ -4074,7 +3051,7 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4074 | 3051 | ||
| 4075 | case succeed_n: | 3052 | case succeed_n: |
| 4076 | /* If N == 0, it should be an on_failure_jump_loop instead. */ | 3053 | /* If N == 0, it should be an on_failure_jump_loop instead. */ |
| 4077 | DEBUG_STATEMENT (EXTRACT_NUMBER (j, p + 2); assert (j > 0)); | 3054 | DEBUG_STATEMENT (EXTRACT_NUMBER (j, p + 2); eassert (j > 0)); |
| 4078 | p += 4; | 3055 | p += 4; |
| 4079 | /* We only care about one iteration of the loop, so we don't | 3056 | /* We only care about one iteration of the loop, so we don't |
| 4080 | need to consider the case where this behaves like an | 3057 | need to consider the case where this behaves like an |
| @@ -4108,8 +3085,8 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4108 | 3085 | ||
| 4109 | } /* analyze_first */ | 3086 | } /* analyze_first */ |
| 4110 | 3087 | ||
| 4111 | /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in | 3088 | /* Compute a fastmap for the compiled pattern in BUFP. |
| 4112 | BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible | 3089 | A fastmap records which of the (1 << BYTEWIDTH) possible |
| 4113 | characters can start a string that matches the pattern. This fastmap | 3090 | characters can start a string that matches the pattern. This fastmap |
| 4114 | is used by re_search to skip quickly over impossible starting points. | 3091 | is used by re_search to skip quickly over impossible starting points. |
| 4115 | 3092 | ||
| @@ -4120,18 +3097,16 @@ analyze_first (re_char *p, re_char *pend, char *fastmap, | |||
| 4120 | The caller must supply the address of a (1 << BYTEWIDTH)-byte data | 3097 | The caller must supply the address of a (1 << BYTEWIDTH)-byte data |
| 4121 | area as BUFP->fastmap. | 3098 | area as BUFP->fastmap. |
| 4122 | 3099 | ||
| 4123 | We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in | 3100 | Set the 'fastmap', 'fastmap_accurate', and 'can_be_null' fields in |
| 4124 | the pattern buffer. | 3101 | the pattern buffer. */ |
| 4125 | |||
| 4126 | Returns 0 if we succeed, -2 if an internal error. */ | ||
| 4127 | 3102 | ||
| 4128 | int | 3103 | static void |
| 4129 | re_compile_fastmap (struct re_pattern_buffer *bufp) | 3104 | re_compile_fastmap (struct re_pattern_buffer *bufp) |
| 4130 | { | 3105 | { |
| 4131 | char *fastmap = bufp->fastmap; | 3106 | char *fastmap = bufp->fastmap; |
| 4132 | int analysis; | 3107 | int analysis; |
| 4133 | 3108 | ||
| 4134 | assert (fastmap && bufp->buffer); | 3109 | eassert (fastmap && bufp->buffer); |
| 4135 | 3110 | ||
| 4136 | memset (fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */ | 3111 | memset (fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */ |
| 4137 | bufp->fastmap_accurate = 1; /* It will be when we're done. */ | 3112 | bufp->fastmap_accurate = 1; /* It will be when we're done. */ |
| @@ -4139,14 +3114,13 @@ re_compile_fastmap (struct re_pattern_buffer *bufp) | |||
| 4139 | analysis = analyze_first (bufp->buffer, bufp->buffer + bufp->used, | 3114 | analysis = analyze_first (bufp->buffer, bufp->buffer + bufp->used, |
| 4140 | fastmap, RE_MULTIBYTE_P (bufp)); | 3115 | fastmap, RE_MULTIBYTE_P (bufp)); |
| 4141 | bufp->can_be_null = (analysis != 0); | 3116 | bufp->can_be_null = (analysis != 0); |
| 4142 | return 0; | ||
| 4143 | } /* re_compile_fastmap */ | 3117 | } /* re_compile_fastmap */ |
| 4144 | 3118 | ||
| 4145 | /* Set REGS to hold NUM_REGS registers, storing them in STARTS and | 3119 | /* Set REGS to hold NUM_REGS registers, storing them in STARTS and |
| 4146 | ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use | 3120 | ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use |
| 4147 | this memory for recording register information. STARTS and ENDS | 3121 | this memory for recording register information. STARTS and ENDS |
| 4148 | must be allocated using the malloc library routine, and must each | 3122 | must be allocated using the malloc library routine, and must each |
| 4149 | be at least NUM_REGS * sizeof (regoff_t) bytes long. | 3123 | be at least NUM_REGS * sizeof (ptrdiff_t) bytes long. |
| 4150 | 3124 | ||
| 4151 | If NUM_REGS == 0, then subsequent matches should allocate their own | 3125 | If NUM_REGS == 0, then subsequent matches should allocate their own |
| 4152 | register data. | 3126 | register data. |
| @@ -4156,7 +3130,8 @@ re_compile_fastmap (struct re_pattern_buffer *bufp) | |||
| 4156 | freeing the old data. */ | 3130 | freeing the old data. */ |
| 4157 | 3131 | ||
| 4158 | void | 3132 | void |
| 4159 | re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, unsigned int num_regs, regoff_t *starts, regoff_t *ends) | 3133 | re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, |
| 3134 | unsigned int num_regs, ptrdiff_t *starts, ptrdiff_t *ends) | ||
| 4160 | { | 3135 | { |
| 4161 | if (num_regs) | 3136 | if (num_regs) |
| 4162 | { | 3137 | { |
| @@ -4172,21 +3147,19 @@ re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, uns | |||
| 4172 | regs->start = regs->end = 0; | 3147 | regs->start = regs->end = 0; |
| 4173 | } | 3148 | } |
| 4174 | } | 3149 | } |
| 4175 | WEAK_ALIAS (__re_set_registers, re_set_registers) | ||
| 4176 | 3150 | ||
| 4177 | /* Searching routines. */ | 3151 | /* Searching routines. */ |
| 4178 | 3152 | ||
| 4179 | /* Like re_search_2, below, but only one string is specified, and | 3153 | /* Like re_search_2, below, but only one string is specified, and |
| 4180 | doesn't let you say where to stop matching. */ | 3154 | doesn't let you say where to stop matching. */ |
| 4181 | 3155 | ||
| 4182 | regoff_t | 3156 | ptrdiff_t |
| 4183 | re_search (struct re_pattern_buffer *bufp, const char *string, size_t size, | 3157 | re_search (struct re_pattern_buffer *bufp, const char *string, size_t size, |
| 4184 | ssize_t startpos, ssize_t range, struct re_registers *regs) | 3158 | ptrdiff_t startpos, ptrdiff_t range, struct re_registers *regs) |
| 4185 | { | 3159 | { |
| 4186 | return re_search_2 (bufp, NULL, 0, string, size, startpos, range, | 3160 | return re_search_2 (bufp, NULL, 0, string, size, startpos, range, |
| 4187 | regs, size); | 3161 | regs, size); |
| 4188 | } | 3162 | } |
| 4189 | WEAK_ALIAS (__re_search, re_search) | ||
| 4190 | 3163 | ||
| 4191 | /* Head address of virtual concatenation of string. */ | 3164 | /* Head address of virtual concatenation of string. */ |
| 4192 | #define HEAD_ADDR_VSTRING(P) \ | 3165 | #define HEAD_ADDR_VSTRING(P) \ |
| @@ -4213,25 +3186,26 @@ WEAK_ALIAS (__re_search, re_search) | |||
| 4213 | Do not consider matching one past the index STOP in the virtual | 3186 | Do not consider matching one past the index STOP in the virtual |
| 4214 | concatenation of STRING1 and STRING2. | 3187 | concatenation of STRING1 and STRING2. |
| 4215 | 3188 | ||
| 4216 | We return either the position in the strings at which the match was | 3189 | Return either the position in the strings at which the match was |
| 4217 | found, -1 if no match, or -2 if error (such as failure | 3190 | found, -1 if no match, or -2 if error (such as failure |
| 4218 | stack overflow). */ | 3191 | stack overflow). */ |
| 4219 | 3192 | ||
| 4220 | regoff_t | 3193 | ptrdiff_t |
| 4221 | re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | 3194 | re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, |
| 4222 | const char *str2, size_t size2, ssize_t startpos, ssize_t range, | 3195 | const char *str2, size_t size2, |
| 4223 | struct re_registers *regs, ssize_t stop) | 3196 | ptrdiff_t startpos, ptrdiff_t range, |
| 3197 | struct re_registers *regs, ptrdiff_t stop) | ||
| 4224 | { | 3198 | { |
| 4225 | regoff_t val; | 3199 | ptrdiff_t val; |
| 4226 | re_char *string1 = (re_char *) str1; | 3200 | re_char *string1 = (re_char *) str1; |
| 4227 | re_char *string2 = (re_char *) str2; | 3201 | re_char *string2 = (re_char *) str2; |
| 4228 | register char *fastmap = bufp->fastmap; | 3202 | char *fastmap = bufp->fastmap; |
| 4229 | register RE_TRANSLATE_TYPE translate = bufp->translate; | 3203 | Lisp_Object translate = bufp->translate; |
| 4230 | size_t total_size = size1 + size2; | 3204 | size_t total_size = size1 + size2; |
| 4231 | ssize_t endpos = startpos + range; | 3205 | ptrdiff_t endpos = startpos + range; |
| 4232 | boolean anchored_start; | 3206 | bool anchored_start; |
| 4233 | /* Nonzero if we are searching multibyte string. */ | 3207 | /* Nonzero if we are searching multibyte string. */ |
| 4234 | const boolean multibyte = RE_TARGET_MULTIBYTE_P (bufp); | 3208 | bool multibyte = RE_TARGET_MULTIBYTE_P (bufp); |
| 4235 | 3209 | ||
| 4236 | /* Check for out-of-range STARTPOS. */ | 3210 | /* Check for out-of-range STARTPOS. */ |
| 4237 | if (startpos < 0 || startpos > total_size) | 3211 | if (startpos < 0 || startpos > total_size) |
| @@ -4255,7 +3229,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4255 | range = 0; | 3229 | range = 0; |
| 4256 | } | 3230 | } |
| 4257 | 3231 | ||
| 4258 | #ifdef emacs | ||
| 4259 | /* In a forward search for something that starts with \=. | 3232 | /* In a forward search for something that starts with \=. |
| 4260 | don't keep searching past point. */ | 3233 | don't keep searching past point. */ |
| 4261 | if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0) | 3234 | if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0) |
| @@ -4264,7 +3237,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4264 | if (range < 0) | 3237 | if (range < 0) |
| 4265 | return -1; | 3238 | return -1; |
| 4266 | } | 3239 | } |
| 4267 | #endif /* emacs */ | ||
| 4268 | 3240 | ||
| 4269 | /* Update the fastmap now if not correct already. */ | 3241 | /* Update the fastmap now if not correct already. */ |
| 4270 | if (fastmap && !bufp->fastmap_accurate) | 3242 | if (fastmap && !bufp->fastmap_accurate) |
| @@ -4273,21 +3245,19 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4273 | /* See whether the pattern is anchored. */ | 3245 | /* See whether the pattern is anchored. */ |
| 4274 | anchored_start = (bufp->buffer[0] == begline); | 3246 | anchored_start = (bufp->buffer[0] == begline); |
| 4275 | 3247 | ||
| 4276 | #ifdef emacs | ||
| 4277 | gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ | 3248 | gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ |
| 4278 | { | 3249 | { |
| 4279 | ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (startpos)); | 3250 | ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (startpos)); |
| 4280 | 3251 | ||
| 4281 | SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); | 3252 | SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); |
| 4282 | } | 3253 | } |
| 4283 | #endif | ||
| 4284 | 3254 | ||
| 4285 | /* Loop through the string, looking for a place to start matching. */ | 3255 | /* Loop through the string, looking for a place to start matching. */ |
| 4286 | for (;;) | 3256 | for (;;) |
| 4287 | { | 3257 | { |
| 4288 | /* If the pattern is anchored, | 3258 | /* If the pattern is anchored, |
| 4289 | skip quickly past places we cannot match. | 3259 | skip quickly past places we cannot match. |
| 4290 | We don't bother to treat startpos == 0 specially | 3260 | Don't bother to treat startpos == 0 specially |
| 4291 | because that case doesn't repeat. */ | 3261 | because that case doesn't repeat. */ |
| 4292 | if (anchored_start && startpos > 0) | 3262 | if (anchored_start && startpos > 0) |
| 4293 | { | 3263 | { |
| @@ -4303,21 +3273,21 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4303 | the first null string. */ | 3273 | the first null string. */ |
| 4304 | if (fastmap && startpos < total_size && !bufp->can_be_null) | 3274 | if (fastmap && startpos < total_size && !bufp->can_be_null) |
| 4305 | { | 3275 | { |
| 4306 | register re_char *d; | 3276 | re_char *d; |
| 4307 | register re_wchar_t buf_ch; | 3277 | int buf_ch; |
| 4308 | 3278 | ||
| 4309 | d = POS_ADDR_VSTRING (startpos); | 3279 | d = POS_ADDR_VSTRING (startpos); |
| 4310 | 3280 | ||
| 4311 | if (range > 0) /* Searching forwards. */ | 3281 | if (range > 0) /* Searching forwards. */ |
| 4312 | { | 3282 | { |
| 4313 | ssize_t irange = range, lim = 0; | 3283 | ptrdiff_t irange = range, lim = 0; |
| 4314 | 3284 | ||
| 4315 | if (startpos < size1 && startpos + range >= size1) | 3285 | if (startpos < size1 && startpos + range >= size1) |
| 4316 | lim = range - (size1 - startpos); | 3286 | lim = range - (size1 - startpos); |
| 4317 | 3287 | ||
| 4318 | /* Written out as an if-else to avoid testing `translate' | 3288 | /* Written out as an if-else to avoid testing 'translate' |
| 4319 | inside the loop. */ | 3289 | inside the loop. */ |
| 4320 | if (RE_TRANSLATE_P (translate)) | 3290 | if (!NILP (translate)) |
| 4321 | { | 3291 | { |
| 4322 | if (multibyte) | 3292 | if (multibyte) |
| 4323 | while (range > lim) | 3293 | while (range > lim) |
| @@ -4335,11 +3305,9 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4335 | else | 3305 | else |
| 4336 | while (range > lim) | 3306 | while (range > lim) |
| 4337 | { | 3307 | { |
| 4338 | register re_wchar_t ch, translated; | ||
| 4339 | |||
| 4340 | buf_ch = *d; | 3308 | buf_ch = *d; |
| 4341 | ch = RE_CHAR_TO_MULTIBYTE (buf_ch); | 3309 | int ch = RE_CHAR_TO_MULTIBYTE (buf_ch); |
| 4342 | translated = RE_TRANSLATE (translate, ch); | 3310 | int translated = RE_TRANSLATE (translate, ch); |
| 4343 | if (translated != ch | 3311 | if (translated != ch |
| 4344 | && (ch = RE_CHAR_TO_UNIBYTE (translated)) >= 0) | 3312 | && (ch = RE_CHAR_TO_UNIBYTE (translated)) >= 0) |
| 4345 | buf_ch = ch; | 3313 | buf_ch = ch; |
| @@ -4382,11 +3350,9 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4382 | } | 3350 | } |
| 4383 | else | 3351 | else |
| 4384 | { | 3352 | { |
| 4385 | register re_wchar_t ch, translated; | ||
| 4386 | |||
| 4387 | buf_ch = *d; | 3353 | buf_ch = *d; |
| 4388 | ch = RE_CHAR_TO_MULTIBYTE (buf_ch); | 3354 | int ch = RE_CHAR_TO_MULTIBYTE (buf_ch); |
| 4389 | translated = TRANSLATE (ch); | 3355 | int translated = TRANSLATE (ch); |
| 4390 | if (translated != ch | 3356 | if (translated != ch |
| 4391 | && (ch = RE_CHAR_TO_UNIBYTE (translated)) >= 0) | 3357 | && (ch = RE_CHAR_TO_UNIBYTE (translated)) >= 0) |
| 4392 | buf_ch = ch; | 3358 | buf_ch = ch; |
| @@ -4456,17 +3422,16 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4456 | } | 3422 | } |
| 4457 | return -1; | 3423 | return -1; |
| 4458 | } /* re_search_2 */ | 3424 | } /* re_search_2 */ |
| 4459 | WEAK_ALIAS (__re_search_2, re_search_2) | ||
| 4460 | 3425 | ||
| 4461 | /* Declarations and macros for re_match_2. */ | 3426 | /* Declarations and macros for re_match_2. */ |
| 4462 | 3427 | ||
| 4463 | static int bcmp_translate (re_char *s1, re_char *s2, | 3428 | static int bcmp_translate (re_char *s1, re_char *s2, |
| 4464 | register ssize_t len, | 3429 | ptrdiff_t len, |
| 4465 | RE_TRANSLATE_TYPE translate, | 3430 | Lisp_Object translate, |
| 4466 | const int multibyte); | 3431 | const int multibyte); |
| 4467 | 3432 | ||
| 4468 | /* This converts PTR, a pointer into one of the search strings `string1' | 3433 | /* This converts PTR, a pointer into one of the search strings 'string1' |
| 4469 | and `string2' into an offset from the beginning of that string. */ | 3434 | and 'string2' into an offset from the beginning of that string. */ |
| 4470 | #define POINTER_TO_OFFSET(ptr) \ | 3435 | #define POINTER_TO_OFFSET(ptr) \ |
| 4471 | (FIRST_STRING_P (ptr) \ | 3436 | (FIRST_STRING_P (ptr) \ |
| 4472 | ? (ptr) - string1 \ | 3437 | ? (ptr) - string1 \ |
| @@ -4490,7 +3455,7 @@ static int bcmp_translate (re_char *s1, re_char *s2, | |||
| 4490 | /* Call before fetching a char with *d if you already checked other limits. | 3455 | /* Call before fetching a char with *d if you already checked other limits. |
| 4491 | This is meant for use in lookahead operations like wordend, etc.. | 3456 | This is meant for use in lookahead operations like wordend, etc.. |
| 4492 | where we might need to look at parts of the string that might be | 3457 | where we might need to look at parts of the string that might be |
| 4493 | outside of the LIMITs (i.e past `stop'). */ | 3458 | outside of the LIMITs (i.e past 'stop'). */ |
| 4494 | #define PREFETCH_NOLIMIT() \ | 3459 | #define PREFETCH_NOLIMIT() \ |
| 4495 | if (d == end1) \ | 3460 | if (d == end1) \ |
| 4496 | { \ | 3461 | { \ |
| @@ -4499,7 +3464,7 @@ static int bcmp_translate (re_char *s1, re_char *s2, | |||
| 4499 | } \ | 3464 | } \ |
| 4500 | 3465 | ||
| 4501 | /* Test if at very beginning or at very end of the virtual concatenation | 3466 | /* Test if at very beginning or at very end of the virtual concatenation |
| 4502 | of `string1' and `string2'. If only one string, it's `string2'. */ | 3467 | of STRING1 and STRING2. If only one string, it's STRING2. */ |
| 4503 | #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) | 3468 | #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) |
| 4504 | #define AT_STRINGS_END(d) ((d) == end2) | 3469 | #define AT_STRINGS_END(d) ((d) == end2) |
| 4505 | 3470 | ||
| @@ -4530,29 +3495,6 @@ static int bcmp_translate (re_char *s1, re_char *s2, | |||
| 4530 | || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) | 3495 | || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) |
| 4531 | #endif | 3496 | #endif |
| 4532 | 3497 | ||
| 4533 | /* Free everything we malloc. */ | ||
| 4534 | #ifdef MATCH_MAY_ALLOCATE | ||
| 4535 | # define FREE_VAR(var) \ | ||
| 4536 | do { \ | ||
| 4537 | if (var) \ | ||
| 4538 | { \ | ||
| 4539 | REGEX_FREE (var); \ | ||
| 4540 | var = NULL; \ | ||
| 4541 | } \ | ||
| 4542 | } while (0) | ||
| 4543 | # define FREE_VARIABLES() \ | ||
| 4544 | do { \ | ||
| 4545 | REGEX_FREE_STACK (fail_stack.stack); \ | ||
| 4546 | FREE_VAR (regstart); \ | ||
| 4547 | FREE_VAR (regend); \ | ||
| 4548 | FREE_VAR (best_regstart); \ | ||
| 4549 | FREE_VAR (best_regend); \ | ||
| 4550 | REGEX_SAFE_FREE (); \ | ||
| 4551 | } while (0) | ||
| 4552 | #else | ||
| 4553 | # define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */ | ||
| 4554 | #endif /* not MATCH_MAY_ALLOCATE */ | ||
| 4555 | |||
| 4556 | 3498 | ||
| 4557 | /* Optimization routines. */ | 3499 | /* Optimization routines. */ |
| 4558 | 3500 | ||
| @@ -4585,10 +3527,8 @@ skip_one_char (re_char *p) | |||
| 4585 | 3527 | ||
| 4586 | case syntaxspec: | 3528 | case syntaxspec: |
| 4587 | case notsyntaxspec: | 3529 | case notsyntaxspec: |
| 4588 | #ifdef emacs | ||
| 4589 | case categoryspec: | 3530 | case categoryspec: |
| 4590 | case notcategoryspec: | 3531 | case notcategoryspec: |
| 4591 | #endif /* emacs */ | ||
| 4592 | p++; | 3532 | p++; |
| 4593 | break; | 3533 | break; |
| 4594 | 3534 | ||
| @@ -4622,7 +3562,7 @@ skip_noops (re_char *p, re_char *pend) | |||
| 4622 | return p; | 3562 | return p; |
| 4623 | } | 3563 | } |
| 4624 | } | 3564 | } |
| 4625 | assert (p == pend); | 3565 | eassert (p == pend); |
| 4626 | return p; | 3566 | return p; |
| 4627 | } | 3567 | } |
| 4628 | 3568 | ||
| @@ -4649,17 +3589,16 @@ execute_charset (re_char **pp, unsigned c, unsigned corig, bool unibyte) | |||
| 4649 | 3589 | ||
| 4650 | if (unibyte && c < (1 << BYTEWIDTH)) | 3590 | if (unibyte && c < (1 << BYTEWIDTH)) |
| 4651 | { /* Lookup bitmap. */ | 3591 | { /* Lookup bitmap. */ |
| 4652 | /* Cast to `unsigned' instead of `unsigned char' in | 3592 | /* Cast to 'unsigned' instead of 'unsigned char' in |
| 4653 | case the bit list is a full 32 bytes long. */ | 3593 | case the bit list is a full 32 bytes long. */ |
| 4654 | if (c < (unsigned) (CHARSET_BITMAP_SIZE (p) * BYTEWIDTH) | 3594 | if (c < (unsigned) (CHARSET_BITMAP_SIZE (p) * BYTEWIDTH) |
| 4655 | && p[2 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) | 3595 | && p[2 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
| 4656 | return !not; | 3596 | return !not; |
| 4657 | } | 3597 | } |
| 4658 | #ifdef emacs | ||
| 4659 | else if (rtp) | 3598 | else if (rtp) |
| 4660 | { | 3599 | { |
| 4661 | int class_bits = CHARSET_RANGE_TABLE_BITS (p); | 3600 | int class_bits = CHARSET_RANGE_TABLE_BITS (p); |
| 4662 | re_wchar_t range_start, range_end; | 3601 | int range_start, range_end; |
| 4663 | 3602 | ||
| 4664 | /* Sort tests by the most commonly used classes with some adjustment to which | 3603 | /* Sort tests by the most commonly used classes with some adjustment to which |
| 4665 | tests are easiest to perform. Take a look at comment in re_wctype_parse | 3604 | tests are easiest to perform. Take a look at comment in re_wctype_parse |
| @@ -4690,7 +3629,7 @@ execute_charset (re_char **pp, unsigned c, unsigned corig, bool unibyte) | |||
| 4690 | return !not; | 3629 | return !not; |
| 4691 | } | 3630 | } |
| 4692 | } | 3631 | } |
| 4693 | #endif /* emacs */ | 3632 | |
| 4694 | return not; | 3633 | return not; |
| 4695 | } | 3634 | } |
| 4696 | 3635 | ||
| @@ -4700,11 +3639,11 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4700 | re_char *p2) | 3639 | re_char *p2) |
| 4701 | { | 3640 | { |
| 4702 | re_opcode_t op2; | 3641 | re_opcode_t op2; |
| 4703 | const boolean multibyte = RE_MULTIBYTE_P (bufp); | 3642 | bool multibyte = RE_MULTIBYTE_P (bufp); |
| 4704 | unsigned char *pend = bufp->buffer + bufp->used; | 3643 | unsigned char *pend = bufp->buffer + bufp->used; |
| 4705 | 3644 | ||
| 4706 | assert (p1 >= bufp->buffer && p1 < pend | 3645 | eassert (p1 >= bufp->buffer && p1 < pend |
| 4707 | && p2 >= bufp->buffer && p2 <= pend); | 3646 | && p2 >= bufp->buffer && p2 <= pend); |
| 4708 | 3647 | ||
| 4709 | /* Skip over open/close-group commands. | 3648 | /* Skip over open/close-group commands. |
| 4710 | If what follows this loop is a ...+ construct, | 3649 | If what follows this loop is a ...+ construct, |
| @@ -4715,8 +3654,8 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4715 | is only used in the case where p1 is a simple match operator. */ | 3654 | is only used in the case where p1 is a simple match operator. */ |
| 4716 | /* p1 = skip_noops (p1, pend); */ | 3655 | /* p1 = skip_noops (p1, pend); */ |
| 4717 | 3656 | ||
| 4718 | assert (p1 >= bufp->buffer && p1 < pend | 3657 | eassert (p1 >= bufp->buffer && p1 < pend |
| 4719 | && p2 >= bufp->buffer && p2 <= pend); | 3658 | && p2 >= bufp->buffer && p2 <= pend); |
| 4720 | 3659 | ||
| 4721 | op2 = p2 == pend ? succeed : *p2; | 3660 | op2 = p2 == pend ? succeed : *p2; |
| 4722 | 3661 | ||
| @@ -4735,7 +3674,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4735 | case endline: | 3674 | case endline: |
| 4736 | case exactn: | 3675 | case exactn: |
| 4737 | { | 3676 | { |
| 4738 | register re_wchar_t c | 3677 | int c |
| 4739 | = (re_opcode_t) *p2 == endline ? '\n' | 3678 | = (re_opcode_t) *p2 == endline ? '\n' |
| 4740 | : RE_STRING_CHAR (p2 + 2, multibyte); | 3679 | : RE_STRING_CHAR (p2 + 2, multibyte); |
| 4741 | 3680 | ||
| @@ -4751,7 +3690,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4751 | else if ((re_opcode_t) *p1 == charset | 3690 | else if ((re_opcode_t) *p1 == charset |
| 4752 | || (re_opcode_t) *p1 == charset_not) | 3691 | || (re_opcode_t) *p1 == charset_not) |
| 4753 | { | 3692 | { |
| 4754 | if (!execute_charset (&p1, c, c, !multibyte || IS_REAL_ASCII (c))) | 3693 | if (!execute_charset (&p1, c, c, !multibyte || ASCII_CHAR_P (c))) |
| 4755 | { | 3694 | { |
| 4756 | DEBUG_PRINT (" No match => fast loop.\n"); | 3695 | DEBUG_PRINT (" No match => fast loop.\n"); |
| 4757 | return 1; | 3696 | return 1; |
| @@ -4778,10 +3717,10 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4778 | else if (!multibyte || !CHARSET_RANGE_TABLE_EXISTS_P (p2)) | 3717 | else if (!multibyte || !CHARSET_RANGE_TABLE_EXISTS_P (p2)) |
| 4779 | { | 3718 | { |
| 4780 | /* Now, we are sure that P2 has no range table. | 3719 | /* Now, we are sure that P2 has no range table. |
| 4781 | So, for the size of bitmap in P2, `p2[1]' is | 3720 | So, for the size of bitmap in P2, 'p2[1]' is |
| 4782 | enough. But P1 may have range table, so the | 3721 | enough. But P1 may have range table, so the |
| 4783 | size of bitmap table of P1 is extracted by | 3722 | size of bitmap table of P1 is extracted by |
| 4784 | using macro `CHARSET_BITMAP_SIZE'. | 3723 | using macro 'CHARSET_BITMAP_SIZE'. |
| 4785 | 3724 | ||
| 4786 | In a multibyte case, we know that all the character | 3725 | In a multibyte case, we know that all the character |
| 4787 | listed in P2 is ASCII. In a unibyte case, P1 has only a | 3726 | listed in P2 is ASCII. In a unibyte case, P1 has only a |
| @@ -4865,12 +3804,10 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4865 | || (re_opcode_t) *p1 == syntaxspec) | 3804 | || (re_opcode_t) *p1 == syntaxspec) |
| 4866 | && p1[1] == Sword); | 3805 | && p1[1] == Sword); |
| 4867 | 3806 | ||
| 4868 | #ifdef emacs | ||
| 4869 | case categoryspec: | 3807 | case categoryspec: |
| 4870 | return ((re_opcode_t) *p1 == notcategoryspec && p1[1] == p2[1]); | 3808 | return ((re_opcode_t) *p1 == notcategoryspec && p1[1] == p2[1]); |
| 4871 | case notcategoryspec: | 3809 | case notcategoryspec: |
| 4872 | return ((re_opcode_t) *p1 == categoryspec && p1[1] == p2[1]); | 3810 | return ((re_opcode_t) *p1 == categoryspec && p1[1] == p2[1]); |
| 4873 | #endif /* emacs */ | ||
| 4874 | 3811 | ||
| 4875 | default: | 3812 | default: |
| 4876 | ; | 3813 | ; |
| @@ -4883,61 +3820,43 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1, | |||
| 4883 | 3820 | ||
| 4884 | /* Matching routines. */ | 3821 | /* Matching routines. */ |
| 4885 | 3822 | ||
| 4886 | #ifndef emacs /* Emacs never uses this. */ | ||
| 4887 | /* re_match is like re_match_2 except it takes only a single string. */ | ||
| 4888 | |||
| 4889 | regoff_t | ||
| 4890 | re_match (struct re_pattern_buffer *bufp, const char *string, | ||
| 4891 | size_t size, ssize_t pos, struct re_registers *regs) | ||
| 4892 | { | ||
| 4893 | regoff_t result = re_match_2_internal (bufp, NULL, 0, (re_char *) string, | ||
| 4894 | size, pos, regs, size); | ||
| 4895 | return result; | ||
| 4896 | } | ||
| 4897 | WEAK_ALIAS (__re_match, re_match) | ||
| 4898 | #endif /* not emacs */ | ||
| 4899 | |||
| 4900 | /* re_match_2 matches the compiled pattern in BUFP against the | 3823 | /* re_match_2 matches the compiled pattern in BUFP against the |
| 4901 | the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 | 3824 | the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 |
| 4902 | and SIZE2, respectively). We start matching at POS, and stop | 3825 | and SIZE2, respectively). We start matching at POS, and stop |
| 4903 | matching at STOP. | 3826 | matching at STOP. |
| 4904 | 3827 | ||
| 4905 | If REGS is non-null and the `no_sub' field of BUFP is nonzero, we | 3828 | If REGS is non-null, store offsets for the substring each group |
| 4906 | store offsets for the substring each group matched in REGS. See the | 3829 | matched in REGS. |
| 4907 | documentation for exactly how many groups we fill. | ||
| 4908 | 3830 | ||
| 4909 | We return -1 if no match, -2 if an internal error (such as the | 3831 | We return -1 if no match, -2 if an internal error (such as the |
| 4910 | failure stack overflowing). Otherwise, we return the length of the | 3832 | failure stack overflowing). Otherwise, we return the length of the |
| 4911 | matched substring. */ | 3833 | matched substring. */ |
| 4912 | 3834 | ||
| 4913 | regoff_t | 3835 | ptrdiff_t |
| 4914 | re_match_2 (struct re_pattern_buffer *bufp, const char *string1, | 3836 | re_match_2 (struct re_pattern_buffer *bufp, const char *string1, |
| 4915 | size_t size1, const char *string2, size_t size2, ssize_t pos, | 3837 | size_t size1, const char *string2, size_t size2, ptrdiff_t pos, |
| 4916 | struct re_registers *regs, ssize_t stop) | 3838 | struct re_registers *regs, ptrdiff_t stop) |
| 4917 | { | 3839 | { |
| 4918 | regoff_t result; | 3840 | ptrdiff_t result; |
| 4919 | 3841 | ||
| 4920 | #ifdef emacs | 3842 | ptrdiff_t charpos; |
| 4921 | ssize_t charpos; | ||
| 4922 | gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ | 3843 | gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ |
| 4923 | charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (pos)); | 3844 | charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (pos)); |
| 4924 | SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); | 3845 | SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); |
| 4925 | #endif | ||
| 4926 | 3846 | ||
| 4927 | result = re_match_2_internal (bufp, (re_char *) string1, size1, | 3847 | result = re_match_2_internal (bufp, (re_char *) string1, size1, |
| 4928 | (re_char *) string2, size2, | 3848 | (re_char *) string2, size2, |
| 4929 | pos, regs, stop); | 3849 | pos, regs, stop); |
| 4930 | return result; | 3850 | return result; |
| 4931 | } | 3851 | } |
| 4932 | WEAK_ALIAS (__re_match_2, re_match_2) | ||
| 4933 | 3852 | ||
| 4934 | 3853 | ||
| 4935 | /* This is a separate function so that we can force an alloca cleanup | 3854 | /* This is a separate function so that we can force an alloca cleanup |
| 4936 | afterwards. */ | 3855 | afterwards. */ |
| 4937 | static regoff_t | 3856 | static ptrdiff_t |
| 4938 | re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | 3857 | re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, |
| 4939 | size_t size1, re_char *string2, size_t size2, | 3858 | size_t size1, re_char *string2, size_t size2, |
| 4940 | ssize_t pos, struct re_registers *regs, ssize_t stop) | 3859 | ptrdiff_t pos, struct re_registers *regs, ptrdiff_t stop) |
| 4941 | { | 3860 | { |
| 4942 | /* General temporaries. */ | 3861 | /* General temporaries. */ |
| 4943 | int mcnt; | 3862 | int mcnt; |
| @@ -4964,13 +3883,13 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 4964 | re_char *pend = p + bufp->used; | 3883 | re_char *pend = p + bufp->used; |
| 4965 | 3884 | ||
| 4966 | /* We use this to map every character in the string. */ | 3885 | /* We use this to map every character in the string. */ |
| 4967 | RE_TRANSLATE_TYPE translate = bufp->translate; | 3886 | Lisp_Object translate = bufp->translate; |
| 4968 | 3887 | ||
| 4969 | /* Nonzero if BUFP is setup from a multibyte regex. */ | 3888 | /* True if BUFP is setup from a multibyte regex. */ |
| 4970 | const boolean multibyte = RE_MULTIBYTE_P (bufp); | 3889 | bool multibyte = RE_MULTIBYTE_P (bufp); |
| 4971 | 3890 | ||
| 4972 | /* Nonzero if STRING1/STRING2 are multibyte. */ | 3891 | /* True if STRING1/STRING2 are multibyte. */ |
| 4973 | const boolean target_multibyte = RE_TARGET_MULTIBYTE_P (bufp); | 3892 | bool target_multibyte = RE_TARGET_MULTIBYTE_P (bufp); |
| 4974 | 3893 | ||
| 4975 | /* Failure point stack. Each place that can handle a failure further | 3894 | /* Failure point stack. Each place that can handle a failure further |
| 4976 | down the line pushes a failure point on this stack. It consists of | 3895 | down the line pushes a failure point on this stack. It consists of |
| @@ -4979,19 +3898,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 4979 | registers, and, finally, two char *'s. The first char * is where | 3898 | registers, and, finally, two char *'s. The first char * is where |
| 4980 | to resume scanning the pattern; the second one is where to resume | 3899 | to resume scanning the pattern; the second one is where to resume |
| 4981 | scanning the strings. */ | 3900 | scanning the strings. */ |
| 4982 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ | ||
| 4983 | fail_stack_type fail_stack; | 3901 | fail_stack_type fail_stack; |
| 4984 | #endif | ||
| 4985 | #ifdef DEBUG_COMPILES_ARGUMENTS | 3902 | #ifdef DEBUG_COMPILES_ARGUMENTS |
| 4986 | unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; | 3903 | unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; |
| 4987 | #endif | 3904 | #endif |
| 4988 | 3905 | ||
| 4989 | #if defined REL_ALLOC && defined REGEX_MALLOC | ||
| 4990 | /* This holds the pointer to the failure stack, when | ||
| 4991 | it is allocated relocatably. */ | ||
| 4992 | fail_stack_elt_t *failure_stack_ptr; | ||
| 4993 | #endif | ||
| 4994 | |||
| 4995 | /* We fill all the registers internally, independent of what we | 3906 | /* We fill all the registers internally, independent of what we |
| 4996 | return, for use in backreferences. The number here includes | 3907 | return, for use in backreferences. The number here includes |
| 4997 | an element for register zero. */ | 3908 | an element for register zero. */ |
| @@ -5004,24 +3915,20 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5004 | matching and the regnum-th regend points to right after where we | 3915 | matching and the regnum-th regend points to right after where we |
| 5005 | stopped matching the regnum-th subexpression. (The zeroth register | 3916 | stopped matching the regnum-th subexpression. (The zeroth register |
| 5006 | keeps track of what the whole pattern matches.) */ | 3917 | keeps track of what the whole pattern matches.) */ |
| 5007 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ | 3918 | re_char **regstart UNINIT, **regend UNINIT; |
| 5008 | re_char **regstart, **regend; | ||
| 5009 | #endif | ||
| 5010 | 3919 | ||
| 5011 | /* The following record the register info as found in the above | 3920 | /* The following record the register info as found in the above |
| 5012 | variables when we find a match better than any we've seen before. | 3921 | variables when we find a match better than any we've seen before. |
| 5013 | This happens as we backtrack through the failure points, which in | 3922 | This happens as we backtrack through the failure points, which in |
| 5014 | turn happens only if we have not yet matched the entire string. */ | 3923 | turn happens only if we have not yet matched the entire string. */ |
| 5015 | unsigned best_regs_set = false; | 3924 | unsigned best_regs_set = false; |
| 5016 | #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ | 3925 | re_char **best_regstart UNINIT, **best_regend UNINIT; |
| 5017 | re_char **best_regstart, **best_regend; | ||
| 5018 | #endif | ||
| 5019 | 3926 | ||
| 5020 | /* Logically, this is `best_regend[0]'. But we don't want to have to | 3927 | /* Logically, this is 'best_regend[0]'. But we don't want to have to |
| 5021 | allocate space for that if we're not allocating space for anything | 3928 | allocate space for that if we're not allocating space for anything |
| 5022 | else (see below). Also, we never need info about register 0 for | 3929 | else (see below). Also, we never need info about register 0 for |
| 5023 | any of the other register vectors, and it seems rather a kludge to | 3930 | any of the other register vectors, and it seems rather a kludge to |
| 5024 | treat `best_regend' differently than the rest. So we keep track of | 3931 | treat 'best_regend' differently than the rest. So we keep track of |
| 5025 | the end of the best match so far in a separate variable. We | 3932 | the end of the best match so far in a separate variable. We |
| 5026 | initialize this to NULL so that when we backtrack the first time | 3933 | initialize this to NULL so that when we backtrack the first time |
| 5027 | and need to test it, it's not garbage. */ | 3934 | and need to test it, it's not garbage. */ |
| @@ -5038,7 +3945,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5038 | 3945 | ||
| 5039 | INIT_FAIL_STACK (); | 3946 | INIT_FAIL_STACK (); |
| 5040 | 3947 | ||
| 5041 | #ifdef MATCH_MAY_ALLOCATE | ||
| 5042 | /* Do not bother to initialize all the register variables if there are | 3948 | /* Do not bother to initialize all the register variables if there are |
| 5043 | no groups in the pattern, as it takes a fair amount of time. If | 3949 | no groups in the pattern, as it takes a fair amount of time. If |
| 5044 | there are groups, we include space for register 0 (the whole | 3950 | there are groups, we include space for register 0 (the whole |
| @@ -5046,29 +3952,16 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5046 | array indexing. We should fix this. */ | 3952 | array indexing. We should fix this. */ |
| 5047 | if (bufp->re_nsub) | 3953 | if (bufp->re_nsub) |
| 5048 | { | 3954 | { |
| 5049 | regstart = REGEX_TALLOC (num_regs, re_char *); | 3955 | regstart = SAFE_ALLOCA (num_regs * 4 * sizeof *regstart); |
| 5050 | regend = REGEX_TALLOC (num_regs, re_char *); | 3956 | regend = regstart + num_regs; |
| 5051 | best_regstart = REGEX_TALLOC (num_regs, re_char *); | 3957 | best_regstart = regend + num_regs; |
| 5052 | best_regend = REGEX_TALLOC (num_regs, re_char *); | 3958 | best_regend = best_regstart + num_regs; |
| 5053 | |||
| 5054 | if (!(regstart && regend && best_regstart && best_regend)) | ||
| 5055 | { | ||
| 5056 | FREE_VARIABLES (); | ||
| 5057 | return -2; | ||
| 5058 | } | ||
| 5059 | } | 3959 | } |
| 5060 | else | ||
| 5061 | { | ||
| 5062 | /* We must initialize all our variables to NULL, so that | ||
| 5063 | `FREE_VARIABLES' doesn't try to free them. */ | ||
| 5064 | regstart = regend = best_regstart = best_regend = NULL; | ||
| 5065 | } | ||
| 5066 | #endif /* MATCH_MAY_ALLOCATE */ | ||
| 5067 | 3960 | ||
| 5068 | /* The starting position is bogus. */ | 3961 | /* The starting position is bogus. */ |
| 5069 | if (pos < 0 || pos > size1 + size2) | 3962 | if (pos < 0 || pos > size1 + size2) |
| 5070 | { | 3963 | { |
| 5071 | FREE_VARIABLES (); | 3964 | SAFE_FREE (); |
| 5072 | return -1; | 3965 | return -1; |
| 5073 | } | 3966 | } |
| 5074 | 3967 | ||
| @@ -5078,8 +3971,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5078 | for (reg = 1; reg < num_regs; reg++) | 3971 | for (reg = 1; reg < num_regs; reg++) |
| 5079 | regstart[reg] = regend[reg] = NULL; | 3972 | regstart[reg] = regend[reg] = NULL; |
| 5080 | 3973 | ||
| 5081 | /* We move `string1' into `string2' if the latter's empty -- but not if | 3974 | /* We move 'string1' into 'string2' if the latter's empty -- but not if |
| 5082 | `string1' is null. */ | 3975 | 'string1' is null. */ |
| 5083 | if (size2 == 0 && string1 != NULL) | 3976 | if (size2 == 0 && string1 != NULL) |
| 5084 | { | 3977 | { |
| 5085 | string2 = string1; | 3978 | string2 = string1; |
| @@ -5090,12 +3983,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5090 | end1 = string1 + size1; | 3983 | end1 = string1 + size1; |
| 5091 | end2 = string2 + size2; | 3984 | end2 = string2 + size2; |
| 5092 | 3985 | ||
| 5093 | /* `p' scans through the pattern as `d' scans through the data. | 3986 | /* P scans through the pattern as D scans through the data. |
| 5094 | `dend' is the end of the input string that `d' points within. `d' | 3987 | DEND is the end of the input string that D points within. |
| 5095 | is advanced into the following input string whenever necessary, but | 3988 | Advance D into the following input string whenever necessary, but |
| 5096 | this happens before fetching; therefore, at the beginning of the | 3989 | this happens before fetching; therefore, at the beginning of the |
| 5097 | loop, `d' can be pointing at the end of a string, but it cannot | 3990 | loop, D can be pointing at the end of a string, but it cannot |
| 5098 | equal `string2'. */ | 3991 | equal STRING2. */ |
| 5099 | if (pos >= size1) | 3992 | if (pos >= size1) |
| 5100 | { | 3993 | { |
| 5101 | /* Only match within string2. */ | 3994 | /* Only match within string2. */ |
| @@ -5112,7 +4005,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5112 | /* BEWARE! | 4005 | /* BEWARE! |
| 5113 | When we reach end_match_1, PREFETCH normally switches to string2. | 4006 | When we reach end_match_1, PREFETCH normally switches to string2. |
| 5114 | But in the present case, this means that just doing a PREFETCH | 4007 | But in the present case, this means that just doing a PREFETCH |
| 5115 | makes us jump from `stop' to `gap' within the string. | 4008 | makes us jump from 'stop' to 'gap' within the string. |
| 5116 | What we really want here is for the search to stop as | 4009 | What we really want here is for the search to stop as |
| 5117 | soon as we hit end_match_1. That's why we set end_match_2 | 4010 | soon as we hit end_match_1. That's why we set end_match_2 |
| 5118 | to end_match_1 (since PREFETCH fails as soon as we hit | 4011 | to end_match_1 (since PREFETCH fails as soon as we hit |
| @@ -5120,8 +4013,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5120 | end_match_2 = end_match_1; | 4013 | end_match_2 = end_match_1; |
| 5121 | } | 4014 | } |
| 5122 | else | 4015 | else |
| 5123 | { /* It's important to use this code when stop == size so that | 4016 | { /* It's important to use this code when STOP == SIZE so that |
| 5124 | moving `d' from end1 to string2 will not prevent the d == dend | 4017 | moving D from end1 to string2 will not prevent the D == DEND |
| 5125 | check from catching the end of string. */ | 4018 | check from catching the end of string. */ |
| 5126 | end_match_1 = end1; | 4019 | end_match_1 = end1; |
| 5127 | end_match_2 = string2 + stop - size1; | 4020 | end_match_2 = string2 + stop - size1; |
| @@ -5197,10 +4090,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5197 | else if (best_regs_set && !best_match_p) | 4090 | else if (best_regs_set && !best_match_p) |
| 5198 | { | 4091 | { |
| 5199 | restore_best_regs: | 4092 | restore_best_regs: |
| 5200 | /* Restore best match. It may happen that `dend == | 4093 | /* Restore best match. It may happen that 'dend == |
| 5201 | end_match_1' while the restored d is in string2. | 4094 | end_match_1' while the restored d is in string2. |
| 5202 | For example, the pattern `x.*y.*z' against the | 4095 | For example, the pattern 'x.*y.*z' against the |
| 5203 | strings `x-' and `y-z-', if the two strings are | 4096 | strings 'x-' and 'y-z-', if the two strings are |
| 5204 | not consecutive in memory. */ | 4097 | not consecutive in memory. */ |
| 5205 | DEBUG_PRINT ("Restoring best registers.\n"); | 4098 | DEBUG_PRINT ("Restoring best registers.\n"); |
| 5206 | 4099 | ||
| @@ -5220,21 +4113,16 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5220 | DEBUG_PRINT ("Accepting match.\n"); | 4113 | DEBUG_PRINT ("Accepting match.\n"); |
| 5221 | 4114 | ||
| 5222 | /* If caller wants register contents data back, do it. */ | 4115 | /* If caller wants register contents data back, do it. */ |
| 5223 | if (regs && !bufp->no_sub) | 4116 | if (regs) |
| 5224 | { | 4117 | { |
| 5225 | /* Have the register data arrays been allocated? */ | 4118 | /* Have the register data arrays been allocated? */ |
| 5226 | if (bufp->regs_allocated == REGS_UNALLOCATED) | 4119 | if (bufp->regs_allocated == REGS_UNALLOCATED) |
| 5227 | { /* No. So allocate them with malloc. We need one | 4120 | { /* No. So allocate them with malloc. We need one |
| 5228 | extra element beyond `num_regs' for the `-1' marker | 4121 | extra element beyond 'num_regs' for the '-1' marker |
| 5229 | GNU code uses. */ | 4122 | GNU code uses. */ |
| 5230 | regs->num_regs = max (RE_NREGS, num_regs + 1); | 4123 | regs->num_regs = max (RE_NREGS, num_regs + 1); |
| 5231 | regs->start = TALLOC (regs->num_regs, regoff_t); | 4124 | regs->start = TALLOC (regs->num_regs, ptrdiff_t); |
| 5232 | regs->end = TALLOC (regs->num_regs, regoff_t); | 4125 | regs->end = TALLOC (regs->num_regs, ptrdiff_t); |
| 5233 | if (regs->start == NULL || regs->end == NULL) | ||
| 5234 | { | ||
| 5235 | FREE_VARIABLES (); | ||
| 5236 | return -2; | ||
| 5237 | } | ||
| 5238 | bufp->regs_allocated = REGS_REALLOCATE; | 4126 | bufp->regs_allocated = REGS_REALLOCATE; |
| 5239 | } | 4127 | } |
| 5240 | else if (bufp->regs_allocated == REGS_REALLOCATE) | 4128 | else if (bufp->regs_allocated == REGS_REALLOCATE) |
| @@ -5244,23 +4132,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5244 | if (regs->num_regs < num_regs + 1) | 4132 | if (regs->num_regs < num_regs + 1) |
| 5245 | { | 4133 | { |
| 5246 | regs->num_regs = num_regs + 1; | 4134 | regs->num_regs = num_regs + 1; |
| 5247 | RETALLOC (regs->start, regs->num_regs, regoff_t); | 4135 | RETALLOC (regs->start, regs->num_regs, ptrdiff_t); |
| 5248 | RETALLOC (regs->end, regs->num_regs, regoff_t); | 4136 | RETALLOC (regs->end, regs->num_regs, ptrdiff_t); |
| 5249 | if (regs->start == NULL || regs->end == NULL) | ||
| 5250 | { | ||
| 5251 | FREE_VARIABLES (); | ||
| 5252 | return -2; | ||
| 5253 | } | ||
| 5254 | } | 4137 | } |
| 5255 | } | 4138 | } |
| 5256 | else | 4139 | else |
| 5257 | { | 4140 | eassert (bufp->regs_allocated == REGS_FIXED); |
| 5258 | /* These braces fend off a "empty body in an else-statement" | ||
| 5259 | warning under GCC when assert expands to nothing. */ | ||
| 5260 | assert (bufp->regs_allocated == REGS_FIXED); | ||
| 5261 | } | ||
| 5262 | 4141 | ||
| 5263 | /* Convert the pointer data in `regstart' and `regend' to | 4142 | /* Convert the pointer data in 'regstart' and 'regend' to |
| 5264 | indices. Register zero has to be set differently, | 4143 | indices. Register zero has to be set differently, |
| 5265 | since we haven't kept track of any info for it. */ | 4144 | since we haven't kept track of any info for it. */ |
| 5266 | if (regs->num_regs > 0) | 4145 | if (regs->num_regs > 0) |
| @@ -5269,7 +4148,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5269 | regs->end[0] = POINTER_TO_OFFSET (d); | 4148 | regs->end[0] = POINTER_TO_OFFSET (d); |
| 5270 | } | 4149 | } |
| 5271 | 4150 | ||
| 5272 | /* Go through the first `min (num_regs, regs->num_regs)' | 4151 | /* Go through the first 'min (num_regs, regs->num_regs)' |
| 5273 | registers, since that is all we initialized. */ | 4152 | registers, since that is all we initialized. */ |
| 5274 | for (reg = 1; reg < min (num_regs, regs->num_regs); reg++) | 4153 | for (reg = 1; reg < min (num_regs, regs->num_regs); reg++) |
| 5275 | { | 4154 | { |
| @@ -5289,7 +4168,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5289 | -1 at the end. */ | 4168 | -1 at the end. */ |
| 5290 | for (reg = num_regs; reg < regs->num_regs; reg++) | 4169 | for (reg = num_regs; reg < regs->num_regs; reg++) |
| 5291 | regs->start[reg] = regs->end[reg] = -1; | 4170 | regs->start[reg] = regs->end[reg] = -1; |
| 5292 | } /* regs && !bufp->no_sub */ | 4171 | } |
| 5293 | 4172 | ||
| 5294 | DEBUG_PRINT ("%u failure points pushed, %u popped (%u remain).\n", | 4173 | DEBUG_PRINT ("%u failure points pushed, %u popped (%u remain).\n", |
| 5295 | nfailure_points_pushed, nfailure_points_popped, | 4174 | nfailure_points_pushed, nfailure_points_popped, |
| @@ -5300,7 +4179,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5300 | 4179 | ||
| 5301 | DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt); | 4180 | DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt); |
| 5302 | 4181 | ||
| 5303 | FREE_VARIABLES (); | 4182 | SAFE_FREE (); |
| 5304 | return dcnt; | 4183 | return dcnt; |
| 5305 | } | 4184 | } |
| 5306 | 4185 | ||
| @@ -5327,34 +4206,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5327 | /* Remember the start point to rollback upon failure. */ | 4206 | /* Remember the start point to rollback upon failure. */ |
| 5328 | dfail = d; | 4207 | dfail = d; |
| 5329 | 4208 | ||
| 5330 | #ifndef emacs | 4209 | /* The cost of testing 'translate' is comparatively small. */ |
| 5331 | /* This is written out as an if-else so we don't waste time | ||
| 5332 | testing `translate' inside the loop. */ | ||
| 5333 | if (RE_TRANSLATE_P (translate)) | ||
| 5334 | do | ||
| 5335 | { | ||
| 5336 | PREFETCH (); | ||
| 5337 | if (RE_TRANSLATE (translate, *d) != *p++) | ||
| 5338 | { | ||
| 5339 | d = dfail; | ||
| 5340 | goto fail; | ||
| 5341 | } | ||
| 5342 | d++; | ||
| 5343 | } | ||
| 5344 | while (--mcnt); | ||
| 5345 | else | ||
| 5346 | do | ||
| 5347 | { | ||
| 5348 | PREFETCH (); | ||
| 5349 | if (*d++ != *p++) | ||
| 5350 | { | ||
| 5351 | d = dfail; | ||
| 5352 | goto fail; | ||
| 5353 | } | ||
| 5354 | } | ||
| 5355 | while (--mcnt); | ||
| 5356 | #else /* emacs */ | ||
| 5357 | /* The cost of testing `translate' is comparatively small. */ | ||
| 5358 | if (target_multibyte) | 4210 | if (target_multibyte) |
| 5359 | do | 4211 | do |
| 5360 | { | 4212 | { |
| @@ -5418,16 +4270,15 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5418 | d++; | 4270 | d++; |
| 5419 | } | 4271 | } |
| 5420 | while (--mcnt); | 4272 | while (--mcnt); |
| 5421 | #endif | 4273 | |
| 5422 | break; | 4274 | break; |
| 5423 | 4275 | ||
| 5424 | 4276 | ||
| 5425 | /* Match any character except possibly a newline or a null. */ | 4277 | /* Match any character except newline. */ |
| 5426 | case anychar: | 4278 | case anychar: |
| 5427 | { | 4279 | { |
| 5428 | int buf_charlen; | 4280 | int buf_charlen; |
| 5429 | re_wchar_t buf_ch; | 4281 | int buf_ch; |
| 5430 | reg_syntax_t syntax; | ||
| 5431 | 4282 | ||
| 5432 | DEBUG_PRINT ("EXECUTING anychar.\n"); | 4283 | DEBUG_PRINT ("EXECUTING anychar.\n"); |
| 5433 | 4284 | ||
| @@ -5435,15 +4286,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5435 | buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen, | 4286 | buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen, |
| 5436 | target_multibyte); | 4287 | target_multibyte); |
| 5437 | buf_ch = TRANSLATE (buf_ch); | 4288 | buf_ch = TRANSLATE (buf_ch); |
| 5438 | 4289 | if (buf_ch == '\n') | |
| 5439 | #ifdef emacs | ||
| 5440 | syntax = RE_SYNTAX_EMACS; | ||
| 5441 | #else | ||
| 5442 | syntax = bufp->syntax; | ||
| 5443 | #endif | ||
| 5444 | |||
| 5445 | if ((!(syntax & RE_DOT_NEWLINE) && buf_ch == '\n') | ||
| 5446 | || ((syntax & RE_DOT_NOT_NULL) && buf_ch == '\000')) | ||
| 5447 | goto fail; | 4290 | goto fail; |
| 5448 | 4291 | ||
| 5449 | DEBUG_PRINT (" Matched \"%d\".\n", *d); | 4292 | DEBUG_PRINT (" Matched \"%d\".\n", *d); |
| @@ -5459,7 +4302,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5459 | int len; | 4302 | int len; |
| 5460 | 4303 | ||
| 5461 | /* Whether matching against a unibyte character. */ | 4304 | /* Whether matching against a unibyte character. */ |
| 5462 | boolean unibyte_char = false; | 4305 | bool unibyte_char = false; |
| 5463 | 4306 | ||
| 5464 | DEBUG_PRINT ("EXECUTING charset%s.\n", | 4307 | DEBUG_PRINT ("EXECUTING charset%s.\n", |
| 5465 | (re_opcode_t) *(p - 1) == charset_not ? "_not" : ""); | 4308 | (re_opcode_t) *(p - 1) == charset_not ? "_not" : ""); |
| @@ -5529,10 +4372,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5529 | case stop_memory: | 4372 | case stop_memory: |
| 5530 | DEBUG_PRINT ("EXECUTING stop_memory %d:\n", *p); | 4373 | DEBUG_PRINT ("EXECUTING stop_memory %d:\n", *p); |
| 5531 | 4374 | ||
| 5532 | assert (!REG_UNSET (regstart[*p])); | 4375 | eassert (!REG_UNSET (regstart[*p])); |
| 5533 | /* Strictly speaking, there should be code such as: | 4376 | /* Strictly speaking, there should be code such as: |
| 5534 | 4377 | ||
| 5535 | assert (REG_UNSET (regend[*p])); | 4378 | eassert (REG_UNSET (regend[*p])); |
| 5536 | PUSH_FAILURE_REGSTOP ((unsigned int)*p); | 4379 | PUSH_FAILURE_REGSTOP ((unsigned int)*p); |
| 5537 | 4380 | ||
| 5538 | But the only info to be pushed is regend[*p] and it is known to | 4381 | But the only info to be pushed is regend[*p] and it is known to |
| @@ -5552,11 +4395,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5552 | break; | 4395 | break; |
| 5553 | 4396 | ||
| 5554 | 4397 | ||
| 5555 | /* \<digit> has been turned into a `duplicate' command which is | 4398 | /* \<digit> has been turned into a 'duplicate' command which is |
| 5556 | followed by the numeric value of <digit> as the register number. */ | 4399 | followed by the numeric value of <digit> as the register number. */ |
| 5557 | case duplicate: | 4400 | case duplicate: |
| 5558 | { | 4401 | { |
| 5559 | register re_char *d2, *dend2; | 4402 | re_char *d2, *dend2; |
| 5560 | int regno = *p++; /* Get which register to match against. */ | 4403 | int regno = *p++; /* Get which register to match against. */ |
| 5561 | DEBUG_PRINT ("EXECUTING duplicate %d.\n", regno); | 4404 | DEBUG_PRINT ("EXECUTING duplicate %d.\n", regno); |
| 5562 | 4405 | ||
| @@ -5609,7 +4452,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5609 | 4452 | ||
| 5610 | /* Compare that many; failure if mismatch, else move | 4453 | /* Compare that many; failure if mismatch, else move |
| 5611 | past them. */ | 4454 | past them. */ |
| 5612 | if (RE_TRANSLATE_P (translate) | 4455 | if (!NILP (translate) |
| 5613 | ? bcmp_translate (d, d2, dcnt, translate, target_multibyte) | 4456 | ? bcmp_translate (d, d2, dcnt, translate, target_multibyte) |
| 5614 | : memcmp (d, d2, dcnt)) | 4457 | : memcmp (d, d2, dcnt)) |
| 5615 | { | 4458 | { |
| @@ -5622,15 +4465,13 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5622 | break; | 4465 | break; |
| 5623 | 4466 | ||
| 5624 | 4467 | ||
| 5625 | /* begline matches the empty string at the beginning of the string | 4468 | /* begline matches the empty string at the beginning of the string, |
| 5626 | (unless `not_bol' is set in `bufp'), and after newlines. */ | 4469 | and after newlines. */ |
| 5627 | case begline: | 4470 | case begline: |
| 5628 | DEBUG_PRINT ("EXECUTING begline.\n"); | 4471 | DEBUG_PRINT ("EXECUTING begline.\n"); |
| 5629 | 4472 | ||
| 5630 | if (AT_STRINGS_BEG (d)) | 4473 | if (AT_STRINGS_BEG (d)) |
| 5631 | { | 4474 | break; |
| 5632 | if (!bufp->not_bol) break; | ||
| 5633 | } | ||
| 5634 | else | 4475 | else |
| 5635 | { | 4476 | { |
| 5636 | unsigned c; | 4477 | unsigned c; |
| @@ -5638,7 +4479,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5638 | if (c == '\n') | 4479 | if (c == '\n') |
| 5639 | break; | 4480 | break; |
| 5640 | } | 4481 | } |
| 5641 | /* In all other cases, we fail. */ | ||
| 5642 | goto fail; | 4482 | goto fail; |
| 5643 | 4483 | ||
| 5644 | 4484 | ||
| @@ -5647,15 +4487,10 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5647 | DEBUG_PRINT ("EXECUTING endline.\n"); | 4487 | DEBUG_PRINT ("EXECUTING endline.\n"); |
| 5648 | 4488 | ||
| 5649 | if (AT_STRINGS_END (d)) | 4489 | if (AT_STRINGS_END (d)) |
| 5650 | { | 4490 | break; |
| 5651 | if (!bufp->not_eol) break; | 4491 | PREFETCH_NOLIMIT (); |
| 5652 | } | 4492 | if (*d == '\n') |
| 5653 | else | 4493 | break; |
| 5654 | { | ||
| 5655 | PREFETCH_NOLIMIT (); | ||
| 5656 | if (*d == '\n') | ||
| 5657 | break; | ||
| 5658 | } | ||
| 5659 | goto fail; | 4494 | goto fail; |
| 5660 | 4495 | ||
| 5661 | 4496 | ||
| @@ -5675,21 +4510,21 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5675 | goto fail; | 4510 | goto fail; |
| 5676 | 4511 | ||
| 5677 | 4512 | ||
| 5678 | /* on_failure_keep_string_jump is used to optimize `.*\n'. It | 4513 | /* on_failure_keep_string_jump is used to optimize '.*\n'. It |
| 5679 | pushes NULL as the value for the string on the stack. Then | 4514 | pushes NULL as the value for the string on the stack. Then |
| 5680 | `POP_FAILURE_POINT' will keep the current value for the | 4515 | 'POP_FAILURE_POINT' will keep the current value for the |
| 5681 | string, instead of restoring it. To see why, consider | 4516 | string, instead of restoring it. To see why, consider |
| 5682 | matching `foo\nbar' against `.*\n'. The .* matches the foo; | 4517 | matching 'foo\nbar' against '.*\n'. The .* matches the foo; |
| 5683 | then the . fails against the \n. But the next thing we want | 4518 | then the . fails against the \n. But the next thing we want |
| 5684 | to do is match the \n against the \n; if we restored the | 4519 | to do is match the \n against the \n; if we restored the |
| 5685 | string value, we would be back at the foo. | 4520 | string value, we would be back at the foo. |
| 5686 | 4521 | ||
| 5687 | Because this is used only in specific cases, we don't need to | 4522 | Because this is used only in specific cases, we don't need to |
| 5688 | check all the things that `on_failure_jump' does, to make | 4523 | check all the things that 'on_failure_jump' does, to make |
| 5689 | sure the right things get saved on the stack. Hence we don't | 4524 | sure the right things get saved on the stack. Hence we don't |
| 5690 | share its code. The only reason to push anything on the | 4525 | share its code. The only reason to push anything on the |
| 5691 | stack at all is that otherwise we would have to change | 4526 | stack at all is that otherwise we would have to change |
| 5692 | `anychar's code to do something besides goto fail in this | 4527 | 'anychar's code to do something besides goto fail in this |
| 5693 | case; that seems worse than this. */ | 4528 | case; that seems worse than this. */ |
| 5694 | case on_failure_keep_string_jump: | 4529 | case on_failure_keep_string_jump: |
| 5695 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 4530 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| @@ -5718,7 +4553,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5718 | DEBUG_PRINT ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n", | 4553 | DEBUG_PRINT ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n", |
| 5719 | mcnt, p + mcnt); | 4554 | mcnt, p + mcnt); |
| 5720 | 4555 | ||
| 5721 | assert ((re_opcode_t)p[-4] == no_op); | 4556 | eassert ((re_opcode_t)p[-4] == no_op); |
| 5722 | { | 4557 | { |
| 5723 | int cycle = 0; | 4558 | int cycle = 0; |
| 5724 | CHECK_INFINITE_LOOP (p - 4, d); | 4559 | CHECK_INFINITE_LOOP (p - 4, d); |
| @@ -5743,7 +4578,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5743 | CHECK_INFINITE_LOOP (p - 3, d); | 4578 | CHECK_INFINITE_LOOP (p - 3, d); |
| 5744 | if (cycle) | 4579 | if (cycle) |
| 5745 | /* If there's a cycle, get out of the loop, as if the matching | 4580 | /* If there's a cycle, get out of the loop, as if the matching |
| 5746 | had failed. We used to just `goto fail' here, but that was | 4581 | had failed. We used to just 'goto fail' here, but that was |
| 5747 | aborting the search a bit too early: we want to keep the | 4582 | aborting the search a bit too early: we want to keep the |
| 5748 | empty-loop-match and keep matching after the loop. | 4583 | empty-loop-match and keep matching after the loop. |
| 5749 | We want (x?)*y\1z to match both xxyz and xxyxz. */ | 4584 | We want (x?)*y\1z to match both xxyz and xxyxz. */ |
| @@ -5778,7 +4613,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5778 | Compare the beginning of the repeat with what in the | 4613 | Compare the beginning of the repeat with what in the |
| 5779 | pattern follows its end. If we can establish that there | 4614 | pattern follows its end. If we can establish that there |
| 5780 | is nothing that they would both match, i.e., that we | 4615 | is nothing that they would both match, i.e., that we |
| 5781 | would have to backtrack because of (as in, e.g., `a*a') | 4616 | would have to backtrack because of (as in, e.g., 'a*a') |
| 5782 | then we can use a non-backtracking loop based on | 4617 | then we can use a non-backtracking loop based on |
| 5783 | on_failure_keep_string_jump instead of on_failure_jump. */ | 4618 | on_failure_keep_string_jump instead of on_failure_jump. */ |
| 5784 | case on_failure_jump_smart: | 4619 | case on_failure_jump_smart: |
| @@ -5787,7 +4622,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5787 | mcnt, p + mcnt); | 4622 | mcnt, p + mcnt); |
| 5788 | { | 4623 | { |
| 5789 | re_char *p1 = p; /* Next operation. */ | 4624 | re_char *p1 = p; /* Next operation. */ |
| 5790 | /* Here, we discard `const', making re_match non-reentrant. */ | 4625 | /* Discard 'const', making re_search non-reentrant. */ |
| 5791 | unsigned char *p2 = (unsigned char *) p + mcnt; /* Jump dest. */ | 4626 | unsigned char *p2 = (unsigned char *) p + mcnt; /* Jump dest. */ |
| 5792 | unsigned char *p3 = (unsigned char *) p - 3; /* opcode location. */ | 4627 | unsigned char *p3 = (unsigned char *) p - 3; /* opcode location. */ |
| 5793 | 4628 | ||
| @@ -5798,23 +4633,23 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5798 | 4633 | ||
| 5799 | /* Ensure this is indeed the trivial kind of loop | 4634 | /* Ensure this is indeed the trivial kind of loop |
| 5800 | we are expecting. */ | 4635 | we are expecting. */ |
| 5801 | assert (skip_one_char (p1) == p2 - 3); | 4636 | eassert (skip_one_char (p1) == p2 - 3); |
| 5802 | assert ((re_opcode_t) p2[-3] == jump && p2 + mcnt == p); | 4637 | eassert ((re_opcode_t) p2[-3] == jump && p2 + mcnt == p); |
| 5803 | DEBUG_STATEMENT (debug += 2); | 4638 | DEBUG_STATEMENT (regex_emacs_debug += 2); |
| 5804 | if (mutually_exclusive_p (bufp, p1, p2)) | 4639 | if (mutually_exclusive_p (bufp, p1, p2)) |
| 5805 | { | 4640 | { |
| 5806 | /* Use a fast `on_failure_keep_string_jump' loop. */ | 4641 | /* Use a fast 'on_failure_keep_string_jump' loop. */ |
| 5807 | DEBUG_PRINT (" smart exclusive => fast loop.\n"); | 4642 | DEBUG_PRINT (" smart exclusive => fast loop.\n"); |
| 5808 | *p3 = (unsigned char) on_failure_keep_string_jump; | 4643 | *p3 = (unsigned char) on_failure_keep_string_jump; |
| 5809 | STORE_NUMBER (p2 - 2, mcnt + 3); | 4644 | STORE_NUMBER (p2 - 2, mcnt + 3); |
| 5810 | } | 4645 | } |
| 5811 | else | 4646 | else |
| 5812 | { | 4647 | { |
| 5813 | /* Default to a safe `on_failure_jump' loop. */ | 4648 | /* Default to a safe 'on_failure_jump' loop. */ |
| 5814 | DEBUG_PRINT (" smart default => slow loop.\n"); | 4649 | DEBUG_PRINT (" smart default => slow loop.\n"); |
| 5815 | *p3 = (unsigned char) on_failure_jump; | 4650 | *p3 = (unsigned char) on_failure_jump; |
| 5816 | } | 4651 | } |
| 5817 | DEBUG_STATEMENT (debug -= 2); | 4652 | DEBUG_STATEMENT (regex_emacs_debug -= 2); |
| 5818 | } | 4653 | } |
| 5819 | break; | 4654 | break; |
| 5820 | 4655 | ||
| @@ -5830,7 +4665,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5830 | 4665 | ||
| 5831 | 4666 | ||
| 5832 | /* Have to succeed matching what follows at least n times. | 4667 | /* Have to succeed matching what follows at least n times. |
| 5833 | After that, handle like `on_failure_jump'. */ | 4668 | After that, handle like 'on_failure_jump'. */ |
| 5834 | case succeed_n: | 4669 | case succeed_n: |
| 5835 | /* Signedness doesn't matter since we only compare MCNT to 0. */ | 4670 | /* Signedness doesn't matter since we only compare MCNT to 0. */ |
| 5836 | EXTRACT_NUMBER (mcnt, p + 2); | 4671 | EXTRACT_NUMBER (mcnt, p + 2); |
| @@ -5839,7 +4674,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5839 | /* Originally, mcnt is how many times we HAVE to succeed. */ | 4674 | /* Originally, mcnt is how many times we HAVE to succeed. */ |
| 5840 | if (mcnt != 0) | 4675 | if (mcnt != 0) |
| 5841 | { | 4676 | { |
| 5842 | /* Here, we discard `const', making re_match non-reentrant. */ | 4677 | /* Discard 'const', making re_search non-reentrant. */ |
| 5843 | unsigned char *p2 = (unsigned char *) p + 2; /* counter loc. */ | 4678 | unsigned char *p2 = (unsigned char *) p + 2; /* counter loc. */ |
| 5844 | mcnt--; | 4679 | mcnt--; |
| 5845 | p += 4; | 4680 | p += 4; |
| @@ -5858,7 +4693,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5858 | /* Originally, this is how many times we CAN jump. */ | 4693 | /* Originally, this is how many times we CAN jump. */ |
| 5859 | if (mcnt != 0) | 4694 | if (mcnt != 0) |
| 5860 | { | 4695 | { |
| 5861 | /* Here, we discard `const', making re_match non-reentrant. */ | 4696 | /* Discard 'const', making re_search non-reentrant. */ |
| 5862 | unsigned char *p2 = (unsigned char *) p + 2; /* counter loc. */ | 4697 | unsigned char *p2 = (unsigned char *) p + 2; /* counter loc. */ |
| 5863 | mcnt--; | 4698 | mcnt--; |
| 5864 | PUSH_NUMBER (p2, mcnt); | 4699 | PUSH_NUMBER (p2, mcnt); |
| @@ -5875,7 +4710,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5875 | DEBUG_PRINT ("EXECUTING set_number_at.\n"); | 4710 | DEBUG_PRINT ("EXECUTING set_number_at.\n"); |
| 5876 | 4711 | ||
| 5877 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 4712 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 5878 | /* Here, we discard `const', making re_match non-reentrant. */ | 4713 | /* Discard 'const', making re_search non-reentrant. */ |
| 5879 | p2 = (unsigned char *) p + mcnt; | 4714 | p2 = (unsigned char *) p + mcnt; |
| 5880 | /* Signedness doesn't matter since we only copy MCNT's bits. */ | 4715 | /* Signedness doesn't matter since we only copy MCNT's bits. */ |
| 5881 | EXTRACT_NUMBER_AND_INCR (mcnt, p); | 4716 | EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| @@ -5887,7 +4722,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5887 | case wordbound: | 4722 | case wordbound: |
| 5888 | case notwordbound: | 4723 | case notwordbound: |
| 5889 | { | 4724 | { |
| 5890 | boolean not = (re_opcode_t) *(p - 1) == notwordbound; | 4725 | bool not = (re_opcode_t) *(p - 1) == notwordbound; |
| 5891 | DEBUG_PRINT ("EXECUTING %swordbound.\n", not ? "not" : ""); | 4726 | DEBUG_PRINT ("EXECUTING %swordbound.\n", not ? "not" : ""); |
| 5892 | 4727 | ||
| 5893 | /* We SUCCEED (or FAIL) in one of the following cases: */ | 4728 | /* We SUCCEED (or FAIL) in one of the following cases: */ |
| @@ -5899,19 +4734,15 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5899 | { | 4734 | { |
| 5900 | /* C1 is the character before D, S1 is the syntax of C1, C2 | 4735 | /* C1 is the character before D, S1 is the syntax of C1, C2 |
| 5901 | is the character at D, and S2 is the syntax of C2. */ | 4736 | is the character at D, and S2 is the syntax of C2. */ |
| 5902 | re_wchar_t c1, c2; | 4737 | int c1, c2; |
| 5903 | int s1, s2; | 4738 | int s1, s2; |
| 5904 | int dummy; | 4739 | int dummy; |
| 5905 | #ifdef emacs | 4740 | ptrdiff_t offset = PTR_TO_OFFSET (d - 1); |
| 5906 | ssize_t offset = PTR_TO_OFFSET (d - 1); | 4741 | ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
| 5907 | ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); | ||
| 5908 | UPDATE_SYNTAX_TABLE (charpos); | 4742 | UPDATE_SYNTAX_TABLE (charpos); |
| 5909 | #endif | ||
| 5910 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); | 4743 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
| 5911 | s1 = SYNTAX (c1); | 4744 | s1 = SYNTAX (c1); |
| 5912 | #ifdef emacs | ||
| 5913 | UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); | 4745 | UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); |
| 5914 | #endif | ||
| 5915 | PREFETCH_NOLIMIT (); | 4746 | PREFETCH_NOLIMIT (); |
| 5916 | GET_CHAR_AFTER (c2, d, dummy); | 4747 | GET_CHAR_AFTER (c2, d, dummy); |
| 5917 | s2 = SYNTAX (c2); | 4748 | s2 = SYNTAX (c2); |
| @@ -5941,14 +4772,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5941 | { | 4772 | { |
| 5942 | /* C1 is the character before D, S1 is the syntax of C1, C2 | 4773 | /* C1 is the character before D, S1 is the syntax of C1, C2 |
| 5943 | is the character at D, and S2 is the syntax of C2. */ | 4774 | is the character at D, and S2 is the syntax of C2. */ |
| 5944 | re_wchar_t c1, c2; | 4775 | int c1, c2; |
| 5945 | int s1, s2; | 4776 | int s1, s2; |
| 5946 | int dummy; | 4777 | int dummy; |
| 5947 | #ifdef emacs | 4778 | ptrdiff_t offset = PTR_TO_OFFSET (d); |
| 5948 | ssize_t offset = PTR_TO_OFFSET (d); | 4779 | ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
| 5949 | ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); | ||
| 5950 | UPDATE_SYNTAX_TABLE (charpos); | 4780 | UPDATE_SYNTAX_TABLE (charpos); |
| 5951 | #endif | ||
| 5952 | PREFETCH (); | 4781 | PREFETCH (); |
| 5953 | GET_CHAR_AFTER (c2, d, dummy); | 4782 | GET_CHAR_AFTER (c2, d, dummy); |
| 5954 | s2 = SYNTAX (c2); | 4783 | s2 = SYNTAX (c2); |
| @@ -5961,9 +4790,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5961 | if (!AT_STRINGS_BEG (d)) | 4790 | if (!AT_STRINGS_BEG (d)) |
| 5962 | { | 4791 | { |
| 5963 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); | 4792 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
| 5964 | #ifdef emacs | ||
| 5965 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1); | 4793 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1); |
| 5966 | #endif | ||
| 5967 | s1 = SYNTAX (c1); | 4794 | s1 = SYNTAX (c1); |
| 5968 | 4795 | ||
| 5969 | /* ... and S1 is Sword, and WORD_BOUNDARY_P (C1, C2) | 4796 | /* ... and S1 is Sword, and WORD_BOUNDARY_P (C1, C2) |
| @@ -5986,14 +4813,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 5986 | { | 4813 | { |
| 5987 | /* C1 is the character before D, S1 is the syntax of C1, C2 | 4814 | /* C1 is the character before D, S1 is the syntax of C1, C2 |
| 5988 | is the character at D, and S2 is the syntax of C2. */ | 4815 | is the character at D, and S2 is the syntax of C2. */ |
| 5989 | re_wchar_t c1, c2; | 4816 | int c1, c2; |
| 5990 | int s1, s2; | 4817 | int s1, s2; |
| 5991 | int dummy; | 4818 | int dummy; |
| 5992 | #ifdef emacs | 4819 | ptrdiff_t offset = PTR_TO_OFFSET (d) - 1; |
| 5993 | ssize_t offset = PTR_TO_OFFSET (d) - 1; | 4820 | ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
| 5994 | ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); | ||
| 5995 | UPDATE_SYNTAX_TABLE (charpos); | 4821 | UPDATE_SYNTAX_TABLE (charpos); |
| 5996 | #endif | ||
| 5997 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); | 4822 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
| 5998 | s1 = SYNTAX (c1); | 4823 | s1 = SYNTAX (c1); |
| 5999 | 4824 | ||
| @@ -6006,9 +4831,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6006 | { | 4831 | { |
| 6007 | PREFETCH_NOLIMIT (); | 4832 | PREFETCH_NOLIMIT (); |
| 6008 | GET_CHAR_AFTER (c2, d, dummy); | 4833 | GET_CHAR_AFTER (c2, d, dummy); |
| 6009 | #ifdef emacs | ||
| 6010 | UPDATE_SYNTAX_TABLE_FORWARD (charpos); | 4834 | UPDATE_SYNTAX_TABLE_FORWARD (charpos); |
| 6011 | #endif | ||
| 6012 | s2 = SYNTAX (c2); | 4835 | s2 = SYNTAX (c2); |
| 6013 | 4836 | ||
| 6014 | /* ... and S2 is Sword, and WORD_BOUNDARY_P (C1, C2) | 4837 | /* ... and S2 is Sword, and WORD_BOUNDARY_P (C1, C2) |
| @@ -6031,13 +4854,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6031 | { | 4854 | { |
| 6032 | /* C1 is the character before D, S1 is the syntax of C1, C2 | 4855 | /* C1 is the character before D, S1 is the syntax of C1, C2 |
| 6033 | is the character at D, and S2 is the syntax of C2. */ | 4856 | is the character at D, and S2 is the syntax of C2. */ |
| 6034 | re_wchar_t c1, c2; | 4857 | int c1, c2; |
| 6035 | int s1, s2; | 4858 | int s1, s2; |
| 6036 | #ifdef emacs | 4859 | ptrdiff_t offset = PTR_TO_OFFSET (d); |
| 6037 | ssize_t offset = PTR_TO_OFFSET (d); | 4860 | ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
| 6038 | ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); | ||
| 6039 | UPDATE_SYNTAX_TABLE (charpos); | 4861 | UPDATE_SYNTAX_TABLE (charpos); |
| 6040 | #endif | ||
| 6041 | PREFETCH (); | 4862 | PREFETCH (); |
| 6042 | c2 = RE_STRING_CHAR (d, target_multibyte); | 4863 | c2 = RE_STRING_CHAR (d, target_multibyte); |
| 6043 | s2 = SYNTAX (c2); | 4864 | s2 = SYNTAX (c2); |
| @@ -6050,9 +4871,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6050 | if (!AT_STRINGS_BEG (d)) | 4871 | if (!AT_STRINGS_BEG (d)) |
| 6051 | { | 4872 | { |
| 6052 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); | 4873 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
| 6053 | #ifdef emacs | ||
| 6054 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1); | 4874 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1); |
| 6055 | #endif | ||
| 6056 | s1 = SYNTAX (c1); | 4875 | s1 = SYNTAX (c1); |
| 6057 | 4876 | ||
| 6058 | /* ... and S1 is Sword or Ssymbol. */ | 4877 | /* ... and S1 is Sword or Ssymbol. */ |
| @@ -6074,13 +4893,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6074 | { | 4893 | { |
| 6075 | /* C1 is the character before D, S1 is the syntax of C1, C2 | 4894 | /* C1 is the character before D, S1 is the syntax of C1, C2 |
| 6076 | is the character at D, and S2 is the syntax of C2. */ | 4895 | is the character at D, and S2 is the syntax of C2. */ |
| 6077 | re_wchar_t c1, c2; | 4896 | int c1, c2; |
| 6078 | int s1, s2; | 4897 | int s1, s2; |
| 6079 | #ifdef emacs | 4898 | ptrdiff_t offset = PTR_TO_OFFSET (d) - 1; |
| 6080 | ssize_t offset = PTR_TO_OFFSET (d) - 1; | 4899 | ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
| 6081 | ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); | ||
| 6082 | UPDATE_SYNTAX_TABLE (charpos); | 4900 | UPDATE_SYNTAX_TABLE (charpos); |
| 6083 | #endif | ||
| 6084 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); | 4901 | GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
| 6085 | s1 = SYNTAX (c1); | 4902 | s1 = SYNTAX (c1); |
| 6086 | 4903 | ||
| @@ -6093,9 +4910,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6093 | { | 4910 | { |
| 6094 | PREFETCH_NOLIMIT (); | 4911 | PREFETCH_NOLIMIT (); |
| 6095 | c2 = RE_STRING_CHAR (d, target_multibyte); | 4912 | c2 = RE_STRING_CHAR (d, target_multibyte); |
| 6096 | #ifdef emacs | ||
| 6097 | UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); | 4913 | UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); |
| 6098 | #endif | ||
| 6099 | s2 = SYNTAX (c2); | 4914 | s2 = SYNTAX (c2); |
| 6100 | 4915 | ||
| 6101 | /* ... and S2 is Sword or Ssymbol. */ | 4916 | /* ... and S2 is Sword or Ssymbol. */ |
| @@ -6108,21 +4923,19 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6108 | case syntaxspec: | 4923 | case syntaxspec: |
| 6109 | case notsyntaxspec: | 4924 | case notsyntaxspec: |
| 6110 | { | 4925 | { |
| 6111 | boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec; | 4926 | bool not = (re_opcode_t) *(p - 1) == notsyntaxspec; |
| 6112 | mcnt = *p++; | 4927 | mcnt = *p++; |
| 6113 | DEBUG_PRINT ("EXECUTING %ssyntaxspec %d.\n", not ? "not" : "", | 4928 | DEBUG_PRINT ("EXECUTING %ssyntaxspec %d.\n", not ? "not" : "", |
| 6114 | mcnt); | 4929 | mcnt); |
| 6115 | PREFETCH (); | 4930 | PREFETCH (); |
| 6116 | #ifdef emacs | ||
| 6117 | { | 4931 | { |
| 6118 | ssize_t offset = PTR_TO_OFFSET (d); | 4932 | ptrdiff_t offset = PTR_TO_OFFSET (d); |
| 6119 | ssize_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset); | 4933 | ptrdiff_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
| 6120 | UPDATE_SYNTAX_TABLE (pos1); | 4934 | UPDATE_SYNTAX_TABLE (pos1); |
| 6121 | } | 4935 | } |
| 6122 | #endif | ||
| 6123 | { | 4936 | { |
| 6124 | int len; | 4937 | int len; |
| 6125 | re_wchar_t c; | 4938 | int c; |
| 6126 | 4939 | ||
| 6127 | GET_CHAR_AFTER (c, d, len); | 4940 | GET_CHAR_AFTER (c, d, len); |
| 6128 | if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not) | 4941 | if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not) |
| @@ -6132,7 +4945,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6132 | } | 4945 | } |
| 6133 | break; | 4946 | break; |
| 6134 | 4947 | ||
| 6135 | #ifdef emacs | ||
| 6136 | case at_dot: | 4948 | case at_dot: |
| 6137 | DEBUG_PRINT ("EXECUTING at_dot.\n"); | 4949 | DEBUG_PRINT ("EXECUTING at_dot.\n"); |
| 6138 | if (PTR_BYTE_POS (d) != PT_BYTE) | 4950 | if (PTR_BYTE_POS (d) != PT_BYTE) |
| @@ -6142,7 +4954,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6142 | case categoryspec: | 4954 | case categoryspec: |
| 6143 | case notcategoryspec: | 4955 | case notcategoryspec: |
| 6144 | { | 4956 | { |
| 6145 | boolean not = (re_opcode_t) *(p - 1) == notcategoryspec; | 4957 | bool not = (re_opcode_t) *(p - 1) == notcategoryspec; |
| 6146 | mcnt = *p++; | 4958 | mcnt = *p++; |
| 6147 | DEBUG_PRINT ("EXECUTING %scategoryspec %d.\n", | 4959 | DEBUG_PRINT ("EXECUTING %scategoryspec %d.\n", |
| 6148 | not ? "not" : "", mcnt); | 4960 | not ? "not" : "", mcnt); |
| @@ -6150,7 +4962,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6150 | 4962 | ||
| 6151 | { | 4963 | { |
| 6152 | int len; | 4964 | int len; |
| 6153 | re_wchar_t c; | 4965 | int c; |
| 6154 | GET_CHAR_AFTER (c, d, len); | 4966 | GET_CHAR_AFTER (c, d, len); |
| 6155 | if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not) | 4967 | if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not) |
| 6156 | goto fail; | 4968 | goto fail; |
| @@ -6159,8 +4971,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6159 | } | 4971 | } |
| 6160 | break; | 4972 | break; |
| 6161 | 4973 | ||
| 6162 | #endif /* emacs */ | ||
| 6163 | |||
| 6164 | default: | 4974 | default: |
| 6165 | abort (); | 4975 | abort (); |
| 6166 | } | 4976 | } |
| @@ -6179,11 +4989,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6179 | switch (*pat++) | 4989 | switch (*pat++) |
| 6180 | { | 4990 | { |
| 6181 | case on_failure_keep_string_jump: | 4991 | case on_failure_keep_string_jump: |
| 6182 | assert (str == NULL); | 4992 | eassert (str == NULL); |
| 6183 | goto continue_failure_jump; | 4993 | goto continue_failure_jump; |
| 6184 | 4994 | ||
| 6185 | case on_failure_jump_nastyloop: | 4995 | case on_failure_jump_nastyloop: |
| 6186 | assert ((re_opcode_t)pat[-2] == no_op); | 4996 | eassert ((re_opcode_t)pat[-2] == no_op); |
| 6187 | PUSH_FAILURE_POINT (pat - 2, str); | 4997 | PUSH_FAILURE_POINT (pat - 2, str); |
| 6188 | FALLTHROUGH; | 4998 | FALLTHROUGH; |
| 6189 | case on_failure_jump_loop: | 4999 | case on_failure_jump_loop: |
| @@ -6203,7 +5013,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6203 | abort (); | 5013 | abort (); |
| 6204 | } | 5014 | } |
| 6205 | 5015 | ||
| 6206 | assert (p >= bufp->buffer && p <= pend); | 5016 | eassert (p >= bufp->buffer && p <= pend); |
| 6207 | 5017 | ||
| 6208 | if (d >= string1 && d <= end1) | 5018 | if (d >= string1 && d <= end1) |
| 6209 | dend = end_match_1; | 5019 | dend = end_match_1; |
| @@ -6215,9 +5025,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6215 | if (best_regs_set) | 5025 | if (best_regs_set) |
| 6216 | goto restore_best_regs; | 5026 | goto restore_best_regs; |
| 6217 | 5027 | ||
| 6218 | FREE_VARIABLES (); | 5028 | SAFE_FREE (); |
| 6219 | 5029 | ||
| 6220 | return -1; /* Failure to match. */ | 5030 | return -1; /* Failure to match. */ |
| 6221 | } | 5031 | } |
| 6222 | 5032 | ||
| 6223 | /* Subroutine definitions for re_match_2. */ | 5033 | /* Subroutine definitions for re_match_2. */ |
| @@ -6226,19 +5036,19 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1, | |||
| 6226 | bytes; nonzero otherwise. */ | 5036 | bytes; nonzero otherwise. */ |
| 6227 | 5037 | ||
| 6228 | static int | 5038 | static int |
| 6229 | bcmp_translate (re_char *s1, re_char *s2, ssize_t len, | 5039 | bcmp_translate (re_char *s1, re_char *s2, ptrdiff_t len, |
| 6230 | RE_TRANSLATE_TYPE translate, const int target_multibyte) | 5040 | Lisp_Object translate, int target_multibyte) |
| 6231 | { | 5041 | { |
| 6232 | re_char *p1 = s1, *p2 = s2; | 5042 | re_char *p1 = s1, *p2 = s2; |
| 6233 | re_char *p1_end = s1 + len; | 5043 | re_char *p1_end = s1 + len; |
| 6234 | re_char *p2_end = s2 + len; | 5044 | re_char *p2_end = s2 + len; |
| 6235 | 5045 | ||
| 6236 | /* FIXME: Checking both p1 and p2 presumes that the two strings might have | 5046 | /* FIXME: Checking both p1 and p2 presumes that the two strings might have |
| 6237 | different lengths, but relying on a single `len' would break this. -sm */ | 5047 | different lengths, but relying on a single LEN would break this. -sm */ |
| 6238 | while (p1 < p1_end && p2 < p2_end) | 5048 | while (p1 < p1_end && p2 < p2_end) |
| 6239 | { | 5049 | { |
| 6240 | int p1_charlen, p2_charlen; | 5050 | int p1_charlen, p2_charlen; |
| 6241 | re_wchar_t p1_ch, p2_ch; | 5051 | int p1_ch, p2_ch; |
| 6242 | 5052 | ||
| 6243 | GET_CHAR_AFTER (p1_ch, p1, p1_charlen); | 5053 | GET_CHAR_AFTER (p1_ch, p1, p1_charlen); |
| 6244 | GET_CHAR_AFTER (p2_ch, p2, p2_charlen); | 5054 | GET_CHAR_AFTER (p2_ch, p2, p2_charlen); |
| @@ -6262,16 +5072,14 @@ bcmp_translate (re_char *s1, re_char *s2, ssize_t len, | |||
| 6262 | compiles PATTERN (of length SIZE) and puts the result in BUFP. | 5072 | compiles PATTERN (of length SIZE) and puts the result in BUFP. |
| 6263 | Returns 0 if the pattern was valid, otherwise an error string. | 5073 | Returns 0 if the pattern was valid, otherwise an error string. |
| 6264 | 5074 | ||
| 6265 | Assumes the `allocated' (and perhaps `buffer') and `translate' fields | 5075 | Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields |
| 6266 | are set in BUFP on entry. | 5076 | are set in BUFP on entry. |
| 6267 | 5077 | ||
| 6268 | We call regex_compile to do the actual compilation. */ | 5078 | We call regex_compile to do the actual compilation. */ |
| 6269 | 5079 | ||
| 6270 | const char * | 5080 | const char * |
| 6271 | re_compile_pattern (const char *pattern, size_t length, | 5081 | re_compile_pattern (const char *pattern, size_t length, |
| 6272 | #ifdef emacs | ||
| 6273 | bool posix_backtracking, const char *whitespace_regexp, | 5082 | bool posix_backtracking, const char *whitespace_regexp, |
| 6274 | #endif | ||
| 6275 | struct re_pattern_buffer *bufp) | 5083 | struct re_pattern_buffer *bufp) |
| 6276 | { | 5084 | { |
| 6277 | reg_errcode_t ret; | 5085 | reg_errcode_t ret; |
| @@ -6280,335 +5088,12 @@ re_compile_pattern (const char *pattern, size_t length, | |||
| 6280 | (and at least one extra will be -1). */ | 5088 | (and at least one extra will be -1). */ |
| 6281 | bufp->regs_allocated = REGS_UNALLOCATED; | 5089 | bufp->regs_allocated = REGS_UNALLOCATED; |
| 6282 | 5090 | ||
| 6283 | /* And GNU code determines whether or not to get register information | ||
| 6284 | by passing null for the REGS argument to re_match, etc., not by | ||
| 6285 | setting no_sub. */ | ||
| 6286 | bufp->no_sub = 0; | ||
| 6287 | |||
| 6288 | ret = regex_compile ((re_char *) pattern, length, | 5091 | ret = regex_compile ((re_char *) pattern, length, |
| 6289 | #ifdef emacs | ||
| 6290 | posix_backtracking, | 5092 | posix_backtracking, |
| 6291 | whitespace_regexp, | 5093 | whitespace_regexp, |
| 6292 | #else | ||
| 6293 | re_syntax_options, | ||
| 6294 | #endif | ||
| 6295 | bufp); | 5094 | bufp); |
| 6296 | 5095 | ||
| 6297 | if (!ret) | 5096 | if (!ret) |
| 6298 | return NULL; | 5097 | return NULL; |
| 6299 | return gettext (re_error_msgid[(int) ret]); | 5098 | return re_error_msgid[ret]; |
| 6300 | } | ||
| 6301 | WEAK_ALIAS (__re_compile_pattern, re_compile_pattern) | ||
| 6302 | |||
| 6303 | /* Entry points compatible with 4.2 BSD regex library. We don't define | ||
| 6304 | them unless specifically requested. */ | ||
| 6305 | |||
| 6306 | #if defined _REGEX_RE_COMP || defined _LIBC | ||
| 6307 | |||
| 6308 | /* BSD has one and only one pattern buffer. */ | ||
| 6309 | static struct re_pattern_buffer re_comp_buf; | ||
| 6310 | |||
| 6311 | char * | ||
| 6312 | # ifdef _LIBC | ||
| 6313 | /* Make these definitions weak in libc, so POSIX programs can redefine | ||
| 6314 | these names if they don't use our functions, and still use | ||
| 6315 | regcomp/regexec below without link errors. */ | ||
| 6316 | weak_function | ||
| 6317 | # endif | ||
| 6318 | re_comp (const char *s) | ||
| 6319 | { | ||
| 6320 | reg_errcode_t ret; | ||
| 6321 | |||
| 6322 | if (!s) | ||
| 6323 | { | ||
| 6324 | if (!re_comp_buf.buffer) | ||
| 6325 | /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ | ||
| 6326 | return (char *) gettext ("No previous regular expression"); | ||
| 6327 | return 0; | ||
| 6328 | } | ||
| 6329 | |||
| 6330 | if (!re_comp_buf.buffer) | ||
| 6331 | { | ||
| 6332 | re_comp_buf.buffer = malloc (200); | ||
| 6333 | if (re_comp_buf.buffer == NULL) | ||
| 6334 | /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ | ||
| 6335 | return (char *) gettext (re_error_msgid[(int) REG_ESPACE]); | ||
| 6336 | re_comp_buf.allocated = 200; | ||
| 6337 | |||
| 6338 | re_comp_buf.fastmap = malloc (1 << BYTEWIDTH); | ||
| 6339 | if (re_comp_buf.fastmap == NULL) | ||
| 6340 | /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ | ||
| 6341 | return (char *) gettext (re_error_msgid[(int) REG_ESPACE]); | ||
| 6342 | } | ||
| 6343 | |||
| 6344 | /* Since `re_exec' always passes NULL for the `regs' argument, we | ||
| 6345 | don't need to initialize the pattern buffer fields which affect it. */ | ||
| 6346 | |||
| 6347 | ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); | ||
| 6348 | |||
| 6349 | if (!ret) | ||
| 6350 | return NULL; | ||
| 6351 | |||
| 6352 | /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ | ||
| 6353 | return (char *) gettext (re_error_msgid[(int) ret]); | ||
| 6354 | } | ||
| 6355 | |||
| 6356 | |||
| 6357 | int | ||
| 6358 | # ifdef _LIBC | ||
| 6359 | weak_function | ||
| 6360 | # endif | ||
| 6361 | re_exec (const char *s) | ||
| 6362 | { | ||
| 6363 | const size_t len = strlen (s); | ||
| 6364 | return re_search (&re_comp_buf, s, len, 0, len, 0) >= 0; | ||
| 6365 | } | ||
| 6366 | #endif /* _REGEX_RE_COMP */ | ||
| 6367 | |||
| 6368 | /* POSIX.2 functions. Don't define these for Emacs. */ | ||
| 6369 | |||
| 6370 | #ifndef emacs | ||
| 6371 | |||
| 6372 | /* regcomp takes a regular expression as a string and compiles it. | ||
| 6373 | |||
| 6374 | PREG is a regex_t *. We do not expect any fields to be initialized, | ||
| 6375 | since POSIX says we shouldn't. Thus, we set | ||
| 6376 | |||
| 6377 | `buffer' to the compiled pattern; | ||
| 6378 | `used' to the length of the compiled pattern; | ||
| 6379 | `syntax' to RE_SYNTAX_POSIX_EXTENDED if the | ||
| 6380 | REG_EXTENDED bit in CFLAGS is set; otherwise, to | ||
| 6381 | RE_SYNTAX_POSIX_BASIC; | ||
| 6382 | `fastmap' to an allocated space for the fastmap; | ||
| 6383 | `fastmap_accurate' to zero; | ||
| 6384 | `re_nsub' to the number of subexpressions in PATTERN. | ||
| 6385 | |||
| 6386 | PATTERN is the address of the pattern string. | ||
| 6387 | |||
| 6388 | CFLAGS is a series of bits which affect compilation. | ||
| 6389 | |||
| 6390 | If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we | ||
| 6391 | use POSIX basic syntax. | ||
| 6392 | |||
| 6393 | If REG_NEWLINE is set, then . and [^...] don't match newline. | ||
| 6394 | Also, regexec will try a match beginning after every newline. | ||
| 6395 | |||
| 6396 | If REG_ICASE is set, then we considers upper- and lowercase | ||
| 6397 | versions of letters to be equivalent when matching. | ||
| 6398 | |||
| 6399 | If REG_NOSUB is set, then when PREG is passed to regexec, that | ||
| 6400 | routine will report only success or failure, and nothing about the | ||
| 6401 | registers. | ||
| 6402 | |||
| 6403 | It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for | ||
| 6404 | the return codes and their meanings.) */ | ||
| 6405 | |||
| 6406 | reg_errcode_t | ||
| 6407 | regcomp (regex_t *_Restrict_ preg, const char *_Restrict_ pattern, | ||
| 6408 | int cflags) | ||
| 6409 | { | ||
| 6410 | reg_errcode_t ret; | ||
| 6411 | reg_syntax_t syntax | ||
| 6412 | = (cflags & REG_EXTENDED) ? | ||
| 6413 | RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; | ||
| 6414 | |||
| 6415 | /* regex_compile will allocate the space for the compiled pattern. */ | ||
| 6416 | preg->buffer = 0; | ||
| 6417 | preg->allocated = 0; | ||
| 6418 | preg->used = 0; | ||
| 6419 | |||
| 6420 | /* Try to allocate space for the fastmap. */ | ||
| 6421 | preg->fastmap = malloc (1 << BYTEWIDTH); | ||
| 6422 | |||
| 6423 | if (cflags & REG_ICASE) | ||
| 6424 | { | ||
| 6425 | unsigned i; | ||
| 6426 | |||
| 6427 | preg->translate = malloc (CHAR_SET_SIZE * sizeof *preg->translate); | ||
| 6428 | if (preg->translate == NULL) | ||
| 6429 | return (int) REG_ESPACE; | ||
| 6430 | |||
| 6431 | /* Map uppercase characters to corresponding lowercase ones. */ | ||
| 6432 | for (i = 0; i < CHAR_SET_SIZE; i++) | ||
| 6433 | preg->translate[i] = ISUPPER (i) ? TOLOWER (i) : i; | ||
| 6434 | } | ||
| 6435 | else | ||
| 6436 | preg->translate = NULL; | ||
| 6437 | |||
| 6438 | /* If REG_NEWLINE is set, newlines are treated differently. */ | ||
| 6439 | if (cflags & REG_NEWLINE) | ||
| 6440 | { /* REG_NEWLINE implies neither . nor [^...] match newline. */ | ||
| 6441 | syntax &= ~RE_DOT_NEWLINE; | ||
| 6442 | syntax |= RE_HAT_LISTS_NOT_NEWLINE; | ||
| 6443 | } | ||
| 6444 | else | ||
| 6445 | syntax |= RE_NO_NEWLINE_ANCHOR; | ||
| 6446 | |||
| 6447 | preg->no_sub = !!(cflags & REG_NOSUB); | ||
| 6448 | |||
| 6449 | /* POSIX says a null character in the pattern terminates it, so we | ||
| 6450 | can use strlen here in compiling the pattern. */ | ||
| 6451 | ret = regex_compile ((re_char *) pattern, strlen (pattern), syntax, preg); | ||
| 6452 | |||
| 6453 | /* POSIX doesn't distinguish between an unmatched open-group and an | ||
| 6454 | unmatched close-group: both are REG_EPAREN. */ | ||
| 6455 | if (ret == REG_ERPAREN) | ||
| 6456 | ret = REG_EPAREN; | ||
| 6457 | |||
| 6458 | if (ret == REG_NOERROR && preg->fastmap) | ||
| 6459 | { /* Compute the fastmap now, since regexec cannot modify the pattern | ||
| 6460 | buffer. */ | ||
| 6461 | re_compile_fastmap (preg); | ||
| 6462 | if (preg->can_be_null) | ||
| 6463 | { /* The fastmap can't be used anyway. */ | ||
| 6464 | free (preg->fastmap); | ||
| 6465 | preg->fastmap = NULL; | ||
| 6466 | } | ||
| 6467 | } | ||
| 6468 | return ret; | ||
| 6469 | } | 5099 | } |
| 6470 | WEAK_ALIAS (__regcomp, regcomp) | ||
| 6471 | |||
| 6472 | |||
| 6473 | /* regexec searches for a given pattern, specified by PREG, in the | ||
| 6474 | string STRING. | ||
| 6475 | |||
| 6476 | If NMATCH is zero or REG_NOSUB was set in the cflags argument to | ||
| 6477 | `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at | ||
| 6478 | least NMATCH elements, and we set them to the offsets of the | ||
| 6479 | corresponding matched substrings. | ||
| 6480 | |||
| 6481 | EFLAGS specifies `execution flags' which affect matching: if | ||
| 6482 | REG_NOTBOL is set, then ^ does not match at the beginning of the | ||
| 6483 | string; if REG_NOTEOL is set, then $ does not match at the end. | ||
| 6484 | |||
| 6485 | We return 0 if we find a match and REG_NOMATCH if not. */ | ||
| 6486 | |||
| 6487 | reg_errcode_t | ||
| 6488 | regexec (const regex_t *_Restrict_ preg, const char *_Restrict_ string, | ||
| 6489 | size_t nmatch, regmatch_t pmatch[_Restrict_arr_], int eflags) | ||
| 6490 | { | ||
| 6491 | regoff_t ret; | ||
| 6492 | struct re_registers regs; | ||
| 6493 | regex_t private_preg; | ||
| 6494 | size_t len = strlen (string); | ||
| 6495 | boolean want_reg_info = !preg->no_sub && nmatch > 0 && pmatch; | ||
| 6496 | |||
| 6497 | private_preg = *preg; | ||
| 6498 | |||
| 6499 | private_preg.not_bol = !!(eflags & REG_NOTBOL); | ||
| 6500 | private_preg.not_eol = !!(eflags & REG_NOTEOL); | ||
| 6501 | |||
| 6502 | /* The user has told us exactly how many registers to return | ||
| 6503 | information about, via `nmatch'. We have to pass that on to the | ||
| 6504 | matching routines. */ | ||
| 6505 | private_preg.regs_allocated = REGS_FIXED; | ||
| 6506 | |||
| 6507 | if (want_reg_info) | ||
| 6508 | { | ||
| 6509 | regs.num_regs = nmatch; | ||
| 6510 | regs.start = TALLOC (nmatch * 2, regoff_t); | ||
| 6511 | if (regs.start == NULL) | ||
| 6512 | return REG_NOMATCH; | ||
| 6513 | regs.end = regs.start + nmatch; | ||
| 6514 | } | ||
| 6515 | |||
| 6516 | /* Instead of using not_eol to implement REG_NOTEOL, we could simply | ||
| 6517 | pass (&private_preg, string, len + 1, 0, len, ...) pretending the string | ||
| 6518 | was a little bit longer but still only matching the real part. | ||
| 6519 | This works because the `endline' will check for a '\n' and will find a | ||
| 6520 | '\0', correctly deciding that this is not the end of a line. | ||
| 6521 | But it doesn't work out so nicely for REG_NOTBOL, since we don't have | ||
| 6522 | a convenient '\0' there. For all we know, the string could be preceded | ||
| 6523 | by '\n' which would throw things off. */ | ||
| 6524 | |||
| 6525 | /* Perform the searching operation. */ | ||
| 6526 | ret = re_search (&private_preg, string, len, | ||
| 6527 | /* start: */ 0, /* range: */ len, | ||
| 6528 | want_reg_info ? ®s : 0); | ||
| 6529 | |||
| 6530 | /* Copy the register information to the POSIX structure. */ | ||
| 6531 | if (want_reg_info) | ||
| 6532 | { | ||
| 6533 | if (ret >= 0) | ||
| 6534 | { | ||
| 6535 | unsigned r; | ||
| 6536 | |||
| 6537 | for (r = 0; r < nmatch; r++) | ||
| 6538 | { | ||
| 6539 | pmatch[r].rm_so = regs.start[r]; | ||
| 6540 | pmatch[r].rm_eo = regs.end[r]; | ||
| 6541 | } | ||
| 6542 | } | ||
| 6543 | |||
| 6544 | /* If we needed the temporary register info, free the space now. */ | ||
| 6545 | free (regs.start); | ||
| 6546 | } | ||
| 6547 | |||
| 6548 | /* We want zero return to mean success, unlike `re_search'. */ | ||
| 6549 | return ret >= 0 ? REG_NOERROR : REG_NOMATCH; | ||
| 6550 | } | ||
| 6551 | WEAK_ALIAS (__regexec, regexec) | ||
| 6552 | |||
| 6553 | |||
| 6554 | /* Returns a message corresponding to an error code, ERR_CODE, returned | ||
| 6555 | from either regcomp or regexec. We don't use PREG here. | ||
| 6556 | |||
| 6557 | ERR_CODE was previously called ERRCODE, but that name causes an | ||
| 6558 | error with msvc8 compiler. */ | ||
| 6559 | |||
| 6560 | size_t | ||
| 6561 | regerror (int err_code, const regex_t *preg, char *errbuf, size_t errbuf_size) | ||
| 6562 | { | ||
| 6563 | const char *msg; | ||
| 6564 | size_t msg_size; | ||
| 6565 | |||
| 6566 | if (err_code < 0 | ||
| 6567 | || err_code >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) | ||
| 6568 | /* Only error codes returned by the rest of the code should be passed | ||
| 6569 | to this routine. If we are given anything else, or if other regex | ||
| 6570 | code generates an invalid error code, then the program has a bug. | ||
| 6571 | Dump core so we can fix it. */ | ||
| 6572 | abort (); | ||
| 6573 | |||
| 6574 | msg = gettext (re_error_msgid[err_code]); | ||
| 6575 | |||
| 6576 | msg_size = strlen (msg) + 1; /* Includes the null. */ | ||
| 6577 | |||
| 6578 | if (errbuf_size != 0) | ||
| 6579 | { | ||
| 6580 | if (msg_size > errbuf_size) | ||
| 6581 | { | ||
| 6582 | memcpy (errbuf, msg, errbuf_size - 1); | ||
| 6583 | errbuf[errbuf_size - 1] = 0; | ||
| 6584 | } | ||
| 6585 | else | ||
| 6586 | strcpy (errbuf, msg); | ||
| 6587 | } | ||
| 6588 | |||
| 6589 | return msg_size; | ||
| 6590 | } | ||
| 6591 | WEAK_ALIAS (__regerror, regerror) | ||
| 6592 | |||
| 6593 | |||
| 6594 | /* Free dynamically allocated space used by PREG. */ | ||
| 6595 | |||
| 6596 | void | ||
| 6597 | regfree (regex_t *preg) | ||
| 6598 | { | ||
| 6599 | free (preg->buffer); | ||
| 6600 | preg->buffer = NULL; | ||
| 6601 | |||
| 6602 | preg->allocated = 0; | ||
| 6603 | preg->used = 0; | ||
| 6604 | |||
| 6605 | free (preg->fastmap); | ||
| 6606 | preg->fastmap = NULL; | ||
| 6607 | preg->fastmap_accurate = 0; | ||
| 6608 | |||
| 6609 | free (preg->translate); | ||
| 6610 | preg->translate = NULL; | ||
| 6611 | } | ||
| 6612 | WEAK_ALIAS (__regfree, regfree) | ||
| 6613 | |||
| 6614 | #endif /* not emacs */ | ||
diff --git a/src/regex-emacs.h b/src/regex-emacs.h new file mode 100644 index 00000000000..a849cbea054 --- /dev/null +++ b/src/regex-emacs.h | |||
| @@ -0,0 +1,197 @@ | |||
| 1 | /* Emacs regular expression API | ||
| 2 | |||
| 3 | Copyright (C) 1985, 1989-1993, 1995, 2000-2018 Free Software | ||
| 4 | Foundation, Inc. | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3, or (at your option) | ||
| 9 | any later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #ifndef EMACS_REGEX_H | ||
| 20 | #define EMACS_REGEX_H 1 | ||
| 21 | |||
| 22 | #include <stddef.h> | ||
| 23 | |||
| 24 | /* This is the structure we store register match data in. | ||
| 25 | Declare this before including lisp.h, since lisp.h (via thread.h) | ||
| 26 | uses struct re_registers. */ | ||
| 27 | struct re_registers | ||
| 28 | { | ||
| 29 | unsigned num_regs; | ||
| 30 | ptrdiff_t *start; | ||
| 31 | ptrdiff_t *end; | ||
| 32 | }; | ||
| 33 | |||
| 34 | #include "lisp.h" | ||
| 35 | |||
| 36 | /* The string or buffer being matched. | ||
| 37 | It is used for looking up syntax properties. | ||
| 38 | |||
| 39 | If the value is a Lisp string object, match text in that string; if | ||
| 40 | it's nil, match text in the current buffer; if it's t, match text | ||
| 41 | in a C string. | ||
| 42 | |||
| 43 | This value is effectively another parameter to re_search_2 and | ||
| 44 | re_match_2. No calls into Lisp or thread switches are allowed | ||
| 45 | before setting re_match_object and calling into the regex search | ||
| 46 | and match functions. These functions capture the current value of | ||
| 47 | re_match_object into gl_state on entry. | ||
| 48 | |||
| 49 | TODO: turn into an actual function parameter. */ | ||
| 50 | extern Lisp_Object re_match_object; | ||
| 51 | |||
| 52 | /* Roughly the maximum number of failure points on the stack. */ | ||
| 53 | extern size_t emacs_re_max_failures; | ||
| 54 | |||
| 55 | /* Amount of memory that we can safely stack allocate. */ | ||
| 56 | extern ptrdiff_t emacs_re_safe_alloca; | ||
| 57 | |||
| 58 | /* This data structure represents a compiled pattern. Before calling | ||
| 59 | the pattern compiler, the fields 'buffer', 'allocated', 'fastmap', | ||
| 60 | and 'translate' can be set. After the pattern has been | ||
| 61 | compiled, the 're_nsub' field is available. All other fields are | ||
| 62 | private to the regex routines. */ | ||
| 63 | |||
| 64 | struct re_pattern_buffer | ||
| 65 | { | ||
| 66 | /* Space that holds the compiled pattern. It is declared as | ||
| 67 | 'unsigned char *' because its elements are | ||
| 68 | sometimes used as array indexes. */ | ||
| 69 | unsigned char *buffer; | ||
| 70 | |||
| 71 | /* Number of bytes to which 'buffer' points. */ | ||
| 72 | size_t allocated; | ||
| 73 | |||
| 74 | /* Number of bytes actually used in 'buffer'. */ | ||
| 75 | size_t used; | ||
| 76 | |||
| 77 | /* Charset of unibyte characters at compiling time. */ | ||
| 78 | int charset_unibyte; | ||
| 79 | |||
| 80 | /* Pointer to a fastmap, if any, otherwise zero. re_search uses | ||
| 81 | the fastmap, if there is one, to skip over impossible | ||
| 82 | starting points for matches. */ | ||
| 83 | char *fastmap; | ||
| 84 | |||
| 85 | /* Either a translate table to apply to all characters before | ||
| 86 | comparing them, or zero for no translation. The translation | ||
| 87 | applies to a pattern when it is compiled and to a string | ||
| 88 | when it is matched. */ | ||
| 89 | Lisp_Object translate; | ||
| 90 | |||
| 91 | /* Number of subexpressions found by the compiler. */ | ||
| 92 | size_t re_nsub; | ||
| 93 | |||
| 94 | /* True if and only if this pattern can match the empty string. | ||
| 95 | Well, in truth it's used only in 're_search_2', to see | ||
| 96 | whether or not we should use the fastmap, so we don't set | ||
| 97 | this absolutely perfectly; see 're_compile_fastmap'. */ | ||
| 98 | unsigned can_be_null : 1; | ||
| 99 | |||
| 100 | /* If REGS_UNALLOCATED, allocate space in the 'regs' structure | ||
| 101 | for 'max (RE_NREGS, re_nsub + 1)' groups. | ||
| 102 | If REGS_REALLOCATE, reallocate space if necessary. | ||
| 103 | If REGS_FIXED, use what's there. */ | ||
| 104 | unsigned regs_allocated : 2; | ||
| 105 | |||
| 106 | /* Set to false when 'regex_compile' compiles a pattern; set to true | ||
| 107 | by 're_compile_fastmap' if it updates the fastmap. */ | ||
| 108 | unsigned fastmap_accurate : 1; | ||
| 109 | |||
| 110 | /* If true, the compilation of the pattern had to look up the syntax table, | ||
| 111 | so the compiled pattern is valid for the current syntax table only. */ | ||
| 112 | unsigned used_syntax : 1; | ||
| 113 | |||
| 114 | /* If true, multi-byte form in the regexp pattern should be | ||
| 115 | recognized as a multibyte character. */ | ||
| 116 | unsigned multibyte : 1; | ||
| 117 | |||
| 118 | /* If true, multi-byte form in the target of match should be | ||
| 119 | recognized as a multibyte character. */ | ||
| 120 | unsigned target_multibyte : 1; | ||
| 121 | }; | ||
| 122 | |||
| 123 | /* Declarations for routines. */ | ||
| 124 | |||
| 125 | /* Compile the regular expression PATTERN, with length LENGTH | ||
| 126 | and syntax given by the global 're_syntax_options', into the buffer | ||
| 127 | BUFFER. Return NULL if successful, and an error string if not. */ | ||
| 128 | extern const char *re_compile_pattern (const char *pattern, size_t length, | ||
| 129 | bool posix_backtracking, | ||
| 130 | const char *whitespace_regexp, | ||
| 131 | struct re_pattern_buffer *buffer); | ||
| 132 | |||
| 133 | |||
| 134 | /* Search in the string STRING (with length LENGTH) for the pattern | ||
| 135 | compiled into BUFFER. Start searching at position START, for RANGE | ||
| 136 | characters. Return the starting position of the match, -1 for no | ||
| 137 | match, or -2 for an internal error. Also return register | ||
| 138 | information in REGS (if REGS is non-null). */ | ||
| 139 | extern ptrdiff_t re_search (struct re_pattern_buffer *buffer, | ||
| 140 | const char *string, size_t length, | ||
| 141 | ptrdiff_t start, ptrdiff_t range, | ||
| 142 | struct re_registers *regs); | ||
| 143 | |||
| 144 | |||
| 145 | /* Like 're_search', but search in the concatenation of STRING1 and | ||
| 146 | STRING2. Also, stop searching at index START + STOP. */ | ||
| 147 | extern ptrdiff_t re_search_2 (struct re_pattern_buffer *buffer, | ||
| 148 | const char *string1, size_t length1, | ||
| 149 | const char *string2, size_t length2, | ||
| 150 | ptrdiff_t start, ptrdiff_t range, | ||
| 151 | struct re_registers *regs, | ||
| 152 | ptrdiff_t stop); | ||
| 153 | |||
| 154 | |||
| 155 | /* Like 're_search_2', but return how many characters in STRING the regexp | ||
| 156 | in BUFFER matched, starting at position START. */ | ||
| 157 | extern ptrdiff_t re_match_2 (struct re_pattern_buffer *buffer, | ||
| 158 | const char *string1, size_t length1, | ||
| 159 | const char *string2, size_t length2, | ||
| 160 | ptrdiff_t start, struct re_registers *regs, | ||
| 161 | ptrdiff_t stop); | ||
| 162 | |||
| 163 | |||
| 164 | /* Set REGS to hold NUM_REGS registers, storing them in STARTS and | ||
| 165 | ENDS. Subsequent matches using BUFFER and REGS will use this memory | ||
| 166 | for recording register information. STARTS and ENDS must be | ||
| 167 | allocated with malloc, and must each be at least 'NUM_REGS * sizeof | ||
| 168 | (ptrdiff_t)' bytes long. | ||
| 169 | |||
| 170 | If NUM_REGS == 0, then subsequent matches should allocate their own | ||
| 171 | register data. | ||
| 172 | |||
| 173 | Unless this function is called, the first search or match using | ||
| 174 | PATTERN_BUFFER will allocate its own register data, without | ||
| 175 | freeing the old data. */ | ||
| 176 | extern void re_set_registers (struct re_pattern_buffer *buffer, | ||
| 177 | struct re_registers *regs, | ||
| 178 | unsigned num_regs, | ||
| 179 | ptrdiff_t *starts, ptrdiff_t *ends); | ||
| 180 | |||
| 181 | /* Character classes. */ | ||
| 182 | typedef enum { RECC_ERROR = 0, | ||
| 183 | RECC_ALNUM, RECC_ALPHA, RECC_WORD, | ||
| 184 | RECC_GRAPH, RECC_PRINT, | ||
| 185 | RECC_LOWER, RECC_UPPER, | ||
| 186 | RECC_PUNCT, RECC_CNTRL, | ||
| 187 | RECC_DIGIT, RECC_XDIGIT, | ||
| 188 | RECC_BLANK, RECC_SPACE, | ||
| 189 | RECC_MULTIBYTE, RECC_NONASCII, | ||
| 190 | RECC_ASCII, RECC_UNIBYTE | ||
| 191 | } re_wctype_t; | ||
| 192 | |||
| 193 | extern bool re_iswctype (int ch, re_wctype_t cc); | ||
| 194 | extern re_wctype_t re_wctype_parse (const unsigned char **strp, | ||
| 195 | unsigned limit); | ||
| 196 | |||
| 197 | #endif /* EMACS_REGEX_H */ | ||
diff --git a/src/regex.h b/src/regex.h deleted file mode 100644 index 3a2d74d86a1..00000000000 --- a/src/regex.h +++ /dev/null | |||
| @@ -1,654 +0,0 @@ | |||
| 1 | /* Definitions for data structures and routines for the regular | ||
| 2 | expression library, version 0.12. | ||
| 3 | |||
| 4 | Copyright (C) 1985, 1989-1993, 1995, 2000-2018 Free Software | ||
| 5 | Foundation, Inc. | ||
| 6 | |||
| 7 | This program is free software; you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation; either version 3, or (at your option) | ||
| 10 | any later version. | ||
| 11 | |||
| 12 | This program is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | #ifndef _REGEX_H | ||
| 21 | #define _REGEX_H 1 | ||
| 22 | |||
| 23 | #if defined emacs && (defined _REGEX_RE_COMP || defined _LIBC) | ||
| 24 | /* We're not defining re_set_syntax and using a different prototype of | ||
| 25 | re_compile_pattern when building Emacs so fail compilation early with | ||
| 26 | a (somewhat helpful) error message when conflict is detected. */ | ||
| 27 | # error "_REGEX_RE_COMP nor _LIBC can be defined if emacs is defined." | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include <sys/types.h> | ||
| 31 | |||
| 32 | /* Allow the use in C++ code. */ | ||
| 33 | #ifdef __cplusplus | ||
| 34 | extern "C" { | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS | ||
| 38 | /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it | ||
| 39 | should be there. */ | ||
| 40 | # include <stddef.h> | ||
| 41 | #endif | ||
| 42 | |||
| 43 | /* The following bits are used to determine the regexp syntax we | ||
| 44 | recognize. The set/not-set meanings where historically chosen so | ||
| 45 | that Emacs syntax had the value 0. | ||
| 46 | The bits are given in alphabetical order, and | ||
| 47 | the definitions shifted by one from the previous bit; thus, when we | ||
| 48 | add or remove a bit, only one other definition need change. */ | ||
| 49 | typedef unsigned long reg_syntax_t; | ||
| 50 | |||
| 51 | /* If this bit is not set, then \ inside a bracket expression is literal. | ||
| 52 | If set, then such a \ quotes the following character. */ | ||
| 53 | #define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) | ||
| 54 | |||
| 55 | /* If this bit is not set, then + and ? are operators, and \+ and \? are | ||
| 56 | literals. | ||
| 57 | If set, then \+ and \? are operators and + and ? are literals. */ | ||
| 58 | #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) | ||
| 59 | |||
| 60 | /* If this bit is set, then character classes are supported. They are: | ||
| 61 | [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], | ||
| 62 | [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. | ||
| 63 | If not set, then character classes are not supported. */ | ||
| 64 | #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) | ||
| 65 | |||
| 66 | /* If this bit is set, then ^ and $ are always anchors (outside bracket | ||
| 67 | expressions, of course). | ||
| 68 | If this bit is not set, then it depends: | ||
| 69 | ^ is an anchor if it is at the beginning of a regular | ||
| 70 | expression or after an open-group or an alternation operator; | ||
| 71 | $ is an anchor if it is at the end of a regular expression, or | ||
| 72 | before a close-group or an alternation operator. | ||
| 73 | |||
| 74 | This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because | ||
| 75 | POSIX draft 11.2 says that * etc. in leading positions is undefined. | ||
| 76 | We already implemented a previous draft which made those constructs | ||
| 77 | invalid, though, so we haven't changed the code back. */ | ||
| 78 | #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) | ||
| 79 | |||
| 80 | /* If this bit is set, then special characters are always special | ||
| 81 | regardless of where they are in the pattern. | ||
| 82 | If this bit is not set, then special characters are special only in | ||
| 83 | some contexts; otherwise they are ordinary. Specifically, | ||
| 84 | * + ? and intervals are only special when not after the beginning, | ||
| 85 | open-group, or alternation operator. */ | ||
| 86 | #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) | ||
| 87 | |||
| 88 | /* If this bit is set, then *, +, ?, and { cannot be first in an re or | ||
| 89 | immediately after an alternation or begin-group operator. */ | ||
| 90 | #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) | ||
| 91 | |||
| 92 | /* If this bit is set, then . matches newline. | ||
| 93 | If not set, then it doesn't. */ | ||
| 94 | #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) | ||
| 95 | |||
| 96 | /* If this bit is set, then . doesn't match NUL. | ||
| 97 | If not set, then it does. */ | ||
| 98 | #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) | ||
| 99 | |||
| 100 | /* If this bit is set, nonmatching lists [^...] do not match newline. | ||
| 101 | If not set, they do. */ | ||
| 102 | #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) | ||
| 103 | |||
| 104 | /* If this bit is set, either \{...\} or {...} defines an | ||
| 105 | interval, depending on RE_NO_BK_BRACES. | ||
| 106 | If not set, \{, \}, {, and } are literals. */ | ||
| 107 | #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) | ||
| 108 | |||
| 109 | /* If this bit is set, +, ? and | aren't recognized as operators. | ||
| 110 | If not set, they are. */ | ||
| 111 | #define RE_LIMITED_OPS (RE_INTERVALS << 1) | ||
| 112 | |||
| 113 | /* If this bit is set, newline is an alternation operator. | ||
| 114 | If not set, newline is literal. */ | ||
| 115 | #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) | ||
| 116 | |||
| 117 | /* If this bit is set, then `{...}' defines an interval, and \{ and \} | ||
| 118 | are literals. | ||
| 119 | If not set, then `\{...\}' defines an interval. */ | ||
| 120 | #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) | ||
| 121 | |||
| 122 | /* If this bit is set, (...) defines a group, and \( and \) are literals. | ||
| 123 | If not set, \(...\) defines a group, and ( and ) are literals. */ | ||
| 124 | #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) | ||
| 125 | |||
| 126 | /* If this bit is set, then \<digit> matches <digit>. | ||
| 127 | If not set, then \<digit> is a back-reference. */ | ||
| 128 | #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) | ||
| 129 | |||
| 130 | /* If this bit is set, then | is an alternation operator, and \| is literal. | ||
| 131 | If not set, then \| is an alternation operator, and | is literal. */ | ||
| 132 | #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) | ||
| 133 | |||
| 134 | /* If this bit is set, then an ending range point collating higher | ||
| 135 | than the starting range point, as in [z-a], is invalid. | ||
| 136 | If not set, then when ending range point collates higher than the | ||
| 137 | starting range point, the range is ignored. */ | ||
| 138 | #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) | ||
| 139 | |||
| 140 | /* If this bit is set, then an unmatched ) is ordinary. | ||
| 141 | If not set, then an unmatched ) is invalid. */ | ||
| 142 | #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) | ||
| 143 | |||
| 144 | /* If this bit is set, succeed as soon as we match the whole pattern, | ||
| 145 | without further backtracking. */ | ||
| 146 | #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) | ||
| 147 | |||
| 148 | /* If this bit is set, do not process the GNU regex operators. | ||
| 149 | If not set, then the GNU regex operators are recognized. */ | ||
| 150 | #define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) | ||
| 151 | |||
| 152 | /* If this bit is set, then *?, +? and ?? match non greedily. */ | ||
| 153 | #define RE_FRUGAL (RE_NO_GNU_OPS << 1) | ||
| 154 | |||
| 155 | /* If this bit is set, then (?:...) is treated as a shy group. */ | ||
| 156 | #define RE_SHY_GROUPS (RE_FRUGAL << 1) | ||
| 157 | |||
| 158 | /* If this bit is set, ^ and $ only match at beg/end of buffer. */ | ||
| 159 | #define RE_NO_NEWLINE_ANCHOR (RE_SHY_GROUPS << 1) | ||
| 160 | |||
| 161 | /* If this bit is set, turn on internal regex debugging. | ||
| 162 | If not set, and debugging was on, turn it off. | ||
| 163 | This only works if regex.c is compiled -DDEBUG. | ||
| 164 | We define this bit always, so that all that's needed to turn on | ||
| 165 | debugging is to recompile regex.c; the calling code can always have | ||
| 166 | this bit set, and it won't affect anything in the normal case. */ | ||
| 167 | #define RE_DEBUG (RE_NO_NEWLINE_ANCHOR << 1) | ||
| 168 | |||
| 169 | /* This global variable defines the particular regexp syntax to use (for | ||
| 170 | some interfaces). When a regexp is compiled, the syntax used is | ||
| 171 | stored in the pattern buffer, so changing this does not affect | ||
| 172 | already-compiled regexps. */ | ||
| 173 | /* extern reg_syntax_t re_syntax_options; */ | ||
| 174 | |||
| 175 | #ifdef emacs | ||
| 176 | # include "lisp.h" | ||
| 177 | /* In Emacs, this is the string or buffer in which we are matching. | ||
| 178 | It is used for looking up syntax properties. | ||
| 179 | |||
| 180 | If the value is a Lisp string object, we are matching text in that | ||
| 181 | string; if it's nil, we are matching text in the current buffer; if | ||
| 182 | it's t, we are matching text in a C string. | ||
| 183 | |||
| 184 | This value is effectively another parameter to re_search_2 and | ||
| 185 | re_match_2. No calls into Lisp or thread switches are allowed | ||
| 186 | before setting re_match_object and calling into the regex search | ||
| 187 | and match functions. These functions capture the current value of | ||
| 188 | re_match_object into gl_state on entry. | ||
| 189 | |||
| 190 | TODO: once we get rid of the !emacs case in this code, turn into an | ||
| 191 | actual function parameter. */ | ||
| 192 | extern Lisp_Object re_match_object; | ||
| 193 | #endif | ||
| 194 | |||
| 195 | /* Roughly the maximum number of failure points on the stack. */ | ||
| 196 | extern size_t emacs_re_max_failures; | ||
| 197 | |||
| 198 | #ifdef emacs | ||
| 199 | /* Amount of memory that we can safely stack allocate. */ | ||
| 200 | extern ptrdiff_t emacs_re_safe_alloca; | ||
| 201 | #endif | ||
| 202 | |||
| 203 | |||
| 204 | /* Define combinations of the above bits for the standard possibilities. | ||
| 205 | (The [[[ comments delimit what gets put into the Texinfo file, so | ||
| 206 | don't delete them!) */ | ||
| 207 | /* [[[begin syntaxes]]] */ | ||
| 208 | #define RE_SYNTAX_EMACS \ | ||
| 209 | (RE_CHAR_CLASSES | RE_INTERVALS | RE_SHY_GROUPS | RE_FRUGAL) | ||
| 210 | |||
| 211 | #define RE_SYNTAX_AWK \ | ||
| 212 | (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ | ||
| 213 | | RE_NO_BK_PARENS | RE_NO_BK_REFS \ | ||
| 214 | | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ | ||
| 215 | | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ | ||
| 216 | | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) | ||
| 217 | |||
| 218 | #define RE_SYNTAX_GNU_AWK \ | ||
| 219 | ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ | ||
| 220 | & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS)) | ||
| 221 | |||
| 222 | #define RE_SYNTAX_POSIX_AWK \ | ||
| 223 | (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ | ||
| 224 | | RE_INTERVALS | RE_NO_GNU_OPS) | ||
| 225 | |||
| 226 | #define RE_SYNTAX_GREP \ | ||
| 227 | (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ | ||
| 228 | | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ | ||
| 229 | | RE_NEWLINE_ALT) | ||
| 230 | |||
| 231 | #define RE_SYNTAX_EGREP \ | ||
| 232 | (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ | ||
| 233 | | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ | ||
| 234 | | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ | ||
| 235 | | RE_NO_BK_VBAR) | ||
| 236 | |||
| 237 | #define RE_SYNTAX_POSIX_EGREP \ | ||
| 238 | (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) | ||
| 239 | |||
| 240 | /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ | ||
| 241 | #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC | ||
| 242 | |||
| 243 | #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC | ||
| 244 | |||
| 245 | /* Syntax bits common to both basic and extended POSIX regex syntax. */ | ||
| 246 | #define _RE_SYNTAX_POSIX_COMMON \ | ||
| 247 | (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ | ||
| 248 | | RE_INTERVALS | RE_NO_EMPTY_RANGES) | ||
| 249 | |||
| 250 | #define RE_SYNTAX_POSIX_BASIC \ | ||
| 251 | (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) | ||
| 252 | |||
| 253 | /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes | ||
| 254 | RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this | ||
| 255 | isn't minimal, since other operators, such as \`, aren't disabled. */ | ||
| 256 | #define RE_SYNTAX_POSIX_MINIMAL_BASIC \ | ||
| 257 | (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) | ||
| 258 | |||
| 259 | #define RE_SYNTAX_POSIX_EXTENDED \ | ||
| 260 | (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ | ||
| 261 | | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ | ||
| 262 | | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ | ||
| 263 | | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) | ||
| 264 | |||
| 265 | /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is | ||
| 266 | removed and RE_NO_BK_REFS is added. */ | ||
| 267 | #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ | ||
| 268 | (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ | ||
| 269 | | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ | ||
| 270 | | RE_NO_BK_PARENS | RE_NO_BK_REFS \ | ||
| 271 | | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) | ||
| 272 | /* [[[end syntaxes]]] */ | ||
| 273 | |||
| 274 | /* Maximum number of duplicates an interval can allow. Some systems | ||
| 275 | (erroneously) define this in other header files, but we want our | ||
| 276 | value, so remove any previous define. */ | ||
| 277 | #ifdef RE_DUP_MAX | ||
| 278 | # undef RE_DUP_MAX | ||
| 279 | #endif | ||
| 280 | /* Repeat counts are stored in opcodes as 2 byte integers. This was | ||
| 281 | previously limited to 7fff because the parsing code uses signed | ||
| 282 | ints. But Emacs only runs on 32 bit platforms anyway. */ | ||
| 283 | #define RE_DUP_MAX (0xffff) | ||
| 284 | |||
| 285 | |||
| 286 | /* POSIX `cflags' bits (i.e., information for `regcomp'). */ | ||
| 287 | |||
| 288 | /* If this bit is set, then use extended regular expression syntax. | ||
| 289 | If not set, then use basic regular expression syntax. */ | ||
| 290 | #define REG_EXTENDED 1 | ||
| 291 | |||
| 292 | /* If this bit is set, then ignore case when matching. | ||
| 293 | If not set, then case is significant. */ | ||
| 294 | #define REG_ICASE (REG_EXTENDED << 1) | ||
| 295 | |||
| 296 | /* If this bit is set, then anchors do not match at newline | ||
| 297 | characters in the string. | ||
| 298 | If not set, then anchors do match at newlines. */ | ||
| 299 | #define REG_NEWLINE (REG_ICASE << 1) | ||
| 300 | |||
| 301 | /* If this bit is set, then report only success or fail in regexec. | ||
| 302 | If not set, then returns differ between not matching and errors. */ | ||
| 303 | #define REG_NOSUB (REG_NEWLINE << 1) | ||
| 304 | |||
| 305 | |||
| 306 | /* POSIX `eflags' bits (i.e., information for regexec). */ | ||
| 307 | |||
| 308 | /* If this bit is set, then the beginning-of-line operator doesn't match | ||
| 309 | the beginning of the string (presumably because it's not the | ||
| 310 | beginning of a line). | ||
| 311 | If not set, then the beginning-of-line operator does match the | ||
| 312 | beginning of the string. */ | ||
| 313 | #define REG_NOTBOL 1 | ||
| 314 | |||
| 315 | /* Like REG_NOTBOL, except for the end-of-line. */ | ||
| 316 | #define REG_NOTEOL (1 << 1) | ||
| 317 | |||
| 318 | |||
| 319 | /* If any error codes are removed, changed, or added, update the | ||
| 320 | `re_error_msg' table in regex.c. */ | ||
| 321 | typedef enum | ||
| 322 | { | ||
| 323 | #ifdef _XOPEN_SOURCE | ||
| 324 | REG_ENOSYS = -1, /* This will never happen for this implementation. */ | ||
| 325 | #endif | ||
| 326 | |||
| 327 | REG_NOERROR = 0, /* Success. */ | ||
| 328 | REG_NOMATCH, /* Didn't find a match (for regexec). */ | ||
| 329 | |||
| 330 | /* POSIX regcomp return error codes. (In the order listed in the | ||
| 331 | standard.) */ | ||
| 332 | REG_BADPAT, /* Invalid pattern. */ | ||
| 333 | REG_ECOLLATE, /* Not implemented. */ | ||
| 334 | REG_ECTYPE, /* Invalid character class name. */ | ||
| 335 | REG_EESCAPE, /* Trailing backslash. */ | ||
| 336 | REG_ESUBREG, /* Invalid back reference. */ | ||
| 337 | REG_EBRACK, /* Unmatched left bracket. */ | ||
| 338 | REG_EPAREN, /* Parenthesis imbalance. */ | ||
| 339 | REG_EBRACE, /* Unmatched \{. */ | ||
| 340 | REG_BADBR, /* Invalid contents of \{\}. */ | ||
| 341 | REG_ERANGE, /* Invalid range end. */ | ||
| 342 | REG_ESPACE, /* Ran out of memory. */ | ||
| 343 | REG_BADRPT, /* No preceding re for repetition op. */ | ||
| 344 | |||
| 345 | /* Error codes we've added. */ | ||
| 346 | REG_EEND, /* Premature end. */ | ||
| 347 | REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ | ||
| 348 | REG_ERPAREN, /* Unmatched ) or \); not returned from regcomp. */ | ||
| 349 | REG_ERANGEX, /* Range striding over charsets. */ | ||
| 350 | REG_ESIZEBR /* n or m too big in \{n,m\} */ | ||
| 351 | } reg_errcode_t; | ||
| 352 | |||
| 353 | /* This data structure represents a compiled pattern. Before calling | ||
| 354 | the pattern compiler, the fields `buffer', `allocated', `fastmap', | ||
| 355 | `translate', and `no_sub' can be set. After the pattern has been | ||
| 356 | compiled, the `re_nsub' field is available. All other fields are | ||
| 357 | private to the regex routines. */ | ||
| 358 | |||
| 359 | #ifndef RE_TRANSLATE_TYPE | ||
| 360 | # define RE_TRANSLATE_TYPE char * | ||
| 361 | #endif | ||
| 362 | |||
| 363 | struct re_pattern_buffer | ||
| 364 | { | ||
| 365 | /* [[[begin pattern_buffer]]] */ | ||
| 366 | /* Space that holds the compiled pattern. It is declared as | ||
| 367 | `unsigned char *' because its elements are | ||
| 368 | sometimes used as array indexes. */ | ||
| 369 | unsigned char *buffer; | ||
| 370 | |||
| 371 | /* Number of bytes to which `buffer' points. */ | ||
| 372 | size_t allocated; | ||
| 373 | |||
| 374 | /* Number of bytes actually used in `buffer'. */ | ||
| 375 | size_t used; | ||
| 376 | |||
| 377 | #ifdef emacs | ||
| 378 | /* Charset of unibyte characters at compiling time. */ | ||
| 379 | int charset_unibyte; | ||
| 380 | #else | ||
| 381 | /* Syntax setting with which the pattern was compiled. */ | ||
| 382 | reg_syntax_t syntax; | ||
| 383 | #endif | ||
| 384 | /* Pointer to a fastmap, if any, otherwise zero. re_search uses | ||
| 385 | the fastmap, if there is one, to skip over impossible | ||
| 386 | starting points for matches. */ | ||
| 387 | char *fastmap; | ||
| 388 | |||
| 389 | /* Either a translate table to apply to all characters before | ||
| 390 | comparing them, or zero for no translation. The translation | ||
| 391 | is applied to a pattern when it is compiled and to a string | ||
| 392 | when it is matched. */ | ||
| 393 | RE_TRANSLATE_TYPE translate; | ||
| 394 | |||
| 395 | /* Number of subexpressions found by the compiler. */ | ||
| 396 | size_t re_nsub; | ||
| 397 | |||
| 398 | /* Zero if this pattern cannot match the empty string, one else. | ||
| 399 | Well, in truth it's used only in `re_search_2', to see | ||
| 400 | whether or not we should use the fastmap, so we don't set | ||
| 401 | this absolutely perfectly; see `re_compile_fastmap'. */ | ||
| 402 | unsigned can_be_null : 1; | ||
| 403 | |||
| 404 | /* If REGS_UNALLOCATED, allocate space in the `regs' structure | ||
| 405 | for `max (RE_NREGS, re_nsub + 1)' groups. | ||
| 406 | If REGS_REALLOCATE, reallocate space if necessary. | ||
| 407 | If REGS_FIXED, use what's there. */ | ||
| 408 | #define REGS_UNALLOCATED 0 | ||
| 409 | #define REGS_REALLOCATE 1 | ||
| 410 | #define REGS_FIXED 2 | ||
| 411 | unsigned regs_allocated : 2; | ||
| 412 | |||
| 413 | /* Set to zero when `regex_compile' compiles a pattern; set to one | ||
| 414 | by `re_compile_fastmap' if it updates the fastmap. */ | ||
| 415 | unsigned fastmap_accurate : 1; | ||
| 416 | |||
| 417 | /* If set, `re_match_2' does not return information about | ||
| 418 | subexpressions. */ | ||
| 419 | unsigned no_sub : 1; | ||
| 420 | |||
| 421 | /* If set, a beginning-of-line anchor doesn't match at the | ||
| 422 | beginning of the string. */ | ||
| 423 | unsigned not_bol : 1; | ||
| 424 | |||
| 425 | /* Similarly for an end-of-line anchor. */ | ||
| 426 | unsigned not_eol : 1; | ||
| 427 | |||
| 428 | /* If true, the compilation of the pattern had to look up the syntax table, | ||
| 429 | so the compiled pattern is only valid for the current syntax table. */ | ||
| 430 | unsigned used_syntax : 1; | ||
| 431 | |||
| 432 | #ifdef emacs | ||
| 433 | /* If true, multi-byte form in the regexp pattern should be | ||
| 434 | recognized as a multibyte character. */ | ||
| 435 | unsigned multibyte : 1; | ||
| 436 | |||
| 437 | /* If true, multi-byte form in the target of match should be | ||
| 438 | recognized as a multibyte character. */ | ||
| 439 | unsigned target_multibyte : 1; | ||
| 440 | #endif | ||
| 441 | |||
| 442 | /* [[[end pattern_buffer]]] */ | ||
| 443 | }; | ||
| 444 | |||
| 445 | typedef struct re_pattern_buffer regex_t; | ||
| 446 | |||
| 447 | /* POSIX 1003.1-2008 requires that regoff_t be at least as wide as | ||
| 448 | ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t | ||
| 449 | is wider than ssize_t, so ssize_t is safe. ptrdiff_t is not | ||
| 450 | necessarily visible here, so use ssize_t. */ | ||
| 451 | typedef ssize_t regoff_t; | ||
| 452 | |||
| 453 | |||
| 454 | /* This is the structure we store register match data in. See | ||
| 455 | regex.texinfo for a full description of what registers match. */ | ||
| 456 | struct re_registers | ||
| 457 | { | ||
| 458 | unsigned num_regs; | ||
| 459 | regoff_t *start; | ||
| 460 | regoff_t *end; | ||
| 461 | }; | ||
| 462 | |||
| 463 | |||
| 464 | /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, | ||
| 465 | `re_match_2' returns information about at least this many registers | ||
| 466 | the first time a `regs' structure is passed. */ | ||
| 467 | #ifndef RE_NREGS | ||
| 468 | # define RE_NREGS 30 | ||
| 469 | #endif | ||
| 470 | |||
| 471 | |||
| 472 | /* POSIX specification for registers. Aside from the different names than | ||
| 473 | `re_registers', POSIX uses an array of structures, instead of a | ||
| 474 | structure of arrays. */ | ||
| 475 | typedef struct | ||
| 476 | { | ||
| 477 | regoff_t rm_so; /* Byte offset from string's start to substring's start. */ | ||
| 478 | regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ | ||
| 479 | } regmatch_t; | ||
| 480 | |||
| 481 | /* Declarations for routines. */ | ||
| 482 | |||
| 483 | #ifndef emacs | ||
| 484 | |||
| 485 | /* Sets the current default syntax to SYNTAX, and return the old syntax. | ||
| 486 | You can also simply assign to the `re_syntax_options' variable. */ | ||
| 487 | extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); | ||
| 488 | |||
| 489 | #endif | ||
| 490 | |||
| 491 | /* Compile the regular expression PATTERN, with length LENGTH | ||
| 492 | and syntax given by the global `re_syntax_options', into the buffer | ||
| 493 | BUFFER. Return NULL if successful, and an error string if not. */ | ||
| 494 | extern const char *re_compile_pattern (const char *__pattern, size_t __length, | ||
| 495 | #ifdef emacs | ||
| 496 | bool posix_backtracking, | ||
| 497 | const char *whitespace_regexp, | ||
| 498 | #endif | ||
| 499 | struct re_pattern_buffer *__buffer); | ||
| 500 | |||
| 501 | |||
| 502 | /* Compile a fastmap for the compiled pattern in BUFFER; used to | ||
| 503 | accelerate searches. Return 0 if successful and -2 if was an | ||
| 504 | internal error. */ | ||
| 505 | extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); | ||
| 506 | |||
| 507 | |||
| 508 | /* Search in the string STRING (with length LENGTH) for the pattern | ||
| 509 | compiled into BUFFER. Start searching at position START, for RANGE | ||
| 510 | characters. Return the starting position of the match, -1 for no | ||
| 511 | match, or -2 for an internal error. Also return register | ||
| 512 | information in REGS (if REGS and BUFFER->no_sub are nonzero). */ | ||
| 513 | extern regoff_t re_search (struct re_pattern_buffer *__buffer, | ||
| 514 | const char *__string, size_t __length, | ||
| 515 | ssize_t __start, ssize_t __range, | ||
| 516 | struct re_registers *__regs); | ||
| 517 | |||
| 518 | |||
| 519 | /* Like `re_search', but search in the concatenation of STRING1 and | ||
| 520 | STRING2. Also, stop searching at index START + STOP. */ | ||
| 521 | extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, | ||
| 522 | const char *__string1, size_t __length1, | ||
| 523 | const char *__string2, size_t __length2, | ||
| 524 | ssize_t __start, ssize_t __range, | ||
| 525 | struct re_registers *__regs, | ||
| 526 | ssize_t __stop); | ||
| 527 | |||
| 528 | |||
| 529 | /* Like `re_search', but return how many characters in STRING the regexp | ||
| 530 | in BUFFER matched, starting at position START. */ | ||
| 531 | extern regoff_t re_match (struct re_pattern_buffer *__buffer, | ||
| 532 | const char *__string, size_t __length, | ||
| 533 | ssize_t __start, struct re_registers *__regs); | ||
| 534 | |||
| 535 | |||
| 536 | /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ | ||
| 537 | extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, | ||
| 538 | const char *__string1, size_t __length1, | ||
| 539 | const char *__string2, size_t __length2, | ||
| 540 | ssize_t __start, struct re_registers *__regs, | ||
| 541 | ssize_t __stop); | ||
| 542 | |||
| 543 | |||
| 544 | /* Set REGS to hold NUM_REGS registers, storing them in STARTS and | ||
| 545 | ENDS. Subsequent matches using BUFFER and REGS will use this memory | ||
| 546 | for recording register information. STARTS and ENDS must be | ||
| 547 | allocated with malloc, and must each be at least `NUM_REGS * sizeof | ||
| 548 | (regoff_t)' bytes long. | ||
| 549 | |||
| 550 | If NUM_REGS == 0, then subsequent matches should allocate their own | ||
| 551 | register data. | ||
| 552 | |||
| 553 | Unless this function is called, the first search or match using | ||
| 554 | PATTERN_BUFFER will allocate its own register data, without | ||
| 555 | freeing the old data. */ | ||
| 556 | extern void re_set_registers (struct re_pattern_buffer *__buffer, | ||
| 557 | struct re_registers *__regs, | ||
| 558 | unsigned __num_regs, | ||
| 559 | regoff_t *__starts, regoff_t *__ends); | ||
| 560 | |||
| 561 | #if defined _REGEX_RE_COMP || defined _LIBC | ||
| 562 | # ifndef _CRAY | ||
| 563 | /* 4.2 bsd compatibility. */ | ||
| 564 | extern char *re_comp (const char *); | ||
| 565 | extern int re_exec (const char *); | ||
| 566 | # endif | ||
| 567 | #endif | ||
| 568 | |||
| 569 | /* GCC 2.95 and later have "__restrict"; C99 compilers have | ||
| 570 | "restrict", and "configure" may have defined "restrict". | ||
| 571 | Other compilers use __restrict, __restrict__, and _Restrict, and | ||
| 572 | 'configure' might #define 'restrict' to those words, so pick a | ||
| 573 | different name. */ | ||
| 574 | #ifndef _Restrict_ | ||
| 575 | # if 199901L <= __STDC_VERSION__ | ||
| 576 | # define _Restrict_ restrict | ||
| 577 | # elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) | ||
| 578 | # define _Restrict_ __restrict | ||
| 579 | # else | ||
| 580 | # define _Restrict_ | ||
| 581 | # endif | ||
| 582 | #endif | ||
| 583 | /* gcc 3.1 and up support the [restrict] syntax. Don't trust | ||
| 584 | sys/cdefs.h's definition of __restrict_arr, though, as it | ||
| 585 | mishandles gcc -ansi -pedantic. */ | ||
| 586 | #ifndef _Restrict_arr_ | ||
| 587 | # if ((199901L <= __STDC_VERSION__ \ | ||
| 588 | || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ | ||
| 589 | && !defined __STRICT_ANSI__)) \ | ||
| 590 | && !defined __GNUG__) | ||
| 591 | # define _Restrict_arr_ _Restrict_ | ||
| 592 | # else | ||
| 593 | # define _Restrict_arr_ | ||
| 594 | # endif | ||
| 595 | #endif | ||
| 596 | |||
| 597 | /* POSIX compatibility. */ | ||
| 598 | extern reg_errcode_t regcomp (regex_t *_Restrict_ __preg, | ||
| 599 | const char *_Restrict_ __pattern, | ||
| 600 | int __cflags); | ||
| 601 | |||
| 602 | extern reg_errcode_t regexec (const regex_t *_Restrict_ __preg, | ||
| 603 | const char *_Restrict_ __string, size_t __nmatch, | ||
| 604 | regmatch_t __pmatch[_Restrict_arr_], | ||
| 605 | int __eflags); | ||
| 606 | |||
| 607 | extern size_t regerror (int __errcode, const regex_t * __preg, | ||
| 608 | char *__errbuf, size_t __errbuf_size); | ||
| 609 | |||
| 610 | extern void regfree (regex_t *__preg); | ||
| 611 | |||
| 612 | |||
| 613 | #ifdef __cplusplus | ||
| 614 | } | ||
| 615 | #endif /* C++ */ | ||
| 616 | |||
| 617 | /* For platform which support the ISO C amendment 1 functionality we | ||
| 618 | support user defined character classes. */ | ||
| 619 | #if WIDE_CHAR_SUPPORT | ||
| 620 | /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */ | ||
| 621 | # include <wchar.h> | ||
| 622 | # include <wctype.h> | ||
| 623 | |||
| 624 | typedef wctype_t re_wctype_t; | ||
| 625 | typedef wchar_t re_wchar_t; | ||
| 626 | # define re_wctype wctype | ||
| 627 | # define re_iswctype iswctype | ||
| 628 | # define re_wctype_to_bit(cc) 0 | ||
| 629 | #else | ||
| 630 | # ifndef emacs | ||
| 631 | # define btowc(c) c | ||
| 632 | # endif | ||
| 633 | |||
| 634 | /* Character classes. */ | ||
| 635 | typedef enum { RECC_ERROR = 0, | ||
| 636 | RECC_ALNUM, RECC_ALPHA, RECC_WORD, | ||
| 637 | RECC_GRAPH, RECC_PRINT, | ||
| 638 | RECC_LOWER, RECC_UPPER, | ||
| 639 | RECC_PUNCT, RECC_CNTRL, | ||
| 640 | RECC_DIGIT, RECC_XDIGIT, | ||
| 641 | RECC_BLANK, RECC_SPACE, | ||
| 642 | RECC_MULTIBYTE, RECC_NONASCII, | ||
| 643 | RECC_ASCII, RECC_UNIBYTE | ||
| 644 | } re_wctype_t; | ||
| 645 | |||
| 646 | extern char re_iswctype (int ch, re_wctype_t cc); | ||
| 647 | extern re_wctype_t re_wctype_parse (const unsigned char **strp, unsigned limit); | ||
| 648 | |||
| 649 | typedef int re_wchar_t; | ||
| 650 | |||
| 651 | #endif /* not WIDE_CHAR_SUPPORT */ | ||
| 652 | |||
| 653 | #endif /* regex.h */ | ||
| 654 | |||
diff --git a/src/search.c b/src/search.c index 5385c890f98..f5c771963ea 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -30,7 +30,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 30 | #include "blockinput.h" | 30 | #include "blockinput.h" |
| 31 | #include "intervals.h" | 31 | #include "intervals.h" |
| 32 | 32 | ||
| 33 | #include "regex.h" | 33 | #include "regex-emacs.h" |
| 34 | 34 | ||
| 35 | #define REGEXP_CACHE_SIZE 20 | 35 | #define REGEXP_CACHE_SIZE 20 |
| 36 | 36 | ||
| @@ -59,8 +59,8 @@ static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; | |||
| 59 | static struct regexp_cache *searchbuf_head; | 59 | static struct regexp_cache *searchbuf_head; |
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | /* Every call to re_match, etc., must pass &search_regs as the regs | 62 | /* Every call to re_search, etc., must pass &search_regs as the regs |
| 63 | argument unless you can show it is unnecessary (i.e., if re_match | 63 | argument unless you can show it is unnecessary (i.e., if re_search |
| 64 | is certainly going to be called again before region-around-match | 64 | is certainly going to be called again before region-around-match |
| 65 | can be called). | 65 | can be called). |
| 66 | 66 | ||
| @@ -132,7 +132,7 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, | |||
| 132 | 132 | ||
| 133 | eassert (!cp->busy); | 133 | eassert (!cp->busy); |
| 134 | cp->regexp = Qnil; | 134 | cp->regexp = Qnil; |
| 135 | cp->buf.translate = (! NILP (translate) ? translate : make_fixnum (0)); | 135 | cp->buf.translate = translate; |
| 136 | cp->posix = posix; | 136 | cp->posix = posix; |
| 137 | cp->buf.multibyte = STRING_MULTIBYTE (pattern); | 137 | cp->buf.multibyte = STRING_MULTIBYTE (pattern); |
| 138 | cp->buf.charset_unibyte = charset_unibyte; | 138 | cp->buf.charset_unibyte = charset_unibyte; |
| @@ -238,7 +238,7 @@ compile_pattern (Lisp_Object pattern, struct re_registers *regp, | |||
| 238 | && !cp->busy | 238 | && !cp->busy |
| 239 | && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern) | 239 | && STRING_MULTIBYTE (cp->regexp) == STRING_MULTIBYTE (pattern) |
| 240 | && !NILP (Fstring_equal (cp->regexp, pattern)) | 240 | && !NILP (Fstring_equal (cp->regexp, pattern)) |
| 241 | && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_fixnum (0))) | 241 | && EQ (cp->buf.translate, translate) |
| 242 | && cp->posix == posix | 242 | && cp->posix == posix |
| 243 | && (EQ (cp->syntax_table, Qt) | 243 | && (EQ (cp->syntax_table, Qt) |
| 244 | || EQ (cp->syntax_table, BVAR (current_buffer, syntax_table))) | 244 | || EQ (cp->syntax_table, BVAR (current_buffer, syntax_table))) |
| @@ -290,7 +290,8 @@ looking_at_1 (Lisp_Object string, bool posix) | |||
| 290 | if (running_asynch_code) | 290 | if (running_asynch_code) |
| 291 | save_search_regs (); | 291 | save_search_regs (); |
| 292 | 292 | ||
| 293 | /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ | 293 | /* This is so set_image_of_range_1 in regex-emacs.c can find the EQV |
| 294 | table. */ | ||
| 294 | set_char_table_extras (BVAR (current_buffer, case_canon_table), 2, | 295 | set_char_table_extras (BVAR (current_buffer, case_canon_table), 2, |
| 295 | BVAR (current_buffer, case_eqv_table)); | 296 | BVAR (current_buffer, case_eqv_table)); |
| 296 | 297 | ||
| @@ -410,7 +411,8 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, | |||
| 410 | pos_byte = string_char_to_byte (string, pos); | 411 | pos_byte = string_char_to_byte (string, pos); |
| 411 | } | 412 | } |
| 412 | 413 | ||
| 413 | /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ | 414 | /* This is so set_image_of_range_1 in regex-emacs.c can find the EQV |
| 415 | table. */ | ||
| 414 | set_char_table_extras (BVAR (current_buffer, case_canon_table), 2, | 416 | set_char_table_extras (BVAR (current_buffer, case_canon_table), 2, |
| 415 | BVAR (current_buffer, case_eqv_table)); | 417 | BVAR (current_buffer, case_eqv_table)); |
| 416 | 418 | ||
| @@ -1062,7 +1064,8 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, | |||
| 1062 | lim_byte = CHAR_TO_BYTE (lim); | 1064 | lim_byte = CHAR_TO_BYTE (lim); |
| 1063 | } | 1065 | } |
| 1064 | 1066 | ||
| 1065 | /* This is so set_image_of_range_1 in regex.c can find the EQV table. */ | 1067 | /* This is so set_image_of_range_1 in regex-emacs.c can find the EQV |
| 1068 | table. */ | ||
| 1066 | set_char_table_extras (BVAR (current_buffer, case_canon_table), 2, | 1069 | set_char_table_extras (BVAR (current_buffer, case_canon_table), 2, |
| 1067 | BVAR (current_buffer, case_eqv_table)); | 1070 | BVAR (current_buffer, case_eqv_table)); |
| 1068 | 1071 | ||
| @@ -2186,8 +2189,8 @@ set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes) | |||
| 2186 | the match position. */ | 2189 | the match position. */ |
| 2187 | if (search_regs.num_regs == 0) | 2190 | if (search_regs.num_regs == 0) |
| 2188 | { | 2191 | { |
| 2189 | search_regs.start = xmalloc (2 * sizeof (regoff_t)); | 2192 | search_regs.start = xmalloc (2 * sizeof *search_regs.start); |
| 2190 | search_regs.end = xmalloc (2 * sizeof (regoff_t)); | 2193 | search_regs.end = xmalloc (2 * sizeof *search_regs.end); |
| 2191 | search_regs.num_regs = 2; | 2194 | search_regs.num_regs = 2; |
| 2192 | } | 2195 | } |
| 2193 | 2196 | ||
| @@ -2998,9 +3001,9 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 2998 | memory_full (SIZE_MAX); | 3001 | memory_full (SIZE_MAX); |
| 2999 | search_regs.start = | 3002 | search_regs.start = |
| 3000 | xpalloc (search_regs.start, &num_regs, length - num_regs, | 3003 | xpalloc (search_regs.start, &num_regs, length - num_regs, |
| 3001 | min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t)); | 3004 | min (PTRDIFF_MAX, UINT_MAX), sizeof *search_regs.start); |
| 3002 | search_regs.end = | 3005 | search_regs.end = |
| 3003 | xrealloc (search_regs.end, num_regs * sizeof (regoff_t)); | 3006 | xrealloc (search_regs.end, num_regs * sizeof *search_regs.end); |
| 3004 | 3007 | ||
| 3005 | for (i = search_regs.num_regs; i < num_regs; i++) | 3008 | for (i = search_regs.num_regs; i < num_regs; i++) |
| 3006 | search_regs.start[i] = -1; | 3009 | search_regs.start[i] = -1; |
| @@ -3055,12 +3058,9 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 3055 | XSETFASTINT (marker, 0); | 3058 | XSETFASTINT (marker, 0); |
| 3056 | 3059 | ||
| 3057 | CHECK_FIXNUM_COERCE_MARKER (marker); | 3060 | CHECK_FIXNUM_COERCE_MARKER (marker); |
| 3058 | if ((XFIXNUM (from) < 0 | 3061 | if (PTRDIFF_MIN <= XFIXNUM (from) && XFIXNUM (from) <= PTRDIFF_MAX |
| 3059 | ? TYPE_MINIMUM (regoff_t) <= XFIXNUM (from) | 3062 | && PTRDIFF_MIN <= XFIXNUM (marker) |
| 3060 | : XFIXNUM (from) <= TYPE_MAXIMUM (regoff_t)) | 3063 | && XFIXNUM (marker) <= PTRDIFF_MAX) |
| 3061 | && (XFIXNUM (marker) < 0 | ||
| 3062 | ? TYPE_MINIMUM (regoff_t) <= XFIXNUM (marker) | ||
| 3063 | : XFIXNUM (marker) <= TYPE_MAXIMUM (regoff_t))) | ||
| 3064 | { | 3064 | { |
| 3065 | search_regs.start[i] = XFIXNUM (from); | 3065 | search_regs.start[i] = XFIXNUM (from); |
| 3066 | search_regs.end[i] = XFIXNUM (marker); | 3066 | search_regs.end[i] = XFIXNUM (marker); |
diff --git a/src/syntax.c b/src/syntax.c index ee83ed070a0..a9bc36ae9f2 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -23,7 +23,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 23 | #include "lisp.h" | 23 | #include "lisp.h" |
| 24 | #include "character.h" | 24 | #include "character.h" |
| 25 | #include "buffer.h" | 25 | #include "buffer.h" |
| 26 | #include "regex.h" | 26 | #include "regex-emacs.h" |
| 27 | #include "syntax.h" | 27 | #include "syntax.h" |
| 28 | #include "intervals.h" | 28 | #include "intervals.h" |
| 29 | #include "category.h" | 29 | #include "category.h" |
| @@ -267,9 +267,10 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) | |||
| 267 | If it is t (which is only used in fast_c_string_match_ignore_case), | 267 | If it is t (which is only used in fast_c_string_match_ignore_case), |
| 268 | ignore properties altogether. | 268 | ignore properties altogether. |
| 269 | 269 | ||
| 270 | This is meant for regex.c to use. For buffers, regex.c passes arguments | 270 | This is meant for regex-emacs.c to use. For buffers, regex-emacs.c |
| 271 | to the UPDATE_SYNTAX_TABLE functions which are relative to BEGV. | 271 | passes arguments to the UPDATE_SYNTAX_TABLE functions which are |
| 272 | So if it is a buffer, we set the offset field to BEGV. */ | 272 | relative to BEGV. So if it is a buffer, we set the offset field to |
| 273 | BEGV. */ | ||
| 273 | 274 | ||
| 274 | void | 275 | void |
| 275 | SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, | 276 | SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, |
| @@ -3729,7 +3730,7 @@ syms_of_syntax (void) | |||
| 3729 | staticpro (&gl_state.current_syntax_table); | 3730 | staticpro (&gl_state.current_syntax_table); |
| 3730 | staticpro (&gl_state.old_prop); | 3731 | staticpro (&gl_state.old_prop); |
| 3731 | 3732 | ||
| 3732 | /* Defined in regex.c. */ | 3733 | /* Defined in regex-emacs.c. */ |
| 3733 | staticpro (&re_match_object); | 3734 | staticpro (&re_match_object); |
| 3734 | 3735 | ||
| 3735 | DEFSYM (Qscan_error, "scan-error"); | 3736 | DEFSYM (Qscan_error, "scan-error"); |
diff --git a/src/terminal.c b/src/terminal.c index 76ac4ca200f..18982fe7044 100644 --- a/src/terminal.c +++ b/src/terminal.c | |||
| @@ -483,7 +483,7 @@ static Lisp_Object | |||
| 483 | store_terminal_param (struct terminal *t, Lisp_Object parameter, Lisp_Object value) | 483 | store_terminal_param (struct terminal *t, Lisp_Object parameter, Lisp_Object value) |
| 484 | { | 484 | { |
| 485 | Lisp_Object old_alist_elt = Fassq (parameter, t->param_alist); | 485 | Lisp_Object old_alist_elt = Fassq (parameter, t->param_alist); |
| 486 | if (EQ (old_alist_elt, Qnil)) | 486 | if (NILP (old_alist_elt)) |
| 487 | { | 487 | { |
| 488 | tset_param_alist (t, Fcons (Fcons (parameter, value), t->param_alist)); | 488 | tset_param_alist (t, Fcons (Fcons (parameter, value), t->param_alist)); |
| 489 | return Qnil; | 489 | return Qnil; |
diff --git a/src/textprop.c b/src/textprop.c index 4bd4892b730..8e8baf43d9f 100644 --- a/src/textprop.c +++ b/src/textprop.c | |||
| @@ -1350,6 +1350,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, | |||
| 1350 | { | 1350 | { |
| 1351 | register INTERVAL i; | 1351 | register INTERVAL i; |
| 1352 | Lisp_Object ostart, oend; | 1352 | Lisp_Object ostart, oend; |
| 1353 | bool first_time = true; | ||
| 1353 | 1354 | ||
| 1354 | ostart = start; | 1355 | ostart = start; |
| 1355 | oend = end; | 1356 | oend = end; |
| @@ -1372,6 +1373,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, | |||
| 1372 | return Qt; | 1373 | return Qt; |
| 1373 | } | 1374 | } |
| 1374 | 1375 | ||
| 1376 | retry: | ||
| 1375 | i = validate_interval_range (object, &start, &end, soft); | 1377 | i = validate_interval_range (object, &start, &end, soft); |
| 1376 | 1378 | ||
| 1377 | if (!i) | 1379 | if (!i) |
| @@ -1391,8 +1393,22 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, | |||
| 1391 | return Qnil; | 1393 | return Qnil; |
| 1392 | } | 1394 | } |
| 1393 | 1395 | ||
| 1394 | if (BUFFERP (object) && !NILP (coherent_change_p)) | 1396 | if (BUFFERP (object) && !NILP (coherent_change_p) && first_time) |
| 1395 | modify_text_properties (object, start, end); | 1397 | { |
| 1398 | ptrdiff_t prev_length = LENGTH (i); | ||
| 1399 | ptrdiff_t prev_pos = i->position; | ||
| 1400 | |||
| 1401 | modify_text_properties (object, start, end); | ||
| 1402 | /* If someone called us recursively as a side effect of | ||
| 1403 | modify_text_properties, and changed the intervals behind our | ||
| 1404 | back, we cannot continue with I, because its data changed. | ||
| 1405 | So we restart the interval analysis anew. */ | ||
| 1406 | if (LENGTH (i) != prev_length || i->position != prev_pos) | ||
| 1407 | { | ||
| 1408 | first_time = false; | ||
| 1409 | goto retry; | ||
| 1410 | } | ||
| 1411 | } | ||
| 1396 | 1412 | ||
| 1397 | set_text_properties_1 (start, end, properties, object, i); | 1413 | set_text_properties_1 (start, end, properties, object, i); |
| 1398 | 1414 | ||
| @@ -2269,7 +2285,7 @@ verify_interval_modification (struct buffer *buf, | |||
| 2269 | if (!inhibit_modification_hooks) | 2285 | if (!inhibit_modification_hooks) |
| 2270 | { | 2286 | { |
| 2271 | hooks = Fnreverse (hooks); | 2287 | hooks = Fnreverse (hooks); |
| 2272 | while (! EQ (hooks, Qnil)) | 2288 | while (! NILP (hooks)) |
| 2273 | { | 2289 | { |
| 2274 | call_mod_hooks (Fcar (hooks), make_fixnum (start), | 2290 | call_mod_hooks (Fcar (hooks), make_fixnum (start), |
| 2275 | make_fixnum (end)); | 2291 | make_fixnum (end)); |
diff --git a/src/thread.c b/src/thread.c index f11e3e5addb..1c73d938655 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -681,7 +681,7 @@ invoke_thread_function (void) | |||
| 681 | { | 681 | { |
| 682 | ptrdiff_t count = SPECPDL_INDEX (); | 682 | ptrdiff_t count = SPECPDL_INDEX (); |
| 683 | 683 | ||
| 684 | Ffuncall (1, ¤t_thread->function); | 684 | current_thread->result = Ffuncall (1, ¤t_thread->function); |
| 685 | return unbind_to (count, Qnil); | 685 | return unbind_to (count, Qnil); |
| 686 | } | 686 | } |
| 687 | 687 | ||
| @@ -789,6 +789,7 @@ If NAME is given, it must be a string; it names the new thread. */) | |||
| 789 | new_thread->m_last_thing_searched = Qnil; /* copy from parent? */ | 789 | new_thread->m_last_thing_searched = Qnil; /* copy from parent? */ |
| 790 | new_thread->m_saved_last_thing_searched = Qnil; | 790 | new_thread->m_saved_last_thing_searched = Qnil; |
| 791 | new_thread->m_current_buffer = current_thread->m_current_buffer; | 791 | new_thread->m_current_buffer = current_thread->m_current_buffer; |
| 792 | new_thread->result = Qnil; | ||
| 792 | new_thread->error_symbol = Qnil; | 793 | new_thread->error_symbol = Qnil; |
| 793 | new_thread->error_data = Qnil; | 794 | new_thread->error_data = Qnil; |
| 794 | new_thread->event_object = Qnil; | 795 | new_thread->event_object = Qnil; |
| @@ -933,12 +934,13 @@ thread_join_callback (void *arg) | |||
| 933 | 934 | ||
| 934 | DEFUN ("thread-join", Fthread_join, Sthread_join, 1, 1, 0, | 935 | DEFUN ("thread-join", Fthread_join, Sthread_join, 1, 1, 0, |
| 935 | doc: /* Wait for THREAD to exit. | 936 | doc: /* Wait for THREAD to exit. |
| 936 | This blocks the current thread until THREAD exits or until | 937 | This blocks the current thread until THREAD exits or until the current |
| 937 | the current thread is signaled. | 938 | thread is signaled. It returns the result of the THREAD function. It |
| 938 | It is an error for a thread to try to join itself. */) | 939 | is an error for a thread to try to join itself. */) |
| 939 | (Lisp_Object thread) | 940 | (Lisp_Object thread) |
| 940 | { | 941 | { |
| 941 | struct thread_state *tstate; | 942 | struct thread_state *tstate; |
| 943 | Lisp_Object error_symbol, error_data; | ||
| 942 | 944 | ||
| 943 | CHECK_THREAD (thread); | 945 | CHECK_THREAD (thread); |
| 944 | tstate = XTHREAD (thread); | 946 | tstate = XTHREAD (thread); |
| @@ -946,10 +948,16 @@ It is an error for a thread to try to join itself. */) | |||
| 946 | if (tstate == current_thread) | 948 | if (tstate == current_thread) |
| 947 | error ("Cannot join current thread"); | 949 | error ("Cannot join current thread"); |
| 948 | 950 | ||
| 951 | error_symbol = tstate->error_symbol; | ||
| 952 | error_data = tstate->error_data; | ||
| 953 | |||
| 949 | if (thread_alive_p (tstate)) | 954 | if (thread_alive_p (tstate)) |
| 950 | flush_stack_call_func (thread_join_callback, tstate); | 955 | flush_stack_call_func (thread_join_callback, tstate); |
| 951 | 956 | ||
| 952 | return Qnil; | 957 | if (!NILP (error_symbol)) |
| 958 | Fsignal (error_symbol, error_data); | ||
| 959 | |||
| 960 | return tstate->result; | ||
| 953 | } | 961 | } |
| 954 | 962 | ||
| 955 | DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0, | 963 | DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0, |
| @@ -973,11 +981,17 @@ DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0, | |||
| 973 | return result; | 981 | return result; |
| 974 | } | 982 | } |
| 975 | 983 | ||
| 976 | DEFUN ("thread-last-error", Fthread_last_error, Sthread_last_error, 0, 0, 0, | 984 | DEFUN ("thread-last-error", Fthread_last_error, Sthread_last_error, 0, 1, 0, |
| 977 | doc: /* Return the last error form recorded by a dying thread. */) | 985 | doc: /* Return the last error form recorded by a dying thread. |
| 978 | (void) | 986 | If CLEANUP is non-nil, remove this error form from history. */) |
| 987 | (Lisp_Object cleanup) | ||
| 979 | { | 988 | { |
| 980 | return last_thread_error; | 989 | Lisp_Object result = last_thread_error; |
| 990 | |||
| 991 | if (!NILP (cleanup)) | ||
| 992 | last_thread_error = Qnil; | ||
| 993 | |||
| 994 | return result; | ||
| 981 | } | 995 | } |
| 982 | 996 | ||
| 983 | 997 | ||
| @@ -1011,6 +1025,7 @@ init_main_thread (void) | |||
| 1011 | main_thread.m_saved_last_thing_searched = Qnil; | 1025 | main_thread.m_saved_last_thing_searched = Qnil; |
| 1012 | main_thread.name = Qnil; | 1026 | main_thread.name = Qnil; |
| 1013 | main_thread.function = Qnil; | 1027 | main_thread.function = Qnil; |
| 1028 | main_thread.result = Qnil; | ||
| 1014 | main_thread.error_symbol = Qnil; | 1029 | main_thread.error_symbol = Qnil; |
| 1015 | main_thread.error_data = Qnil; | 1030 | main_thread.error_data = Qnil; |
| 1016 | main_thread.event_object = Qnil; | 1031 | main_thread.event_object = Qnil; |
| @@ -1076,9 +1091,19 @@ syms_of_threads (void) | |||
| 1076 | 1091 | ||
| 1077 | staticpro (&last_thread_error); | 1092 | staticpro (&last_thread_error); |
| 1078 | last_thread_error = Qnil; | 1093 | last_thread_error = Qnil; |
| 1094 | |||
| 1095 | Fprovide (intern_c_string ("threads"), Qnil); | ||
| 1079 | } | 1096 | } |
| 1080 | 1097 | ||
| 1081 | DEFSYM (Qthreadp, "threadp"); | 1098 | DEFSYM (Qthreadp, "threadp"); |
| 1082 | DEFSYM (Qmutexp, "mutexp"); | 1099 | DEFSYM (Qmutexp, "mutexp"); |
| 1083 | DEFSYM (Qcondition_variable_p, "condition-variable-p"); | 1100 | DEFSYM (Qcondition_variable_p, "condition-variable-p"); |
| 1101 | |||
| 1102 | DEFVAR_LISP ("main-thread", Vmain_thread, | ||
| 1103 | doc: /* The main thread of Emacs. */); | ||
| 1104 | #ifdef THREADS_ENABLED | ||
| 1105 | XSETTHREAD (Vmain_thread, &main_thread); | ||
| 1106 | #else | ||
| 1107 | Vmain_thread = Qnil; | ||
| 1108 | #endif | ||
| 1084 | } | 1109 | } |
diff --git a/src/thread.h b/src/thread.h index c10e5ecb758..8ecb00824df 100644 --- a/src/thread.h +++ b/src/thread.h | |||
| @@ -19,7 +19,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 19 | #ifndef THREAD_H | 19 | #ifndef THREAD_H |
| 20 | #define THREAD_H | 20 | #define THREAD_H |
| 21 | 21 | ||
| 22 | #include "regex.h" | 22 | #include "regex-emacs.h" |
| 23 | 23 | ||
| 24 | #ifdef WINDOWSNT | 24 | #ifdef WINDOWSNT |
| 25 | #include <sys/socket.h> | 25 | #include <sys/socket.h> |
| @@ -52,6 +52,9 @@ struct thread_state | |||
| 52 | /* The thread's function. */ | 52 | /* The thread's function. */ |
| 53 | Lisp_Object function; | 53 | Lisp_Object function; |
| 54 | 54 | ||
| 55 | /* The thread's result, if function has finished. */ | ||
| 56 | Lisp_Object result; | ||
| 57 | |||
| 55 | /* If non-nil, this thread has been signaled. */ | 58 | /* If non-nil, this thread has been signaled. */ |
| 56 | Lisp_Object error_symbol; | 59 | Lisp_Object error_symbol; |
| 57 | Lisp_Object error_data; | 60 | Lisp_Object error_data; |
| @@ -109,8 +112,8 @@ struct thread_state | |||
| 109 | struct buffer *m_current_buffer; | 112 | struct buffer *m_current_buffer; |
| 110 | #define current_buffer (current_thread->m_current_buffer) | 113 | #define current_buffer (current_thread->m_current_buffer) |
| 111 | 114 | ||
| 112 | /* Every call to re_match, etc., must pass &search_regs as the regs | 115 | /* Every call to re_match_2, etc., must pass &search_regs as the regs |
| 113 | argument unless you can show it is unnecessary (i.e., if re_match | 116 | argument unless you can show it is unnecessary (i.e., if re_match_2 |
| 114 | is certainly going to be called again before region-around-match | 117 | is certainly going to be called again before region-around-match |
| 115 | can be called). | 118 | can be called). |
| 116 | 119 | ||
diff --git a/src/w32cygwinx.c b/src/w32cygwinx.c index 7bbb8be76cc..bc401239787 100644 --- a/src/w32cygwinx.c +++ b/src/w32cygwinx.c | |||
| @@ -24,6 +24,16 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 24 | #include "lisp.h" | 24 | #include "lisp.h" |
| 25 | #include "w32common.h" | 25 | #include "w32common.h" |
| 26 | 26 | ||
| 27 | static Lisp_Object ATTRIBUTE_FORMAT_PRINTF (1, 2) | ||
| 28 | format_string (char const *format, ...) | ||
| 29 | { | ||
| 30 | va_list args; | ||
| 31 | va_start (args, format); | ||
| 32 | Lisp_Object str = vformat_string (format, args); | ||
| 33 | va_end (args); | ||
| 34 | return str; | ||
| 35 | } | ||
| 36 | |||
| 27 | DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0, | 37 | DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0, |
| 28 | doc: /* Get power status information from Windows system. | 38 | doc: /* Get power status information from Windows system. |
| 29 | 39 | ||
| @@ -92,32 +102,17 @@ The following %-sequences are provided: | |||
| 92 | if (system_status.BatteryLifePercent > 100) | 102 | if (system_status.BatteryLifePercent > 100) |
| 93 | load_percentage = build_string ("N/A"); | 103 | load_percentage = build_string ("N/A"); |
| 94 | else | 104 | else |
| 95 | { | 105 | load_percentage = format_string ("%d", system_status.BatteryLifePercent); |
| 96 | char buffer[16]; | ||
| 97 | snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); | ||
| 98 | load_percentage = build_string (buffer); | ||
| 99 | } | ||
| 100 | 106 | ||
| 101 | if (seconds_left < 0) | 107 | if (seconds_left < 0) |
| 102 | seconds = minutes = hours = remain = build_string ("N/A"); | 108 | seconds = minutes = hours = remain = build_string ("N/A"); |
| 103 | else | 109 | else |
| 104 | { | 110 | { |
| 105 | long m; | 111 | long m = seconds_left / 60; |
| 106 | double h; | 112 | seconds = format_string ("%ld", seconds_left); |
| 107 | char buffer[16]; | 113 | minutes = format_string ("%ld", m); |
| 108 | snprintf (buffer, 16, "%ld", seconds_left); | 114 | hours = format_string ("%3.1f", seconds_left / 3600.0); |
| 109 | seconds = build_string (buffer); | 115 | remain = format_string ("%ld:%02ld", m / 60, m % 60); |
| 110 | |||
| 111 | m = seconds_left / 60; | ||
| 112 | snprintf (buffer, 16, "%ld", m); | ||
| 113 | minutes = build_string (buffer); | ||
| 114 | |||
| 115 | h = seconds_left / 3600.0; | ||
| 116 | snprintf (buffer, 16, "%3.1f", h); | ||
| 117 | hours = build_string (buffer); | ||
| 118 | |||
| 119 | snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); | ||
| 120 | remain = build_string (buffer); | ||
| 121 | } | 116 | } |
| 122 | 117 | ||
| 123 | status = listn (CONSTYPE_HEAP, 8, | 118 | status = listn (CONSTYPE_HEAP, 8, |
diff --git a/src/w32term.c b/src/w32term.c index 9d224fe9b46..8d189ae32c8 100644 --- a/src/w32term.c +++ b/src/w32term.c | |||
| @@ -1476,7 +1476,7 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s) | |||
| 1476 | { | 1476 | { |
| 1477 | sprintf ((char *) buf, "%0*X", | 1477 | sprintf ((char *) buf, "%0*X", |
| 1478 | glyph->u.glyphless.ch < 0x10000 ? 4 : 6, | 1478 | glyph->u.glyphless.ch < 0x10000 ? 4 : 6, |
| 1479 | (unsigned int) glyph->u.glyphless.ch); | 1479 | (unsigned int) glyph->u.glyphless.ch & 0xffffff); |
| 1480 | str = buf; | 1480 | str = buf; |
| 1481 | } | 1481 | } |
| 1482 | 1482 | ||
diff --git a/src/xdisp.c b/src/xdisp.c index e30f800b7ee..76fde99f323 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -265,7 +265,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 265 | character to be delivered is a composed character, the iteration | 265 | character to be delivered is a composed character, the iteration |
| 266 | calls composition_reseat_it and next_element_from_composition. If | 266 | calls composition_reseat_it and next_element_from_composition. If |
| 267 | they succeed to compose the character with one or more of the | 267 | they succeed to compose the character with one or more of the |
| 268 | following characters, the whole sequence of characters that where | 268 | following characters, the whole sequence of characters that were |
| 269 | composed is recorded in the `struct composition_it' object that is | 269 | composed is recorded in the `struct composition_it' object that is |
| 270 | part of the buffer iterator. The composed sequence could produce | 270 | part of the buffer iterator. The composed sequence could produce |
| 271 | one or more font glyphs (called "grapheme clusters") on the screen. | 271 | one or more font glyphs (called "grapheme clusters") on the screen. |
| @@ -467,12 +467,12 @@ static bool message_enable_multibyte; | |||
| 467 | looking for those `redisplay' bits (actually, there might be some such bits | 467 | looking for those `redisplay' bits (actually, there might be some such bits |
| 468 | set, but then only on objects which aren't displayed anyway). | 468 | set, but then only on objects which aren't displayed anyway). |
| 469 | 469 | ||
| 470 | OTOH if it's non-zero we wil have to loop through all windows and then check | 470 | OTOH if it's non-zero we will have to loop through all windows and then |
| 471 | the `redisplay' bit of the corresponding window, frame, and buffer, in order | 471 | check the `redisplay' bit of the corresponding window, frame, and buffer, in |
| 472 | to decide whether that window needs attention or not. Note that we can't | 472 | order to decide whether that window needs attention or not. Note that we |
| 473 | just look at the frame's redisplay bit to decide that the whole frame can be | 473 | can't just look at the frame's redisplay bit to decide that the whole frame |
| 474 | skipped, since even if the frame's redisplay bit is unset, some of its | 474 | can be skipped, since even if the frame's redisplay bit is unset, some of |
| 475 | windows's redisplay bits may be set. | 475 | its windows's redisplay bits may be set. |
| 476 | 476 | ||
| 477 | Mostly for historical reasons, windows_or_buffers_changed can also take | 477 | Mostly for historical reasons, windows_or_buffers_changed can also take |
| 478 | other non-zero values. In that case, the precise value doesn't matter (it | 478 | other non-zero values. In that case, the precise value doesn't matter (it |
| @@ -483,7 +483,7 @@ static bool message_enable_multibyte; | |||
| 483 | int windows_or_buffers_changed; | 483 | int windows_or_buffers_changed; |
| 484 | 484 | ||
| 485 | /* Nonzero if we should redraw the mode lines on the next redisplay. | 485 | /* Nonzero if we should redraw the mode lines on the next redisplay. |
| 486 | Similarly to `windows_or_buffers_changed', If it has value REDISPLAY_SOME, | 486 | Similarly to `windows_or_buffers_changed', if it has value REDISPLAY_SOME, |
| 487 | then only redisplay the mode lines in those buffers/windows/frames where the | 487 | then only redisplay the mode lines in those buffers/windows/frames where the |
| 488 | `redisplay' bit has been set. | 488 | `redisplay' bit has been set. |
| 489 | For any other value, redisplay all mode lines (the number used is then only | 489 | For any other value, redisplay all mode lines (the number used is then only |
| @@ -2281,9 +2281,9 @@ get_phys_cursor_geometry (struct window *w, struct glyph_row *row, | |||
| 2281 | int x, y, wd, h, h0, y0, ascent; | 2281 | int x, y, wd, h, h0, y0, ascent; |
| 2282 | 2282 | ||
| 2283 | /* Compute the width of the rectangle to draw. If on a stretch | 2283 | /* Compute the width of the rectangle to draw. If on a stretch |
| 2284 | glyph, and `x-stretch-block-cursor' is nil, don't draw a | 2284 | glyph, and `x-stretch-cursor' is nil, don't draw a rectangle |
| 2285 | rectangle as wide as the glyph, but use a canonical character | 2285 | as wide as the glyph, but use a canonical character width |
| 2286 | width instead. */ | 2286 | instead. */ |
| 2287 | wd = glyph->pixel_width; | 2287 | wd = glyph->pixel_width; |
| 2288 | 2288 | ||
| 2289 | x = w->phys_cursor.x; | 2289 | x = w->phys_cursor.x; |
| @@ -8384,7 +8384,7 @@ next_element_from_buffer (struct it *it) | |||
| 8384 | eassert (IT_CHARPOS (*it) >= BEGV); | 8384 | eassert (IT_CHARPOS (*it) >= BEGV); |
| 8385 | eassert (NILP (it->string) && !it->s); | 8385 | eassert (NILP (it->string) && !it->s); |
| 8386 | eassert (!it->bidi_p | 8386 | eassert (!it->bidi_p |
| 8387 | || (EQ (it->bidi_it.string.lstring, Qnil) | 8387 | || (NILP (it->bidi_it.string.lstring) |
| 8388 | && it->bidi_it.string.s == NULL)); | 8388 | && it->bidi_it.string.s == NULL)); |
| 8389 | 8389 | ||
| 8390 | /* With bidi reordering, the character to display might not be the | 8390 | /* With bidi reordering, the character to display might not be the |
| @@ -11148,7 +11148,7 @@ display_echo_area (struct window *w) | |||
| 11148 | 11148 | ||
| 11149 | /* Helper for display_echo_area. Display the current buffer which | 11149 | /* Helper for display_echo_area. Display the current buffer which |
| 11150 | contains the current echo area message in window W, a mini-window, | 11150 | contains the current echo area message in window W, a mini-window, |
| 11151 | a pointer to which is passed in A1. A2..A4 are currently not used. | 11151 | a pointer to which is passed in A1. A2 is currently not used. |
| 11152 | Change the height of W so that all of the message is displayed. | 11152 | Change the height of W so that all of the message is displayed. |
| 11153 | Value is true if height of W was changed. */ | 11153 | Value is true if height of W was changed. */ |
| 11154 | 11154 | ||
| @@ -11209,8 +11209,8 @@ resize_echo_area_exactly (void) | |||
| 11209 | /* Callback function for with_echo_area_buffer, when used from | 11209 | /* Callback function for with_echo_area_buffer, when used from |
| 11210 | resize_echo_area_exactly. A1 contains a pointer to the window to | 11210 | resize_echo_area_exactly. A1 contains a pointer to the window to |
| 11211 | resize, EXACTLY non-nil means resize the mini-window exactly to the | 11211 | resize, EXACTLY non-nil means resize the mini-window exactly to the |
| 11212 | size of the text displayed. A3 and A4 are not used. Value is what | 11212 | size of the text displayed. Value is what resize_mini_window |
| 11213 | resize_mini_window returns. */ | 11213 | returns. */ |
| 11214 | 11214 | ||
| 11215 | static bool | 11215 | static bool |
| 11216 | resize_mini_window_1 (ptrdiff_t a1, Lisp_Object exactly) | 11216 | resize_mini_window_1 (ptrdiff_t a1, Lisp_Object exactly) |
| @@ -16916,6 +16916,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 16916 | /* We used to issue a CHECK_MARGINS argument to try_window here, | 16916 | /* We used to issue a CHECK_MARGINS argument to try_window here, |
| 16917 | but this causes scrolling to fail when point begins inside | 16917 | but this causes scrolling to fail when point begins inside |
| 16918 | the scroll margin (bug#148) -- cyd */ | 16918 | the scroll margin (bug#148) -- cyd */ |
| 16919 | clear_glyph_matrix (w->desired_matrix); | ||
| 16919 | if (!try_window (window, startp, 0)) | 16920 | if (!try_window (window, startp, 0)) |
| 16920 | { | 16921 | { |
| 16921 | w->force_start = true; | 16922 | w->force_start = true; |
| @@ -23516,6 +23517,17 @@ move_elt_to_front (Lisp_Object elt, Lisp_Object list) | |||
| 23516 | return list; | 23517 | return list; |
| 23517 | } | 23518 | } |
| 23518 | 23519 | ||
| 23520 | /* Subroutine to call Fset_text_properties through | ||
| 23521 | internal_condition_case_n. ARGS are the arguments of | ||
| 23522 | Fset_text_properties, in order. */ | ||
| 23523 | |||
| 23524 | static Lisp_Object | ||
| 23525 | safe_set_text_properties (ptrdiff_t nargs, Lisp_Object *args) | ||
| 23526 | { | ||
| 23527 | eassert (nargs == 4); | ||
| 23528 | return Fset_text_properties (args[0], args[1], args[2], args[3]); | ||
| 23529 | } | ||
| 23530 | |||
| 23519 | /* Contribute ELT to the mode line for window IT->w. How it | 23531 | /* Contribute ELT to the mode line for window IT->w. How it |
| 23520 | translates into text depends on its data type. | 23532 | translates into text depends on its data type. |
| 23521 | 23533 | ||
| @@ -23610,8 +23622,17 @@ display_mode_element (struct it *it, int depth, int field_width, int precision, | |||
| 23610 | = Fdelq (aelt, mode_line_proptrans_alist); | 23622 | = Fdelq (aelt, mode_line_proptrans_alist); |
| 23611 | 23623 | ||
| 23612 | elt = Fcopy_sequence (elt); | 23624 | elt = Fcopy_sequence (elt); |
| 23613 | Fset_text_properties (make_fixnum (0), Flength (elt), | 23625 | /* PROPS might cause set-text-properties to signal |
| 23614 | props, elt); | 23626 | an error, so we call it via internal_condition_case_n, |
| 23627 | to avoid an infloop in redisplay due to the error. */ | ||
| 23628 | internal_condition_case_n (safe_set_text_properties, | ||
| 23629 | 4, | ||
| 23630 | ((Lisp_Object []) | ||
| 23631 | {make_fixnum (0), | ||
| 23632 | Flength (elt), | ||
| 23633 | props, | ||
| 23634 | elt}), | ||
| 23635 | Qt, safe_eval_handler); | ||
| 23615 | /* Add this item to mode_line_proptrans_alist. */ | 23636 | /* Add this item to mode_line_proptrans_alist. */ |
| 23616 | mode_line_proptrans_alist | 23637 | mode_line_proptrans_alist |
| 23617 | = Fcons (Fcons (elt, props), | 23638 | = Fcons (Fcons (elt, props), |
diff --git a/src/xfaces.c b/src/xfaces.c index 29168e23205..23822b11261 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -2971,7 +2971,7 @@ FRAME 0 means change the face on all frames, and change the default | |||
| 2971 | if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) | 2971 | if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) |
| 2972 | if ((SYMBOLP (value) | 2972 | if ((SYMBOLP (value) |
| 2973 | && !EQ (value, Qt) | 2973 | && !EQ (value, Qt) |
| 2974 | && !EQ (value, Qnil)) | 2974 | && !NILP (value)) |
| 2975 | /* Overline color. */ | 2975 | /* Overline color. */ |
| 2976 | || (STRINGP (value) | 2976 | || (STRINGP (value) |
| 2977 | && SCHARS (value) == 0)) | 2977 | && SCHARS (value) == 0)) |
| @@ -2985,7 +2985,7 @@ FRAME 0 means change the face on all frames, and change the default | |||
| 2985 | if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) | 2985 | if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) |
| 2986 | if ((SYMBOLP (value) | 2986 | if ((SYMBOLP (value) |
| 2987 | && !EQ (value, Qt) | 2987 | && !EQ (value, Qt) |
| 2988 | && !EQ (value, Qnil)) | 2988 | && !NILP (value)) |
| 2989 | /* Strike-through color. */ | 2989 | /* Strike-through color. */ |
| 2990 | || (STRINGP (value) | 2990 | || (STRINGP (value) |
| 2991 | && SCHARS (value) == 0)) | 2991 | && SCHARS (value) == 0)) |
diff --git a/src/xfns.c b/src/xfns.c index d9df03e7ef3..c455cfe1f5f 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -1456,7 +1456,7 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 1456 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | 1456 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) |
| 1457 | return; | 1457 | return; |
| 1458 | } | 1458 | } |
| 1459 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | 1459 | else if (!STRINGP (oldval) && NILP (oldval) == NILP (arg)) |
| 1460 | return; | 1460 | return; |
| 1461 | 1461 | ||
| 1462 | block_input (); | 1462 | block_input (); |
| @@ -5722,7 +5722,7 @@ If TERMINAL is omitted or nil, that stands for the selected frame's display. */ | |||
| 5722 | { | 5722 | { |
| 5723 | struct x_display_info *dpyinfo = check_x_display_info (terminal); | 5723 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
| 5724 | 5724 | ||
| 5725 | XSynchronize (dpyinfo->display, !EQ (on, Qnil)); | 5725 | XSynchronize (dpyinfo->display, !NILP (on)); |
| 5726 | 5726 | ||
| 5727 | return Qnil; | 5727 | return Qnil; |
| 5728 | } | 5728 | } |
diff --git a/src/xmenu.c b/src/xmenu.c index e6740af7ca6..10e882af439 100644 --- a/src/xmenu.c +++ b/src/xmenu.c | |||
| @@ -1487,7 +1487,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 1487 | i = 0; | 1487 | i = 0; |
| 1488 | while (i < menu_items_used) | 1488 | while (i < menu_items_used) |
| 1489 | { | 1489 | { |
| 1490 | if (EQ (AREF (menu_items, i), Qnil)) | 1490 | if (NILP (AREF (menu_items, i))) |
| 1491 | { | 1491 | { |
| 1492 | submenu_stack[submenu_depth++] = save_wv; | 1492 | submenu_stack[submenu_depth++] = save_wv; |
| 1493 | save_wv = prev_wv; | 1493 | save_wv = prev_wv; |
| @@ -1656,7 +1656,7 @@ x_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 1656 | i = 0; | 1656 | i = 0; |
| 1657 | while (i < menu_items_used) | 1657 | while (i < menu_items_used) |
| 1658 | { | 1658 | { |
| 1659 | if (EQ (AREF (menu_items, i), Qnil)) | 1659 | if (NILP (AREF (menu_items, i))) |
| 1660 | { | 1660 | { |
| 1661 | subprefix_stack[submenu_depth++] = prefix; | 1661 | subprefix_stack[submenu_depth++] = prefix; |
| 1662 | prefix = entry; | 1662 | prefix = entry; |
diff --git a/src/xselect.c b/src/xselect.c index 984d95d7483..dd3da8e1243 100644 --- a/src/xselect.c +++ b/src/xselect.c | |||
| @@ -2094,7 +2094,7 @@ On Nextstep, TERMINAL is unused. */) | |||
| 2094 | struct frame *f = frame_for_x_selection (terminal); | 2094 | struct frame *f = frame_for_x_selection (terminal); |
| 2095 | 2095 | ||
| 2096 | CHECK_SYMBOL (selection); | 2096 | CHECK_SYMBOL (selection); |
| 2097 | if (EQ (selection, Qnil)) selection = QPRIMARY; | 2097 | if (NILP (selection)) selection = QPRIMARY; |
| 2098 | if (EQ (selection, Qt)) selection = QSECONDARY; | 2098 | if (EQ (selection, Qt)) selection = QSECONDARY; |
| 2099 | 2099 | ||
| 2100 | if (f && !NILP (LOCAL_SELECTION (selection, FRAME_DISPLAY_INFO (f)))) | 2100 | if (f && !NILP (LOCAL_SELECTION (selection, FRAME_DISPLAY_INFO (f)))) |
| @@ -2124,7 +2124,7 @@ On Nextstep, TERMINAL is unused. */) | |||
| 2124 | struct x_display_info *dpyinfo; | 2124 | struct x_display_info *dpyinfo; |
| 2125 | 2125 | ||
| 2126 | CHECK_SYMBOL (selection); | 2126 | CHECK_SYMBOL (selection); |
| 2127 | if (EQ (selection, Qnil)) selection = QPRIMARY; | 2127 | if (NILP (selection)) selection = QPRIMARY; |
| 2128 | if (EQ (selection, Qt)) selection = QSECONDARY; | 2128 | if (EQ (selection, Qt)) selection = QSECONDARY; |
| 2129 | 2129 | ||
| 2130 | if (!f) | 2130 | if (!f) |
diff --git a/src/xwidget.c b/src/xwidget.c index d6b39fe4105..4739993e729 100644 --- a/src/xwidget.c +++ b/src/xwidget.c | |||
| @@ -1099,7 +1099,7 @@ xwidget_view_lookup (struct xwidget *xw, struct window *w) | |||
| 1099 | 1099 | ||
| 1100 | ret = Fxwidget_view_lookup (xwidget, window); | 1100 | ret = Fxwidget_view_lookup (xwidget, window); |
| 1101 | 1101 | ||
| 1102 | return EQ (ret, Qnil) ? NULL : XXWIDGET_VIEW (ret); | 1102 | return NILP (ret) ? NULL : XXWIDGET_VIEW (ret); |
| 1103 | } | 1103 | } |
| 1104 | 1104 | ||
| 1105 | struct xwidget * | 1105 | struct xwidget * |