aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2013-05-05 21:31:16 -0700
committerPaul Eggert2013-05-05 21:31:16 -0700
commitdc4a2ee0efe25b03973ea5feb5de9e46560a8127 (patch)
tree47d0bac1b62e90be25687878e3319206c2a95925
parent8c13f3d62856ced64f25fbeedba5c121457d5e76 (diff)
downloademacs-dc4a2ee0efe25b03973ea5feb5de9e46560a8127.tar.gz
emacs-dc4a2ee0efe25b03973ea5feb5de9e46560a8127.zip
* regex.c: Fix problems when DEBUG is defined.
(extract_number, extract_number_and_incr): Define regardless of whether DEBUG is defined; that's simpler and makes the code less likely to go stale in the normal case when DEBUG is not defined. Return int rather than taking an int * arg. All callers changed. (DEBUG_PRINT1, DEBUG_PRINT2, DEBUG_PRINT3, DEBUG_PRINT4): Remove, replacing with ... (DEBUG_PRINT): New macro. All callers changed. (DEBUG_COMPILES_ARGUMENTS): New macro. (print_fastmap, print_partial_compiled_pattern) [DEBUG]: (print_compiled_pattern, print_double_string) [DEBUG]: Use prototype rather than old-style definition. (print_partial_compiled_pattern, print_compiled_pattern) [DEBUG]: (ENSURE_FAIL_STACK, PUSH_FAILURE_REG) [DEBUG]: (POP_FAILURE_REG_OR_COUNT, PUSH_FAILURE_POINT) [DEBUG]: (POP_FAILURE_POINT, re_match_2_internal) [DEBUG]: Don't assume ptrdiff_t, size_t, and long are the same width as int. (POINTER_TO_OFFSET): Return ptrdiff_t, not regoff_t. This matters only when DEBUG is defined.
-rw-r--r--src/ChangeLog22
-rw-r--r--src/regex.c378
2 files changed, 201 insertions, 199 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 098af549ab9..648a33a6fa1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,25 @@
12013-05-06 Paul Eggert <eggert@cs.ucla.edu>
2
3 * regex.c: Fix problems when DEBUG is defined.
4 (extract_number, extract_number_and_incr): Define regardless of
5 whether DEBUG is defined; that's simpler and makes the code less
6 likely to go stale in the normal case when DEBUG is not defined.
7 Return int rather than taking an int * arg. All callers changed.
8 (DEBUG_PRINT1, DEBUG_PRINT2, DEBUG_PRINT3, DEBUG_PRINT4):
9 Remove, replacing with ...
10 (DEBUG_PRINT): New macro. All callers changed.
11 (DEBUG_COMPILES_ARGUMENTS): New macro.
12 (print_fastmap, print_partial_compiled_pattern) [DEBUG]:
13 (print_compiled_pattern, print_double_string) [DEBUG]:
14 Use prototype rather than old-style definition.
15 (print_partial_compiled_pattern, print_compiled_pattern) [DEBUG]:
16 (ENSURE_FAIL_STACK, PUSH_FAILURE_REG) [DEBUG]:
17 (POP_FAILURE_REG_OR_COUNT, PUSH_FAILURE_POINT) [DEBUG]:
18 (POP_FAILURE_POINT, re_match_2_internal) [DEBUG]:
19 Don't assume ptrdiff_t, size_t, and long are the same width as int.
20 (POINTER_TO_OFFSET): Return ptrdiff_t, not regoff_t.
21 This matters only when DEBUG is defined.
22
12013-05-05 Eli Zaretskii <eliz@gnu.org> 232013-05-05 Eli Zaretskii <eliz@gnu.org>
2 24
3 * xdisp.c (set_iterator_to_next): Set the 25 * xdisp.c (set_iterator_to_next): Set the
diff --git a/src/regex.c b/src/regex.c
index 648f2529649..83d80b5aaa9 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -710,51 +710,27 @@ typedef enum
710 at SOURCE. */ 710 at SOURCE. */
711 711
712#define EXTRACT_NUMBER(destination, source) \ 712#define EXTRACT_NUMBER(destination, source) \
713 do { \ 713 ((destination) = extract_number (source))
714 (destination) = *(source) & 0377; \
715 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
716 } while (0)
717 714
718#ifdef DEBUG 715static int
719static void 716extract_number (re_char *source)
720extract_number (int *dest, re_char *source)
721{ 717{
722 int temp = SIGN_EXTEND_CHAR (*(source + 1)); 718 return (SIGN_EXTEND_CHAR (source[1]) << 8) + source[0];
723 *dest = *source & 0377;
724 *dest += temp << 8;
725} 719}
726 720
727# ifndef EXTRACT_MACROS /* To debug the macros. */
728# undef EXTRACT_NUMBER
729# define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
730# endif /* not EXTRACT_MACROS */
731
732#endif /* DEBUG */
733
734/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. 721/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
735 SOURCE must be an lvalue. */ 722 SOURCE must be an lvalue. */
736 723
737#define EXTRACT_NUMBER_AND_INCR(destination, source) \ 724#define EXTRACT_NUMBER_AND_INCR(destination, source) \
738 do { \ 725 ((destination) = extract_number_and_incr (&source))
739 EXTRACT_NUMBER (destination, source); \
740 (source) += 2; \
741 } while (0)
742 726
743#ifdef DEBUG 727static int
744static void 728extract_number_and_incr (re_char **source)
745extract_number_and_incr (int *destination, re_char **source)
746{ 729{
747 extract_number (destination, *source); 730 int num = extract_number (*source);
748 *source += 2; 731 *source += 2;
732 return num;
749} 733}
750
751# ifndef EXTRACT_MACROS
752# undef EXTRACT_NUMBER_AND_INCR
753# define EXTRACT_NUMBER_AND_INCR(dest, src) \
754 extract_number_and_incr (&dest, &src)
755# endif /* not EXTRACT_MACROS */
756
757#endif /* DEBUG */
758 734
759/* Store a multibyte character in three contiguous bytes starting 735/* Store a multibyte character in three contiguous bytes starting
760 DESTINATION, and increment DESTINATION to the byte after where the 736 DESTINATION, and increment DESTINATION to the byte after where the
@@ -861,10 +837,8 @@ extract_number_and_incr (int *destination, re_char **source)
861static int debug = -100000; 837static int debug = -100000;
862 838
863# define DEBUG_STATEMENT(e) e 839# define DEBUG_STATEMENT(e) e
864# define DEBUG_PRINT1(x) if (debug > 0) printf (x) 840# define DEBUG_PRINT(...) if (debug > 0) printf (__VA_ARGS__)
865# define DEBUG_PRINT2(x1, x2) if (debug > 0) printf (x1, x2) 841# define DEBUG_COMPILES_ARGUMENTS
866# define DEBUG_PRINT3(x1, x2, x3) if (debug > 0) printf (x1, x2, x3)
867# define DEBUG_PRINT4(x1, x2, x3, x4) if (debug > 0) printf (x1, x2, x3, x4)
868# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ 842# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
869 if (debug > 0) print_partial_compiled_pattern (s, e) 843 if (debug > 0) print_partial_compiled_pattern (s, e)
870# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ 844# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
@@ -873,9 +847,8 @@ static int debug = -100000;
873 847
874/* Print the fastmap in human-readable form. */ 848/* Print the fastmap in human-readable form. */
875 849
876void 850static void
877print_fastmap (fastmap) 851print_fastmap (char *fastmap)
878 char *fastmap;
879{ 852{
880 unsigned was_a_range = 0; 853 unsigned was_a_range = 0;
881 unsigned i = 0; 854 unsigned i = 0;
@@ -905,10 +878,8 @@ print_fastmap (fastmap)
905/* Print a compiled pattern string in human-readable form, starting at 878/* Print a compiled pattern string in human-readable form, starting at
906 the START pointer into it and ending just before the pointer END. */ 879 the START pointer into it and ending just before the pointer END. */
907 880
908void 881static void
909print_partial_compiled_pattern (start, end) 882print_partial_compiled_pattern (re_char *start, re_char *end)
910 re_char *start;
911 re_char *end;
912{ 883{
913 int mcnt, mcnt2; 884 int mcnt, mcnt2;
914 re_char *p = start; 885 re_char *p = start;
@@ -923,7 +894,7 @@ print_partial_compiled_pattern (start, end)
923 /* Loop over pattern commands. */ 894 /* Loop over pattern commands. */
924 while (p < pend) 895 while (p < pend)
925 { 896 {
926 fprintf (stderr, "%d:\t", p - start); 897 fprintf (stderr, "%td:\t", p - start);
927 898
928 switch ((re_opcode_t) *p++) 899 switch ((re_opcode_t) *p++)
929 { 900 {
@@ -1027,51 +998,58 @@ print_partial_compiled_pattern (start, end)
1027 break; 998 break;
1028 999
1029 case on_failure_jump: 1000 case on_failure_jump:
1030 extract_number_and_incr (&mcnt, &p); 1001 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1031 fprintf (stderr, "/on_failure_jump to %d", p + mcnt - start); 1002 fprintf (stderr, "/on_failure_jump to %td", p + mcnt - start);
1032 break; 1003 break;
1033 1004
1034 case on_failure_keep_string_jump: 1005 case on_failure_keep_string_jump:
1035 extract_number_and_incr (&mcnt, &p); 1006 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1036 fprintf (stderr, "/on_failure_keep_string_jump to %d", p + mcnt - start); 1007 fprintf (stderr, "/on_failure_keep_string_jump to %td",
1008 p + mcnt - start);
1037 break; 1009 break;
1038 1010
1039 case on_failure_jump_nastyloop: 1011 case on_failure_jump_nastyloop:
1040 extract_number_and_incr (&mcnt, &p); 1012 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1041 fprintf (stderr, "/on_failure_jump_nastyloop to %d", p + mcnt - start); 1013 fprintf (stderr, "/on_failure_jump_nastyloop to %td",
1014 p + mcnt - start);
1042 break; 1015 break;
1043 1016
1044 case on_failure_jump_loop: 1017 case on_failure_jump_loop:
1045 extract_number_and_incr (&mcnt, &p); 1018 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1046 fprintf (stderr, "/on_failure_jump_loop to %d", p + mcnt - start); 1019 fprintf (stderr, "/on_failure_jump_loop to %td",
1020 p + mcnt - start);
1047 break; 1021 break;
1048 1022
1049 case on_failure_jump_smart: 1023 case on_failure_jump_smart:
1050 extract_number_and_incr (&mcnt, &p); 1024 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1051 fprintf (stderr, "/on_failure_jump_smart to %d", p + mcnt - start); 1025 fprintf (stderr, "/on_failure_jump_smart to %td",
1026 p + mcnt - start);
1052 break; 1027 break;
1053 1028
1054 case jump: 1029 case jump:
1055 extract_number_and_incr (&mcnt, &p); 1030 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1056 fprintf (stderr, "/jump to %d", p + mcnt - start); 1031 fprintf (stderr, "/jump to %td", p + mcnt - start);
1057 break; 1032 break;
1058 1033
1059 case succeed_n: 1034 case succeed_n:
1060 extract_number_and_incr (&mcnt, &p); 1035 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1061 extract_number_and_incr (&mcnt2, &p); 1036 EXTRACT_NUMBER_AND_INCR (mcnt2, p);
1062 fprintf (stderr, "/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2); 1037 fprintf (stderr, "/succeed_n to %td, %d times",
1038 p - 2 + mcnt - start, mcnt2);
1063 break; 1039 break;
1064 1040
1065 case jump_n: 1041 case jump_n:
1066 extract_number_and_incr (&mcnt, &p); 1042 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1067 extract_number_and_incr (&mcnt2, &p); 1043 EXTRACT_NUMBER_AND_INCR (mcnt2, p);
1068 fprintf (stderr, "/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2); 1044 fprintf (stderr, "/jump_n to %td, %d times",
1045 p - 2 + mcnt - start, mcnt2);
1069 break; 1046 break;
1070 1047
1071 case set_number_at: 1048 case set_number_at:
1072 extract_number_and_incr (&mcnt, &p); 1049 EXTRACT_NUMBER_AND_INCR (mcnt, p);
1073 extract_number_and_incr (&mcnt2, &p); 1050 EXTRACT_NUMBER_AND_INCR (mcnt2, p);
1074 fprintf (stderr, "/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2); 1051 fprintf (stderr, "/set_number_at location %td to %d",
1052 p - 2 + mcnt - start, mcnt2);
1075 break; 1053 break;
1076 1054
1077 case wordbound: 1055 case wordbound:
@@ -1151,13 +1129,12 @@ print_partial_compiled_pattern (start, end)
1151 fprintf (stderr, "\n"); 1129 fprintf (stderr, "\n");
1152 } 1130 }
1153 1131
1154 fprintf (stderr, "%d:\tend of pattern.\n", p - start); 1132 fprintf (stderr, "%td:\tend of pattern.\n", p - start);
1155} 1133}
1156 1134
1157 1135
1158void 1136static void
1159print_compiled_pattern (bufp) 1137print_compiled_pattern (struct re_pattern_buffer *bufp)
1160 struct re_pattern_buffer *bufp;
1161{ 1138{
1162 re_char *buffer = bufp->buffer; 1139 re_char *buffer = bufp->buffer;
1163 1140
@@ -1171,7 +1148,7 @@ print_compiled_pattern (bufp)
1171 print_fastmap (bufp->fastmap); 1148 print_fastmap (bufp->fastmap);
1172 } 1149 }
1173 1150
1174 printf ("re_nsub: %d\t", bufp->re_nsub); 1151 printf ("re_nsub: %zu\t", bufp->re_nsub);
1175 printf ("regs_alloc: %d\t", bufp->regs_allocated); 1152 printf ("regs_alloc: %d\t", bufp->regs_allocated);
1176 printf ("can_be_null: %d\t", bufp->can_be_null); 1153 printf ("can_be_null: %d\t", bufp->can_be_null);
1177 printf ("no_sub: %d\t", bufp->no_sub); 1154 printf ("no_sub: %d\t", bufp->no_sub);
@@ -1183,13 +1160,9 @@ print_compiled_pattern (bufp)
1183} 1160}
1184 1161
1185 1162
1186void 1163static void
1187print_double_string (where, string1, size1, string2, size2) 1164print_double_string (re_char *where, re_char *string1, ssize_t size1,
1188 re_char *where; 1165 re_char *string2, ssize_t size2)
1189 re_char *string1;
1190 re_char *string2;
1191 ssize_t size1;
1192 ssize_t size2;
1193{ 1166{
1194 ssize_t this_char; 1167 ssize_t this_char;
1195 1168
@@ -1216,10 +1189,12 @@ print_double_string (where, string1, size1, string2, size2)
1216# define assert(e) 1189# define assert(e)
1217 1190
1218# define DEBUG_STATEMENT(e) 1191# define DEBUG_STATEMENT(e)
1219# define DEBUG_PRINT1(x) 1192# if __STDC_VERSION__ < 199901L
1220# define DEBUG_PRINT2(x1, x2) 1193# define DEBUG_COMPILES_ARGUMENTS
1221# define DEBUG_PRINT3(x1, x2, x3) 1194# define DEBUG_PRINT /* 'DEBUG_PRINT (x, y)' discards X and Y. */ (void)
1222# define DEBUG_PRINT4(x1, x2, x3, x4) 1195# else
1196# define DEBUG_PRINT(...)
1197# endif
1223# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) 1198# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
1224# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) 1199# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
1225 1200
@@ -1469,20 +1444,21 @@ typedef struct
1469while (REMAINING_AVAIL_SLOTS <= space) { \ 1444while (REMAINING_AVAIL_SLOTS <= space) { \
1470 if (!GROW_FAIL_STACK (fail_stack)) \ 1445 if (!GROW_FAIL_STACK (fail_stack)) \
1471 return -2; \ 1446 return -2; \
1472 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", (fail_stack).size);\ 1447 DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\
1473 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ 1448 DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\
1474} 1449}
1475 1450
1476/* Push register NUM onto the stack. */ 1451/* Push register NUM onto the stack. */
1477#define PUSH_FAILURE_REG(num) \ 1452#define PUSH_FAILURE_REG(num) \
1478do { \ 1453do { \
1479 char *destination; \ 1454 char *destination; \
1455 long n = num; \
1480 ENSURE_FAIL_STACK(3); \ 1456 ENSURE_FAIL_STACK(3); \
1481 DEBUG_PRINT4 (" Push reg %d (spanning %p -> %p)\n", \ 1457 DEBUG_PRINT (" Push reg %ld (spanning %p -> %p)\n", \
1482 num, regstart[num], regend[num]); \ 1458 n, regstart[n], regend[n]); \
1483 PUSH_FAILURE_POINTER (regstart[num]); \ 1459 PUSH_FAILURE_POINTER (regstart[n]); \
1484 PUSH_FAILURE_POINTER (regend[num]); \ 1460 PUSH_FAILURE_POINTER (regend[n]); \
1485 PUSH_FAILURE_INT (num); \ 1461 PUSH_FAILURE_INT (n); \
1486} while (0) 1462} while (0)
1487 1463
1488/* Change the counter's value to VAL, but make sure that it will 1464/* Change the counter's value to VAL, but make sure that it will
@@ -1493,7 +1469,7 @@ do { \
1493 int c; \ 1469 int c; \
1494 ENSURE_FAIL_STACK(3); \ 1470 ENSURE_FAIL_STACK(3); \
1495 EXTRACT_NUMBER (c, ptr); \ 1471 EXTRACT_NUMBER (c, ptr); \
1496 DEBUG_PRINT4 (" Push number %p = %d -> %d\n", ptr, c, val); \ 1472 DEBUG_PRINT (" Push number %p = %d -> %d\n", ptr, c, val); \
1497 PUSH_FAILURE_INT (c); \ 1473 PUSH_FAILURE_INT (c); \
1498 PUSH_FAILURE_POINTER (ptr); \ 1474 PUSH_FAILURE_POINTER (ptr); \
1499 PUSH_FAILURE_INT (-1); \ 1475 PUSH_FAILURE_INT (-1); \
@@ -1511,14 +1487,14 @@ do { \
1511 unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \ 1487 unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \
1512 pfreg = POP_FAILURE_INT (); \ 1488 pfreg = POP_FAILURE_INT (); \
1513 STORE_NUMBER (ptr, pfreg); \ 1489 STORE_NUMBER (ptr, pfreg); \
1514 DEBUG_PRINT3 (" Pop counter %p = %d\n", ptr, pfreg); \ 1490 DEBUG_PRINT (" Pop counter %p = %ld\n", ptr, pfreg); \
1515 } \ 1491 } \
1516 else \ 1492 else \
1517 { \ 1493 { \
1518 regend[pfreg] = POP_FAILURE_POINTER (); \ 1494 regend[pfreg] = POP_FAILURE_POINTER (); \
1519 regstart[pfreg] = POP_FAILURE_POINTER (); \ 1495 regstart[pfreg] = POP_FAILURE_POINTER (); \
1520 DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \ 1496 DEBUG_PRINT (" Pop reg %ld (spanning %p -> %p)\n", \
1521 pfreg, regstart[pfreg], regend[pfreg]); \ 1497 pfreg, regstart[pfreg], regend[pfreg]); \
1522 } \ 1498 } \
1523} while (0) 1499} while (0)
1524 1500
@@ -1538,10 +1514,10 @@ do { \
1538 cycle = 1; \ 1514 cycle = 1; \
1539 break; \ 1515 break; \
1540 } \ 1516 } \
1541 DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \ 1517 DEBUG_PRINT (" Other pattern: %p\n", FAILURE_PAT (failure)); \
1542 failure = NEXT_FAILURE_HANDLE(failure); \ 1518 failure = NEXT_FAILURE_HANDLE(failure); \
1543 } \ 1519 } \
1544 DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \ 1520 DEBUG_PRINT (" Other string: %p\n", FAILURE_STR (failure)); \
1545} while (0) 1521} while (0)
1546 1522
1547/* Push the information about the state we will need 1523/* Push the information about the state we will need
@@ -1560,23 +1536,23 @@ do { \
1560 of 0 + -1 isn't done as unsigned. */ \ 1536 of 0 + -1 isn't done as unsigned. */ \
1561 \ 1537 \
1562 DEBUG_STATEMENT (nfailure_points_pushed++); \ 1538 DEBUG_STATEMENT (nfailure_points_pushed++); \
1563 DEBUG_PRINT1 ("\nPUSH_FAILURE_POINT:\n"); \ 1539 DEBUG_PRINT ("\nPUSH_FAILURE_POINT:\n"); \
1564 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail); \ 1540 DEBUG_PRINT (" Before push, next avail: %zd\n", (fail_stack).avail); \
1565 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ 1541 DEBUG_PRINT (" size: %zd\n", (fail_stack).size);\
1566 \ 1542 \
1567 ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \ 1543 ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \
1568 \ 1544 \
1569 DEBUG_PRINT1 ("\n"); \ 1545 DEBUG_PRINT ("\n"); \
1570 \ 1546 \
1571 DEBUG_PRINT2 (" Push frame index: %d\n", fail_stack.frame); \ 1547 DEBUG_PRINT (" Push frame index: %zd\n", fail_stack.frame); \
1572 PUSH_FAILURE_INT (fail_stack.frame); \ 1548 PUSH_FAILURE_INT (fail_stack.frame); \
1573 \ 1549 \
1574 DEBUG_PRINT2 (" Push string %p: `", string_place); \ 1550 DEBUG_PRINT (" Push string %p: `", string_place); \
1575 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\ 1551 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\
1576 DEBUG_PRINT1 ("'\n"); \ 1552 DEBUG_PRINT ("'\n"); \
1577 PUSH_FAILURE_POINTER (string_place); \ 1553 PUSH_FAILURE_POINTER (string_place); \
1578 \ 1554 \
1579 DEBUG_PRINT2 (" Push pattern %p: ", pattern); \ 1555 DEBUG_PRINT (" Push pattern %p: ", pattern); \
1580 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \ 1556 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \
1581 PUSH_FAILURE_POINTER (pattern); \ 1557 PUSH_FAILURE_POINTER (pattern); \
1582 \ 1558 \
@@ -1609,28 +1585,28 @@ do { \
1609 assert (!FAIL_STACK_EMPTY ()); \ 1585 assert (!FAIL_STACK_EMPTY ()); \
1610 \ 1586 \
1611 /* Remove failure points and point to how many regs pushed. */ \ 1587 /* Remove failure points and point to how many regs pushed. */ \
1612 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ 1588 DEBUG_PRINT ("POP_FAILURE_POINT:\n"); \
1613 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ 1589 DEBUG_PRINT (" Before pop, next avail: %zd\n", fail_stack.avail); \
1614 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ 1590 DEBUG_PRINT (" size: %zd\n", fail_stack.size); \
1615 \ 1591 \
1616 /* Pop the saved registers. */ \ 1592 /* Pop the saved registers. */ \
1617 while (fail_stack.frame < fail_stack.avail) \ 1593 while (fail_stack.frame < fail_stack.avail) \
1618 POP_FAILURE_REG_OR_COUNT (); \ 1594 POP_FAILURE_REG_OR_COUNT (); \
1619 \ 1595 \
1620 pat = POP_FAILURE_POINTER (); \ 1596 pat = POP_FAILURE_POINTER (); \
1621 DEBUG_PRINT2 (" Popping pattern %p: ", pat); \ 1597 DEBUG_PRINT (" Popping pattern %p: ", pat); \
1622 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ 1598 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
1623 \ 1599 \
1624 /* If the saved string location is NULL, it came from an \ 1600 /* If the saved string location is NULL, it came from an \
1625 on_failure_keep_string_jump opcode, and we want to throw away the \ 1601 on_failure_keep_string_jump opcode, and we want to throw away the \
1626 saved NULL, thus retaining our current position in the string. */ \ 1602 saved NULL, thus retaining our current position in the string. */ \
1627 str = POP_FAILURE_POINTER (); \ 1603 str = POP_FAILURE_POINTER (); \
1628 DEBUG_PRINT2 (" Popping string %p: `", str); \ 1604 DEBUG_PRINT (" Popping string %p: `", str); \
1629 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ 1605 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
1630 DEBUG_PRINT1 ("'\n"); \ 1606 DEBUG_PRINT ("'\n"); \
1631 \ 1607 \
1632 fail_stack.frame = POP_FAILURE_INT (); \ 1608 fail_stack.frame = POP_FAILURE_INT (); \
1633 DEBUG_PRINT2 (" Popping frame index: %d\n", fail_stack.frame); \ 1609 DEBUG_PRINT (" Popping frame index: %zd\n", fail_stack.frame); \
1634 \ 1610 \
1635 assert (fail_stack.avail >= 0); \ 1611 assert (fail_stack.avail >= 0); \
1636 assert (fail_stack.frame <= fail_stack.avail); \ 1612 assert (fail_stack.frame <= fail_stack.avail); \
@@ -2493,7 +2469,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
2493 2469
2494#ifdef DEBUG 2470#ifdef DEBUG
2495 debug++; 2471 debug++;
2496 DEBUG_PRINT1 ("\nCompiling pattern: "); 2472 DEBUG_PRINT ("\nCompiling pattern: ");
2497 if (debug > 0) 2473 if (debug > 0)
2498 { 2474 {
2499 unsigned debug_count; 2475 unsigned debug_count;
@@ -3697,7 +3673,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
3697 if (debug > 0) 3673 if (debug > 0)
3698 { 3674 {
3699 re_compile_fastmap (bufp); 3675 re_compile_fastmap (bufp);
3700 DEBUG_PRINT1 ("\nCompiled pattern: \n"); 3676 DEBUG_PRINT ("\nCompiled pattern: \n");
3701 print_compiled_pattern (bufp); 3677 print_compiled_pattern (bufp);
3702 } 3678 }
3703 debug--; 3679 debug--;
@@ -4523,8 +4499,8 @@ static int bcmp_translate (re_char *s1, re_char *s2,
4523 and `string2' into an offset from the beginning of that string. */ 4499 and `string2' into an offset from the beginning of that string. */
4524#define POINTER_TO_OFFSET(ptr) \ 4500#define POINTER_TO_OFFSET(ptr) \
4525 (FIRST_STRING_P (ptr) \ 4501 (FIRST_STRING_P (ptr) \
4526 ? ((regoff_t) ((ptr) - string1)) \ 4502 ? (ptr) - string1 \
4527 : ((regoff_t) ((ptr) - string2 + size1))) 4503 : (ptr) - string2 + (ptrdiff_t) size1)
4528 4504
4529/* Call before fetching a character with *d. This switches over to 4505/* Call before fetching a character with *d. This switches over to
4530 string2 if necessary. 4506 string2 if necessary.
@@ -4711,7 +4687,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
4711 /* If we're at the end of the pattern, we can change. */ 4687 /* If we're at the end of the pattern, we can change. */
4712 if (skip_one_char (p1)) 4688 if (skip_one_char (p1))
4713 { 4689 {
4714 DEBUG_PRINT1 (" End of pattern: fast loop.\n"); 4690 DEBUG_PRINT (" End of pattern: fast loop.\n");
4715 return 1; 4691 return 1;
4716 } 4692 }
4717 break; 4693 break;
@@ -4727,7 +4703,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
4727 { 4703 {
4728 if (c != RE_STRING_CHAR (p1 + 2, multibyte)) 4704 if (c != RE_STRING_CHAR (p1 + 2, multibyte))
4729 { 4705 {
4730 DEBUG_PRINT3 (" '%c' != '%c' => fast loop.\n", c, p1[2]); 4706 DEBUG_PRINT (" '%c' != '%c' => fast loop.\n", c, p1[2]);
4731 return 1; 4707 return 1;
4732 } 4708 }
4733 } 4709 }
@@ -4752,14 +4728,14 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
4752 that we can't change to pop_failure_jump. */ 4728 that we can't change to pop_failure_jump. */
4753 if (!not) 4729 if (!not)
4754 { 4730 {
4755 DEBUG_PRINT1 (" No match => fast loop.\n"); 4731 DEBUG_PRINT (" No match => fast loop.\n");
4756 return 1; 4732 return 1;
4757 } 4733 }
4758 } 4734 }
4759 else if ((re_opcode_t) *p1 == anychar 4735 else if ((re_opcode_t) *p1 == anychar
4760 && c == '\n') 4736 && c == '\n')
4761 { 4737 {
4762 DEBUG_PRINT1 (" . != \\n => fast loop.\n"); 4738 DEBUG_PRINT (" . != \\n => fast loop.\n");
4763 return 1; 4739 return 1;
4764 } 4740 }
4765 } 4741 }
@@ -4802,7 +4778,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
4802 if (idx == p2[1] 4778 if (idx == p2[1]
4803 || idx == CHARSET_BITMAP_SIZE (p1)) 4779 || idx == CHARSET_BITMAP_SIZE (p1))
4804 { 4780 {
4805 DEBUG_PRINT1 (" No match => fast loop.\n"); 4781 DEBUG_PRINT (" No match => fast loop.\n");
4806 return 1; 4782 return 1;
4807 } 4783 }
4808 } 4784 }
@@ -4819,7 +4795,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
4819 4795
4820 if (idx == p2[1]) 4796 if (idx == p2[1])
4821 { 4797 {
4822 DEBUG_PRINT1 (" No match => fast loop.\n"); 4798 DEBUG_PRINT (" No match => fast loop.\n");
4823 return 1; 4799 return 1;
4824 } 4800 }
4825 } 4801 }
@@ -4945,7 +4921,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
4945 ssize_t pos, struct re_registers *regs, ssize_t stop) 4921 ssize_t pos, struct re_registers *regs, ssize_t stop)
4946{ 4922{
4947 /* General temporaries. */ 4923 /* General temporaries. */
4948 ssize_t mcnt; 4924 int mcnt;
4949 size_t reg; 4925 size_t reg;
4950 4926
4951 /* Just past the end of the corresponding string. */ 4927 /* Just past the end of the corresponding string. */
@@ -4987,7 +4963,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
4987#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ 4963#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
4988 fail_stack_type fail_stack; 4964 fail_stack_type fail_stack;
4989#endif 4965#endif
4990#ifdef DEBUG 4966#ifdef DEBUG_COMPILES_ARGUMENTS
4991 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; 4967 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
4992#endif 4968#endif
4993 4969
@@ -5032,12 +5008,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5032 and need to test it, it's not garbage. */ 5008 and need to test it, it's not garbage. */
5033 re_char *match_end = NULL; 5009 re_char *match_end = NULL;
5034 5010
5035#ifdef DEBUG 5011#ifdef DEBUG_COMPILES_ARGUMENTS
5036 /* Counts the total number of registers pushed. */ 5012 /* Counts the total number of registers pushed. */
5037 unsigned num_regs_pushed = 0; 5013 unsigned num_regs_pushed = 0;
5038#endif 5014#endif
5039 5015
5040 DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); 5016 DEBUG_PRINT ("\n\nEntering re_match_2.\n");
5041 5017
5042 INIT_FAIL_STACK (); 5018 INIT_FAIL_STACK ();
5043 5019
@@ -5133,22 +5109,25 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5133 dend = end_match_1; 5109 dend = end_match_1;
5134 } 5110 }
5135 5111
5136 DEBUG_PRINT1 ("The compiled pattern is: "); 5112 DEBUG_PRINT ("The compiled pattern is: ");
5137 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); 5113 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
5138 DEBUG_PRINT1 ("The string to match is: `"); 5114 DEBUG_PRINT ("The string to match is: `");
5139 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); 5115 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
5140 DEBUG_PRINT1 ("'\n"); 5116 DEBUG_PRINT ("'\n");
5141 5117
5142 /* This loops over pattern commands. It exits by returning from the 5118 /* This loops over pattern commands. It exits by returning from the
5143 function if the match is complete, or it drops through if the match 5119 function if the match is complete, or it drops through if the match
5144 fails at this starting point in the input data. */ 5120 fails at this starting point in the input data. */
5145 for (;;) 5121 for (;;)
5146 { 5122 {
5147 DEBUG_PRINT2 ("\n%p: ", p); 5123 DEBUG_PRINT ("\n%p: ", p);
5148 5124
5149 if (p == pend) 5125 if (p == pend)
5150 { /* End of pattern means we might have succeeded. */ 5126 {
5151 DEBUG_PRINT1 ("end of pattern ... "); 5127 ptrdiff_t dcnt;
5128
5129 /* End of pattern means we might have succeeded. */
5130 DEBUG_PRINT ("end of pattern ... ");
5152 5131
5153 /* If we haven't matched the entire string, and we want the 5132 /* If we haven't matched the entire string, and we want the
5154 longest match, try backtracking. */ 5133 longest match, try backtracking. */
@@ -5168,7 +5147,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5168 else 5147 else
5169 best_match_p = !FIRST_STRING_P (d); 5148 best_match_p = !FIRST_STRING_P (d);
5170 5149
5171 DEBUG_PRINT1 ("backtracking.\n"); 5150 DEBUG_PRINT ("backtracking.\n");
5172 5151
5173 if (!FAIL_STACK_EMPTY ()) 5152 if (!FAIL_STACK_EMPTY ())
5174 { /* More failure points to try. */ 5153 { /* More failure points to try. */
@@ -5179,7 +5158,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5179 best_regs_set = true; 5158 best_regs_set = true;
5180 match_end = d; 5159 match_end = d;
5181 5160
5182 DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); 5161 DEBUG_PRINT ("\nSAVING match as best so far.\n");
5183 5162
5184 for (reg = 1; reg < num_regs; reg++) 5163 for (reg = 1; reg < num_regs; reg++)
5185 { 5164 {
@@ -5201,7 +5180,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5201 For example, the pattern `x.*y.*z' against the 5180 For example, the pattern `x.*y.*z' against the
5202 strings `x-' and `y-z-', if the two strings are 5181 strings `x-' and `y-z-', if the two strings are
5203 not consecutive in memory. */ 5182 not consecutive in memory. */
5204 DEBUG_PRINT1 ("Restoring best registers.\n"); 5183 DEBUG_PRINT ("Restoring best registers.\n");
5205 5184
5206 d = match_end; 5185 d = match_end;
5207 dend = ((d >= string1 && d <= end1) 5186 dend = ((d >= string1 && d <= end1)
@@ -5216,7 +5195,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5216 } /* d != end_match_2 */ 5195 } /* d != end_match_2 */
5217 5196
5218 succeed_label: 5197 succeed_label:
5219 DEBUG_PRINT1 ("Accepting match.\n"); 5198 DEBUG_PRINT ("Accepting match.\n");
5220 5199
5221 /* If caller wants register contents data back, do it. */ 5200 /* If caller wants register contents data back, do it. */
5222 if (regs && !bufp->no_sub) 5201 if (regs && !bufp->no_sub)
@@ -5276,10 +5255,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5276 regs->start[reg] = regs->end[reg] = -1; 5255 regs->start[reg] = regs->end[reg] = -1;
5277 else 5256 else
5278 { 5257 {
5279 regs->start[reg] 5258 regs->start[reg] = POINTER_TO_OFFSET (regstart[reg]);
5280 = (regoff_t) POINTER_TO_OFFSET (regstart[reg]); 5259 regs->end[reg] = POINTER_TO_OFFSET (regend[reg]);
5281 regs->end[reg]
5282 = (regoff_t) POINTER_TO_OFFSET (regend[reg]);
5283 } 5260 }
5284 } 5261 }
5285 5262
@@ -5292,17 +5269,17 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5292 regs->start[reg] = regs->end[reg] = -1; 5269 regs->start[reg] = regs->end[reg] = -1;
5293 } /* regs && !bufp->no_sub */ 5270 } /* regs && !bufp->no_sub */
5294 5271
5295 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", 5272 DEBUG_PRINT ("%u failure points pushed, %u popped (%u remain).\n",
5296 nfailure_points_pushed, nfailure_points_popped, 5273 nfailure_points_pushed, nfailure_points_popped,
5297 nfailure_points_pushed - nfailure_points_popped); 5274 nfailure_points_pushed - nfailure_points_popped);
5298 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); 5275 DEBUG_PRINT ("%u registers pushed.\n", num_regs_pushed);
5299 5276
5300 mcnt = POINTER_TO_OFFSET (d) - pos; 5277 dcnt = POINTER_TO_OFFSET (d) - pos;
5301 5278
5302 DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); 5279 DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt);
5303 5280
5304 FREE_VARIABLES (); 5281 FREE_VARIABLES ();
5305 return mcnt; 5282 return dcnt;
5306 } 5283 }
5307 5284
5308 /* Otherwise match next pattern command. */ 5285 /* Otherwise match next pattern command. */
@@ -5311,11 +5288,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5311 /* Ignore these. Used to ignore the n of succeed_n's which 5288 /* Ignore these. Used to ignore the n of succeed_n's which
5312 currently have n == 0. */ 5289 currently have n == 0. */
5313 case no_op: 5290 case no_op:
5314 DEBUG_PRINT1 ("EXECUTING no_op.\n"); 5291 DEBUG_PRINT ("EXECUTING no_op.\n");
5315 break; 5292 break;
5316 5293
5317 case succeed: 5294 case succeed:
5318 DEBUG_PRINT1 ("EXECUTING succeed.\n"); 5295 DEBUG_PRINT ("EXECUTING succeed.\n");
5319 goto succeed_label; 5296 goto succeed_label;
5320 5297
5321 /* Match the next n pattern characters exactly. The following 5298 /* Match the next n pattern characters exactly. The following
@@ -5323,7 +5300,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5323 are the characters to match. */ 5300 are the characters to match. */
5324 case exactn: 5301 case exactn:
5325 mcnt = *p++; 5302 mcnt = *p++;
5326 DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); 5303 DEBUG_PRINT ("EXECUTING exactn %d.\n", mcnt);
5327 5304
5328 /* Remember the start point to rollback upon failure. */ 5305 /* Remember the start point to rollback upon failure. */
5329 dfail = d; 5306 dfail = d;
@@ -5429,7 +5406,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5429 int buf_charlen; 5406 int buf_charlen;
5430 re_wchar_t buf_ch; 5407 re_wchar_t buf_ch;
5431 5408
5432 DEBUG_PRINT1 ("EXECUTING anychar.\n"); 5409 DEBUG_PRINT ("EXECUTING anychar.\n");
5433 5410
5434 PREFETCH (); 5411 PREFETCH ();
5435 buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen, 5412 buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen,
@@ -5442,7 +5419,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5442 && buf_ch == '\000')) 5419 && buf_ch == '\000'))
5443 goto fail; 5420 goto fail;
5444 5421
5445 DEBUG_PRINT2 (" Matched `%d'.\n", *d); 5422 DEBUG_PRINT (" Matched `%d'.\n", *d);
5446 d += buf_charlen; 5423 d += buf_charlen;
5447 } 5424 }
5448 break; 5425 break;
@@ -5469,7 +5446,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5469 /* Whether matching against a unibyte character. */ 5446 /* Whether matching against a unibyte character. */
5470 boolean unibyte_char = false; 5447 boolean unibyte_char = false;
5471 5448
5472 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); 5449 DEBUG_PRINT ("EXECUTING charset%s.\n", not ? "_not" : "");
5473 5450
5474 range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]); 5451 range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]);
5475 5452
@@ -5553,14 +5530,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5553 matched within the group is recorded (in the internal 5530 matched within the group is recorded (in the internal
5554 registers data structure) under the register number. */ 5531 registers data structure) under the register number. */
5555 case start_memory: 5532 case start_memory:
5556 DEBUG_PRINT2 ("EXECUTING start_memory %d:\n", *p); 5533 DEBUG_PRINT ("EXECUTING start_memory %d:\n", *p);
5557 5534
5558 /* In case we need to undo this operation (via backtracking). */ 5535 /* In case we need to undo this operation (via backtracking). */
5559 PUSH_FAILURE_REG ((unsigned int)*p); 5536 PUSH_FAILURE_REG (*p);
5560 5537
5561 regstart[*p] = d; 5538 regstart[*p] = d;
5562 regend[*p] = NULL; /* probably unnecessary. -sm */ 5539 regend[*p] = NULL; /* probably unnecessary. -sm */
5563 DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); 5540 DEBUG_PRINT (" regstart: %td\n", POINTER_TO_OFFSET (regstart[*p]));
5564 5541
5565 /* Move past the register number and inner group count. */ 5542 /* Move past the register number and inner group count. */
5566 p += 1; 5543 p += 1;
@@ -5570,7 +5547,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5570 /* The stop_memory opcode represents the end of a group. Its 5547 /* The stop_memory opcode represents the end of a group. Its
5571 argument is the same as start_memory's: the register number. */ 5548 argument is the same as start_memory's: the register number. */
5572 case stop_memory: 5549 case stop_memory:
5573 DEBUG_PRINT2 ("EXECUTING stop_memory %d:\n", *p); 5550 DEBUG_PRINT ("EXECUTING stop_memory %d:\n", *p);
5574 5551
5575 assert (!REG_UNSET (regstart[*p])); 5552 assert (!REG_UNSET (regstart[*p]));
5576 /* Strictly speaking, there should be code such as: 5553 /* Strictly speaking, there should be code such as:
@@ -5588,7 +5565,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5588 is *not* undone. */ 5565 is *not* undone. */
5589 5566
5590 regend[*p] = d; 5567 regend[*p] = d;
5591 DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); 5568 DEBUG_PRINT (" regend: %td\n", POINTER_TO_OFFSET (regend[*p]));
5592 5569
5593 /* Move past the register number and the inner group count. */ 5570 /* Move past the register number and the inner group count. */
5594 p += 1; 5571 p += 1;
@@ -5601,7 +5578,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5601 { 5578 {
5602 register re_char *d2, *dend2; 5579 register re_char *d2, *dend2;
5603 int regno = *p++; /* Get which register to match against. */ 5580 int regno = *p++; /* Get which register to match against. */
5604 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); 5581 DEBUG_PRINT ("EXECUTING duplicate %d.\n", regno);
5605 5582
5606 /* Can't back reference a group which we've never matched. */ 5583 /* Can't back reference a group which we've never matched. */
5607 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) 5584 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
@@ -5623,6 +5600,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5623 ? regend[regno] : end_match_1); 5600 ? regend[regno] : end_match_1);
5624 for (;;) 5601 for (;;)
5625 { 5602 {
5603 ptrdiff_t dcnt;
5604
5626 /* If necessary, advance to next segment in register 5605 /* If necessary, advance to next segment in register
5627 contents. */ 5606 contents. */
5628 while (d2 == dend2) 5607 while (d2 == dend2)
@@ -5641,23 +5620,23 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5641 PREFETCH (); 5620 PREFETCH ();
5642 5621
5643 /* How many characters left in this segment to match. */ 5622 /* How many characters left in this segment to match. */
5644 mcnt = dend - d; 5623 dcnt = dend - d;
5645 5624
5646 /* Want how many consecutive characters we can match in 5625 /* Want how many consecutive characters we can match in
5647 one shot, so, if necessary, adjust the count. */ 5626 one shot, so, if necessary, adjust the count. */
5648 if (mcnt > dend2 - d2) 5627 if (dcnt > dend2 - d2)
5649 mcnt = dend2 - d2; 5628 dcnt = dend2 - d2;
5650 5629
5651 /* Compare that many; failure if mismatch, else move 5630 /* Compare that many; failure if mismatch, else move
5652 past them. */ 5631 past them. */
5653 if (RE_TRANSLATE_P (translate) 5632 if (RE_TRANSLATE_P (translate)
5654 ? bcmp_translate (d, d2, mcnt, translate, target_multibyte) 5633 ? bcmp_translate (d, d2, dcnt, translate, target_multibyte)
5655 : memcmp (d, d2, mcnt)) 5634 : memcmp (d, d2, dcnt))
5656 { 5635 {
5657 d = dfail; 5636 d = dfail;
5658 goto fail; 5637 goto fail;
5659 } 5638 }
5660 d += mcnt, d2 += mcnt; 5639 d += dcnt, d2 += dcnt;
5661 } 5640 }
5662 } 5641 }
5663 break; 5642 break;
@@ -5666,7 +5645,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5666 /* begline matches the empty string at the beginning of the string 5645 /* begline matches the empty string at the beginning of the string
5667 (unless `not_bol' is set in `bufp'), and after newlines. */ 5646 (unless `not_bol' is set in `bufp'), and after newlines. */
5668 case begline: 5647 case begline:
5669 DEBUG_PRINT1 ("EXECUTING begline.\n"); 5648 DEBUG_PRINT ("EXECUTING begline.\n");
5670 5649
5671 if (AT_STRINGS_BEG (d)) 5650 if (AT_STRINGS_BEG (d))
5672 { 5651 {
@@ -5685,7 +5664,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5685 5664
5686 /* endline is the dual of begline. */ 5665 /* endline is the dual of begline. */
5687 case endline: 5666 case endline:
5688 DEBUG_PRINT1 ("EXECUTING endline.\n"); 5667 DEBUG_PRINT ("EXECUTING endline.\n");
5689 5668
5690 if (AT_STRINGS_END (d)) 5669 if (AT_STRINGS_END (d))
5691 { 5670 {
@@ -5702,7 +5681,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5702 5681
5703 /* Match at the very beginning of the data. */ 5682 /* Match at the very beginning of the data. */
5704 case begbuf: 5683 case begbuf:
5705 DEBUG_PRINT1 ("EXECUTING begbuf.\n"); 5684 DEBUG_PRINT ("EXECUTING begbuf.\n");
5706 if (AT_STRINGS_BEG (d)) 5685 if (AT_STRINGS_BEG (d))
5707 break; 5686 break;
5708 goto fail; 5687 goto fail;
@@ -5710,7 +5689,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5710 5689
5711 /* Match at the very end of the data. */ 5690 /* Match at the very end of the data. */
5712 case endbuf: 5691 case endbuf:
5713 DEBUG_PRINT1 ("EXECUTING endbuf.\n"); 5692 DEBUG_PRINT ("EXECUTING endbuf.\n");
5714 if (AT_STRINGS_END (d)) 5693 if (AT_STRINGS_END (d))
5715 break; 5694 break;
5716 goto fail; 5695 goto fail;
@@ -5734,8 +5713,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5734 case; that seems worse than this. */ 5713 case; that seems worse than this. */
5735 case on_failure_keep_string_jump: 5714 case on_failure_keep_string_jump:
5736 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5715 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5737 DEBUG_PRINT3 ("EXECUTING on_failure_keep_string_jump %d (to %p):\n", 5716 DEBUG_PRINT ("EXECUTING on_failure_keep_string_jump %d (to %p):\n",
5738 mcnt, p + mcnt); 5717 mcnt, p + mcnt);
5739 5718
5740 PUSH_FAILURE_POINT (p - 3, NULL); 5719 PUSH_FAILURE_POINT (p - 3, NULL);
5741 break; 5720 break;
@@ -5756,8 +5735,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5756 the loop. */ 5735 the loop. */
5757 case on_failure_jump_nastyloop: 5736 case on_failure_jump_nastyloop:
5758 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5737 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5759 DEBUG_PRINT3 ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n", 5738 DEBUG_PRINT ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n",
5760 mcnt, p + mcnt); 5739 mcnt, p + mcnt);
5761 5740
5762 assert ((re_opcode_t)p[-4] == no_op); 5741 assert ((re_opcode_t)p[-4] == no_op);
5763 { 5742 {
@@ -5777,8 +5756,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5777 case on_failure_jump_loop: 5756 case on_failure_jump_loop:
5778 on_failure: 5757 on_failure:
5779 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5758 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5780 DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n", 5759 DEBUG_PRINT ("EXECUTING on_failure_jump_loop %d (to %p):\n",
5781 mcnt, p + mcnt); 5760 mcnt, p + mcnt);
5782 { 5761 {
5783 int cycle = 0; 5762 int cycle = 0;
5784 CHECK_INFINITE_LOOP (p - 3, d); 5763 CHECK_INFINITE_LOOP (p - 3, d);
@@ -5809,8 +5788,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5809 pop_failure_jump back to this on_failure_jump. */ 5788 pop_failure_jump back to this on_failure_jump. */
5810 case on_failure_jump: 5789 case on_failure_jump:
5811 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5790 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5812 DEBUG_PRINT3 ("EXECUTING on_failure_jump %d (to %p):\n", 5791 DEBUG_PRINT ("EXECUTING on_failure_jump %d (to %p):\n",
5813 mcnt, p + mcnt); 5792 mcnt, p + mcnt);
5814 5793
5815 PUSH_FAILURE_POINT (p -3, d); 5794 PUSH_FAILURE_POINT (p -3, d);
5816 break; 5795 break;
@@ -5824,8 +5803,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5824 on_failure_keep_string_jump instead of on_failure_jump. */ 5803 on_failure_keep_string_jump instead of on_failure_jump. */
5825 case on_failure_jump_smart: 5804 case on_failure_jump_smart:
5826 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5805 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5827 DEBUG_PRINT3 ("EXECUTING on_failure_jump_smart %d (to %p).\n", 5806 DEBUG_PRINT ("EXECUTING on_failure_jump_smart %d (to %p).\n",
5828 mcnt, p + mcnt); 5807 mcnt, p + mcnt);
5829 { 5808 {
5830 re_char *p1 = p; /* Next operation. */ 5809 re_char *p1 = p; /* Next operation. */
5831 /* Here, we discard `const', making re_match non-reentrant. */ 5810 /* Here, we discard `const', making re_match non-reentrant. */
@@ -5845,14 +5824,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5845 if (mutually_exclusive_p (bufp, p1, p2)) 5824 if (mutually_exclusive_p (bufp, p1, p2))
5846 { 5825 {
5847 /* Use a fast `on_failure_keep_string_jump' loop. */ 5826 /* Use a fast `on_failure_keep_string_jump' loop. */
5848 DEBUG_PRINT1 (" smart exclusive => fast loop.\n"); 5827 DEBUG_PRINT (" smart exclusive => fast loop.\n");
5849 *p3 = (unsigned char) on_failure_keep_string_jump; 5828 *p3 = (unsigned char) on_failure_keep_string_jump;
5850 STORE_NUMBER (p2 - 2, mcnt + 3); 5829 STORE_NUMBER (p2 - 2, mcnt + 3);
5851 } 5830 }
5852 else 5831 else
5853 { 5832 {
5854 /* Default to a safe `on_failure_jump' loop. */ 5833 /* Default to a safe `on_failure_jump' loop. */
5855 DEBUG_PRINT1 (" smart default => slow loop.\n"); 5834 DEBUG_PRINT (" smart default => slow loop.\n");
5856 *p3 = (unsigned char) on_failure_jump; 5835 *p3 = (unsigned char) on_failure_jump;
5857 } 5836 }
5858 DEBUG_STATEMENT (debug -= 2); 5837 DEBUG_STATEMENT (debug -= 2);
@@ -5864,9 +5843,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5864 unconditional_jump: 5843 unconditional_jump:
5865 IMMEDIATE_QUIT_CHECK; 5844 IMMEDIATE_QUIT_CHECK;
5866 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ 5845 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
5867 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); 5846 DEBUG_PRINT ("EXECUTING jump %d ", mcnt);
5868 p += mcnt; /* Do the jump. */ 5847 p += mcnt; /* Do the jump. */
5869 DEBUG_PRINT2 ("(to %p).\n", p); 5848 DEBUG_PRINT ("(to %p).\n", p);
5870 break; 5849 break;
5871 5850
5872 5851
@@ -5875,7 +5854,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5875 case succeed_n: 5854 case succeed_n:
5876 /* Signedness doesn't matter since we only compare MCNT to 0. */ 5855 /* Signedness doesn't matter since we only compare MCNT to 0. */
5877 EXTRACT_NUMBER (mcnt, p + 2); 5856 EXTRACT_NUMBER (mcnt, p + 2);
5878 DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); 5857 DEBUG_PRINT ("EXECUTING succeed_n %d.\n", mcnt);
5879 5858
5880 /* Originally, mcnt is how many times we HAVE to succeed. */ 5859 /* Originally, mcnt is how many times we HAVE to succeed. */
5881 if (mcnt != 0) 5860 if (mcnt != 0)
@@ -5894,7 +5873,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5894 case jump_n: 5873 case jump_n:
5895 /* Signedness doesn't matter since we only compare MCNT to 0. */ 5874 /* Signedness doesn't matter since we only compare MCNT to 0. */
5896 EXTRACT_NUMBER (mcnt, p + 2); 5875 EXTRACT_NUMBER (mcnt, p + 2);
5897 DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); 5876 DEBUG_PRINT ("EXECUTING jump_n %d.\n", mcnt);
5898 5877
5899 /* Originally, this is how many times we CAN jump. */ 5878 /* Originally, this is how many times we CAN jump. */
5900 if (mcnt != 0) 5879 if (mcnt != 0)
@@ -5913,14 +5892,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5913 case set_number_at: 5892 case set_number_at:
5914 { 5893 {
5915 unsigned char *p2; /* Location of the counter. */ 5894 unsigned char *p2; /* Location of the counter. */
5916 DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); 5895 DEBUG_PRINT ("EXECUTING set_number_at.\n");
5917 5896
5918 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5897 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5919 /* Here, we discard `const', making re_match non-reentrant. */ 5898 /* Here, we discard `const', making re_match non-reentrant. */
5920 p2 = (unsigned char*) p + mcnt; 5899 p2 = (unsigned char*) p + mcnt;
5921 /* Signedness doesn't matter since we only copy MCNT's bits . */ 5900 /* Signedness doesn't matter since we only copy MCNT's bits . */
5922 EXTRACT_NUMBER_AND_INCR (mcnt, p); 5901 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5923 DEBUG_PRINT3 (" Setting %p to %d.\n", p2, mcnt); 5902 DEBUG_PRINT (" Setting %p to %d.\n", p2, mcnt);
5924 PUSH_NUMBER (p2, mcnt); 5903 PUSH_NUMBER (p2, mcnt);
5925 break; 5904 break;
5926 } 5905 }
@@ -5929,7 +5908,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5929 case notwordbound: 5908 case notwordbound:
5930 { 5909 {
5931 boolean not = (re_opcode_t) *(p - 1) == notwordbound; 5910 boolean not = (re_opcode_t) *(p - 1) == notwordbound;
5932 DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":""); 5911 DEBUG_PRINT ("EXECUTING %swordbound.\n", not ? "not" : "");
5933 5912
5934 /* We SUCCEED (or FAIL) in one of the following cases: */ 5913 /* We SUCCEED (or FAIL) in one of the following cases: */
5935 5914
@@ -5971,7 +5950,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
5971 } 5950 }
5972 5951
5973 case wordbeg: 5952 case wordbeg:
5974 DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); 5953 DEBUG_PRINT ("EXECUTING wordbeg.\n");
5975 5954
5976 /* We FAIL in one of the following cases: */ 5955 /* We FAIL in one of the following cases: */
5977 5956
@@ -6016,7 +5995,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6016 break; 5995 break;
6017 5996
6018 case wordend: 5997 case wordend:
6019 DEBUG_PRINT1 ("EXECUTING wordend.\n"); 5998 DEBUG_PRINT ("EXECUTING wordend.\n");
6020 5999
6021 /* We FAIL in one of the following cases: */ 6000 /* We FAIL in one of the following cases: */
6022 6001
@@ -6061,7 +6040,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6061 break; 6040 break;
6062 6041
6063 case symbeg: 6042 case symbeg:
6064 DEBUG_PRINT1 ("EXECUTING symbeg.\n"); 6043 DEBUG_PRINT ("EXECUTING symbeg.\n");
6065 6044
6066 /* We FAIL in one of the following cases: */ 6045 /* We FAIL in one of the following cases: */
6067 6046
@@ -6104,7 +6083,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6104 break; 6083 break;
6105 6084
6106 case symend: 6085 case symend:
6107 DEBUG_PRINT1 ("EXECUTING symend.\n"); 6086 DEBUG_PRINT ("EXECUTING symend.\n");
6108 6087
6109 /* We FAIL in one of the following cases: */ 6088 /* We FAIL in one of the following cases: */
6110 6089
@@ -6151,7 +6130,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6151 { 6130 {
6152 boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec; 6131 boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec;
6153 mcnt = *p++; 6132 mcnt = *p++;
6154 DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt); 6133 DEBUG_PRINT ("EXECUTING %ssyntaxspec %d.\n", not ? "not" : "",
6134 mcnt);
6155 PREFETCH (); 6135 PREFETCH ();
6156#ifdef emacs 6136#ifdef emacs
6157 { 6137 {
@@ -6174,19 +6154,19 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6174 6154
6175#ifdef emacs 6155#ifdef emacs
6176 case before_dot: 6156 case before_dot:
6177 DEBUG_PRINT1 ("EXECUTING before_dot.\n"); 6157 DEBUG_PRINT ("EXECUTING before_dot.\n");
6178 if (PTR_BYTE_POS (d) >= PT_BYTE) 6158 if (PTR_BYTE_POS (d) >= PT_BYTE)
6179 goto fail; 6159 goto fail;
6180 break; 6160 break;
6181 6161
6182 case at_dot: 6162 case at_dot:
6183 DEBUG_PRINT1 ("EXECUTING at_dot.\n"); 6163 DEBUG_PRINT ("EXECUTING at_dot.\n");
6184 if (PTR_BYTE_POS (d) != PT_BYTE) 6164 if (PTR_BYTE_POS (d) != PT_BYTE)
6185 goto fail; 6165 goto fail;
6186 break; 6166 break;
6187 6167
6188 case after_dot: 6168 case after_dot:
6189 DEBUG_PRINT1 ("EXECUTING after_dot.\n"); 6169 DEBUG_PRINT ("EXECUTING after_dot.\n");
6190 if (PTR_BYTE_POS (d) <= PT_BYTE) 6170 if (PTR_BYTE_POS (d) <= PT_BYTE)
6191 goto fail; 6171 goto fail;
6192 break; 6172 break;
@@ -6196,8 +6176,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6196 { 6176 {
6197 boolean not = (re_opcode_t) *(p - 1) == notcategoryspec; 6177 boolean not = (re_opcode_t) *(p - 1) == notcategoryspec;
6198 mcnt = *p++; 6178 mcnt = *p++;
6199 DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n", 6179 DEBUG_PRINT ("EXECUTING %scategoryspec %d.\n",
6200 not?"not":"", mcnt); 6180 not ? "not" : "", mcnt);
6201 PREFETCH (); 6181 PREFETCH ();
6202 6182
6203 { 6183 {
@@ -6226,7 +6206,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6226 { 6206 {
6227 re_char *str, *pat; 6207 re_char *str, *pat;
6228 /* A restart point is known. Restore to that state. */ 6208 /* A restart point is known. Restore to that state. */
6229 DEBUG_PRINT1 ("\nFAIL:\n"); 6209 DEBUG_PRINT ("\nFAIL:\n");
6230 POP_FAILURE_POINT (str, pat); 6210 POP_FAILURE_POINT (str, pat);
6231 switch (*pat++) 6211 switch (*pat++)
6232 { 6212 {
@@ -6271,7 +6251,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
6271 FREE_VARIABLES (); 6251 FREE_VARIABLES ();
6272 6252
6273 return -1; /* Failure to match. */ 6253 return -1; /* Failure to match. */
6274} /* re_match_2 */ 6254}
6275 6255
6276/* Subroutine definitions for re_match_2. */ 6256/* Subroutine definitions for re_match_2. */
6277 6257