diff options
| author | Paul Eggert | 2016-10-23 02:50:48 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-10-23 02:50:48 -0700 |
| commit | 394bdb8f2317e312d39e071b588581802dd3027a (patch) | |
| tree | 159fc5496fbecff8760a3c434e82f95f67e99e61 /src | |
| parent | 46288dd6321e2ff4028781383660786050933304 (diff) | |
| parent | 50fa7d64d36c3f2d6ab11e7136575fbca7012cae (diff) | |
| download | emacs-394bdb8f2317e312d39e071b588581802dd3027a.tar.gz emacs-394bdb8f2317e312d39e071b588581802dd3027a.zip | |
Merge from origin/emacs-25
50fa7d6 ;* src/w32heap.c: Fix typo and wording of the comments.
6f1325e electric-quote mode no longer worries about coding
c2a1792 * src/regex.c (re_search_2): Make new code safe for -Wjump-mi...
f6134bb Port to GCC 6.2.1 + --enable-gcc-warnings
b2ba630 Explain how to debug emacsclient lisp errors
9da53e2 Let describe-function work for lambda again
5c2da93 Fix kill-line's docstring
ad66b3f Fix handling of allocation in regex matching
5a26c9b * lisp/electric.el (electric-quote-mode): Improve doc (Bug#24...
3877c91 vc-region-history: Search just on lines intersecting the region
8988327 Fix documentation of 'alist-get'
b6998ea * src/regex.h (re_match_object): Improve commentary.
# Conflicts:
# etc/NEWS
# lisp/help-fns.el
Diffstat (limited to 'src')
| -rw-r--r-- | src/dired.c | 4 | ||||
| -rw-r--r-- | src/regex.c | 79 | ||||
| -rw-r--r-- | src/regex.h | 10 | ||||
| -rw-r--r-- | src/search.c | 36 | ||||
| -rw-r--r-- | src/w32heap.c | 14 |
5 files changed, 119 insertions, 24 deletions
diff --git a/src/dired.c b/src/dired.c index e468147e8b2..c69164b2a1f 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -253,9 +253,11 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, | |||
| 253 | QUIT; | 253 | QUIT; |
| 254 | 254 | ||
| 255 | bool wanted = (NILP (match) | 255 | bool wanted = (NILP (match) |
| 256 | || re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0); | 256 | || (re_match_object = name, |
| 257 | re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0)); | ||
| 257 | 258 | ||
| 258 | immediate_quit = 0; | 259 | immediate_quit = 0; |
| 260 | re_match_object = Qnil; /* Stop protecting name from GC. */ | ||
| 259 | 261 | ||
| 260 | if (wanted) | 262 | if (wanted) |
| 261 | { | 263 | { |
diff --git a/src/regex.c b/src/regex.c index 1917a8480ae..8bc830356d0 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -153,6 +153,8 @@ | |||
| 153 | 153 | ||
| 154 | /* Converts the pointer to the char to BEG-based offset from the start. */ | 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)) | 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. */ | ||
| 156 | # define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object))) | 158 | # define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object))) |
| 157 | 159 | ||
| 158 | # define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) | 160 | # define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) |
| @@ -1363,11 +1365,62 @@ typedef struct | |||
| 1363 | #define NEXT_FAILURE_HANDLE(h) fail_stack.stack[(h) - 3].integer | 1365 | #define NEXT_FAILURE_HANDLE(h) fail_stack.stack[(h) - 3].integer |
| 1364 | #define TOP_FAILURE_HANDLE() fail_stack.frame | 1366 | #define TOP_FAILURE_HANDLE() fail_stack.frame |
| 1365 | 1367 | ||
| 1368 | #ifdef emacs | ||
| 1369 | # define STR_BASE_PTR(obj) \ | ||
| 1370 | (NILP (obj) ? current_buffer->text->beg \ | ||
| 1371 | : STRINGP (obj) ? SDATA (obj) \ | ||
| 1372 | : NULL) | ||
| 1373 | #else | ||
| 1374 | # define STR_BASE_PTR(obj) NULL | ||
| 1375 | #endif | ||
| 1366 | 1376 | ||
| 1367 | #define ENSURE_FAIL_STACK(space) \ | 1377 | #define ENSURE_FAIL_STACK(space) \ |
| 1368 | while (REMAINING_AVAIL_SLOTS <= space) { \ | 1378 | while (REMAINING_AVAIL_SLOTS <= space) { \ |
| 1379 | re_char *orig_base = STR_BASE_PTR (re_match_object); \ | ||
| 1380 | bool might_relocate = orig_base != NULL; \ | ||
| 1381 | ptrdiff_t string1_off, end1_off, end_match_1_off; \ | ||
| 1382 | ptrdiff_t string2_off, end2_off, end_match_2_off; \ | ||
| 1383 | ptrdiff_t d_off, dend_off, dfail_off; \ | ||
| 1384 | if (might_relocate) \ | ||
| 1385 | { \ | ||
| 1386 | if (string1) \ | ||
| 1387 | { \ | ||
| 1388 | string1_off = string1 - orig_base; \ | ||
| 1389 | end1_off = end1 - orig_base; \ | ||
| 1390 | end_match_1_off = end_match_1 - orig_base; \ | ||
| 1391 | } \ | ||
| 1392 | if (string2) \ | ||
| 1393 | { \ | ||
| 1394 | string2_off = string2 - orig_base; \ | ||
| 1395 | end2_off = end2 - orig_base; \ | ||
| 1396 | end_match_2_off = end_match_2 - orig_base; \ | ||
| 1397 | } \ | ||
| 1398 | d_off = d - orig_base; \ | ||
| 1399 | dend_off = dend - orig_base; \ | ||
| 1400 | dfail_off = dfail - orig_base; \ | ||
| 1401 | } \ | ||
| 1369 | if (!GROW_FAIL_STACK (fail_stack)) \ | 1402 | if (!GROW_FAIL_STACK (fail_stack)) \ |
| 1370 | return -2; \ | 1403 | return -2; \ |
| 1404 | /* In Emacs, GROW_FAIL_STACK might relocate string pointers. */ \ | ||
| 1405 | if (might_relocate) \ | ||
| 1406 | { \ | ||
| 1407 | re_char *new_base = STR_BASE_PTR (re_match_object); \ | ||
| 1408 | if (string1) \ | ||
| 1409 | { \ | ||
| 1410 | string1 = new_base + string1_off; \ | ||
| 1411 | end1 = new_base + end1_off; \ | ||
| 1412 | end_match_1 = new_base + end_match_1_off; \ | ||
| 1413 | } \ | ||
| 1414 | if (string2) \ | ||
| 1415 | { \ | ||
| 1416 | string2 = new_base + string2_off; \ | ||
| 1417 | end2 = new_base + end2_off; \ | ||
| 1418 | end_match_2 = new_base + end_match_2_off; \ | ||
| 1419 | } \ | ||
| 1420 | d = new_base + d_off; \ | ||
| 1421 | dend = new_base + dend_off; \ | ||
| 1422 | dfail = new_base + dfail_off; \ | ||
| 1423 | } \ | ||
| 1371 | DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\ | 1424 | DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\ |
| 1372 | DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\ | 1425 | DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\ |
| 1373 | } | 1426 | } |
| @@ -4293,6 +4346,10 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4293 | /* Loop through the string, looking for a place to start matching. */ | 4346 | /* Loop through the string, looking for a place to start matching. */ |
| 4294 | for (;;) | 4347 | for (;;) |
| 4295 | { | 4348 | { |
| 4349 | ptrdiff_t offset1, offset2; | ||
| 4350 | re_char *orig_base; | ||
| 4351 | bool might_relocate; | ||
| 4352 | |||
| 4296 | /* If the pattern is anchored, | 4353 | /* If the pattern is anchored, |
| 4297 | skip quickly past places we cannot match. | 4354 | skip quickly past places we cannot match. |
| 4298 | We don't bother to treat startpos == 0 specially | 4355 | We don't bother to treat startpos == 0 specially |
| @@ -4409,6 +4466,17 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4409 | && !bufp->can_be_null) | 4466 | && !bufp->can_be_null) |
| 4410 | return -1; | 4467 | return -1; |
| 4411 | 4468 | ||
| 4469 | /* re_match_2_internal may allocate, relocating the Lisp text | ||
| 4470 | object that we're searching. */ | ||
| 4471 | IF_LINT (offset2 = 0); /* Work around GCC bug 78081. */ | ||
| 4472 | orig_base = STR_BASE_PTR (re_match_object); | ||
| 4473 | might_relocate = orig_base != NULL; | ||
| 4474 | if (might_relocate) | ||
| 4475 | { | ||
| 4476 | if (string1) offset1 = string1 - orig_base; | ||
| 4477 | if (string2) offset2 = string2 - orig_base; | ||
| 4478 | } | ||
| 4479 | |||
| 4412 | val = re_match_2_internal (bufp, string1, size1, string2, size2, | 4480 | val = re_match_2_internal (bufp, string1, size1, string2, size2, |
| 4413 | startpos, regs, stop); | 4481 | startpos, regs, stop); |
| 4414 | 4482 | ||
| @@ -4418,6 +4486,13 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4418 | if (val == -2) | 4486 | if (val == -2) |
| 4419 | return -2; | 4487 | return -2; |
| 4420 | 4488 | ||
| 4489 | if (might_relocate) | ||
| 4490 | { | ||
| 4491 | re_char *new_base = STR_BASE_PTR (re_match_object); | ||
| 4492 | if (string1) string1 = offset1 + new_base; | ||
| 4493 | if (string2) string2 = offset2 + new_base; | ||
| 4494 | } | ||
| 4495 | |||
| 4421 | advance: | 4496 | advance: |
| 4422 | if (!range) | 4497 | if (!range) |
| 4423 | break; | 4498 | break; |
| @@ -4905,8 +4980,8 @@ WEAK_ALIAS (__re_match, re_match) | |||
| 4905 | #endif /* not emacs */ | 4980 | #endif /* not emacs */ |
| 4906 | 4981 | ||
| 4907 | #ifdef emacs | 4982 | #ifdef emacs |
| 4908 | /* In Emacs, this is the string or buffer in which we | 4983 | /* In Emacs, this is the string or buffer in which we are matching. |
| 4909 | are matching. It is used for looking up syntax properties. */ | 4984 | See the declaration in regex.h for details. */ |
| 4910 | Lisp_Object re_match_object; | 4985 | Lisp_Object re_match_object; |
| 4911 | #endif | 4986 | #endif |
| 4912 | 4987 | ||
diff --git a/src/regex.h b/src/regex.h index b672d3fdef7..cb0796fe9cb 100644 --- a/src/regex.h +++ b/src/regex.h | |||
| @@ -175,8 +175,14 @@ extern reg_syntax_t re_syntax_options; | |||
| 175 | 175 | ||
| 176 | #ifdef emacs | 176 | #ifdef emacs |
| 177 | # include "lisp.h" | 177 | # include "lisp.h" |
| 178 | /* In Emacs, this is the string or buffer in which we | 178 | /* In Emacs, this is the string or buffer in which we are matching. |
| 179 | are matching. It is used for looking up syntax properties. */ | 179 | It is used for looking up syntax properties, and also to recompute |
| 180 | pointers in case the object is relocated as a side effect of | ||
| 181 | calling malloc (if it calls r_alloc_sbrk in ralloc.c). | ||
| 182 | |||
| 183 | If the value is a Lisp string object, we are matching text in that | ||
| 184 | string; if it's nil, we are matching text in the current buffer; if | ||
| 185 | it's t, we are matching text in a C string. */ | ||
| 180 | extern Lisp_Object re_match_object; | 186 | extern Lisp_Object re_match_object; |
| 181 | #endif | 187 | #endif |
| 182 | 188 | ||
diff --git a/src/search.c b/src/search.c index 9b8fc584120..bcb5ee95edb 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -280,8 +280,10 @@ looking_at_1 (Lisp_Object string, bool posix) | |||
| 280 | immediate_quit = 1; | 280 | immediate_quit = 1; |
| 281 | QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */ | 281 | QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */ |
| 282 | 282 | ||
| 283 | /* Get pointers and sizes of the two strings | 283 | /* Get pointers and sizes of the two strings that make up the |
| 284 | that make up the visible portion of the buffer. */ | 284 | visible portion of the buffer. Note that we can use pointers |
| 285 | here, unlike in search_buffer, because we only call re_match_2 | ||
| 286 | once, after which we never use the pointers again. */ | ||
| 285 | 287 | ||
| 286 | p1 = BEGV_ADDR; | 288 | p1 = BEGV_ADDR; |
| 287 | s1 = GPT_BYTE - BEGV_BYTE; | 289 | s1 = GPT_BYTE - BEGV_BYTE; |
| @@ -400,6 +402,7 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, | |||
| 400 | (NILP (Vinhibit_changing_match_data) | 402 | (NILP (Vinhibit_changing_match_data) |
| 401 | ? &search_regs : NULL)); | 403 | ? &search_regs : NULL)); |
| 402 | immediate_quit = 0; | 404 | immediate_quit = 0; |
| 405 | re_match_object = Qnil; /* Stop protecting string from GC. */ | ||
| 403 | 406 | ||
| 404 | /* Set last_thing_searched only when match data is changed. */ | 407 | /* Set last_thing_searched only when match data is changed. */ |
| 405 | if (NILP (Vinhibit_changing_match_data)) | 408 | if (NILP (Vinhibit_changing_match_data)) |
| @@ -470,6 +473,7 @@ fast_string_match_internal (Lisp_Object regexp, Lisp_Object string, | |||
| 470 | SBYTES (string), 0, | 473 | SBYTES (string), 0, |
| 471 | SBYTES (string), 0); | 474 | SBYTES (string), 0); |
| 472 | immediate_quit = 0; | 475 | immediate_quit = 0; |
| 476 | re_match_object = Qnil; /* Stop protecting string from GC. */ | ||
| 473 | return val; | 477 | return val; |
| 474 | } | 478 | } |
| 475 | 479 | ||
| @@ -557,6 +561,7 @@ fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 557 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, | 561 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, |
| 558 | pos_byte, NULL, limit_byte); | 562 | pos_byte, NULL, limit_byte); |
| 559 | immediate_quit = 0; | 563 | immediate_quit = 0; |
| 564 | re_match_object = Qnil; /* Stop protecting string from GC. */ | ||
| 560 | 565 | ||
| 561 | return len; | 566 | return len; |
| 562 | } | 567 | } |
| @@ -1171,8 +1176,8 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1171 | 1176 | ||
| 1172 | if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) | 1177 | if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) |
| 1173 | { | 1178 | { |
| 1174 | unsigned char *p1, *p2; | 1179 | unsigned char *base; |
| 1175 | ptrdiff_t s1, s2; | 1180 | ptrdiff_t off1, off2, s1, s2; |
| 1176 | struct re_pattern_buffer *bufp; | 1181 | struct re_pattern_buffer *bufp; |
| 1177 | 1182 | ||
| 1178 | bufp = compile_pattern (string, | 1183 | bufp = compile_pattern (string, |
| @@ -1186,16 +1191,19 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1186 | can take too long. */ | 1191 | can take too long. */ |
| 1187 | QUIT; /* Do a pending quit right away, | 1192 | QUIT; /* Do a pending quit right away, |
| 1188 | to avoid paradoxical behavior */ | 1193 | to avoid paradoxical behavior */ |
| 1189 | /* Get pointers and sizes of the two strings | 1194 | /* Get offsets and sizes of the two strings that make up the |
| 1190 | that make up the visible portion of the buffer. */ | 1195 | visible portion of the buffer. We compute offsets instead of |
| 1196 | pointers because re_search_2 may call malloc and therefore | ||
| 1197 | change the buffer text address. */ | ||
| 1191 | 1198 | ||
| 1192 | p1 = BEGV_ADDR; | 1199 | base = current_buffer->text->beg; |
| 1200 | off1 = BEGV_ADDR - base; | ||
| 1193 | s1 = GPT_BYTE - BEGV_BYTE; | 1201 | s1 = GPT_BYTE - BEGV_BYTE; |
| 1194 | p2 = GAP_END_ADDR; | 1202 | off2 = GAP_END_ADDR - base; |
| 1195 | s2 = ZV_BYTE - GPT_BYTE; | 1203 | s2 = ZV_BYTE - GPT_BYTE; |
| 1196 | if (s1 < 0) | 1204 | if (s1 < 0) |
| 1197 | { | 1205 | { |
| 1198 | p2 = p1; | 1206 | off2 = off1; |
| 1199 | s2 = ZV_BYTE - BEGV_BYTE; | 1207 | s2 = ZV_BYTE - BEGV_BYTE; |
| 1200 | s1 = 0; | 1208 | s1 = 0; |
| 1201 | } | 1209 | } |
| @@ -1210,7 +1218,9 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1210 | { | 1218 | { |
| 1211 | ptrdiff_t val; | 1219 | ptrdiff_t val; |
| 1212 | 1220 | ||
| 1213 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 1221 | val = re_search_2 (bufp, |
| 1222 | (char*) (base + off1), s1, | ||
| 1223 | (char*) (base + off2), s2, | ||
| 1214 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | 1224 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
| 1215 | (NILP (Vinhibit_changing_match_data) | 1225 | (NILP (Vinhibit_changing_match_data) |
| 1216 | ? &search_regs : &search_regs_1), | 1226 | ? &search_regs : &search_regs_1), |
| @@ -1255,8 +1265,10 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1255 | { | 1265 | { |
| 1256 | ptrdiff_t val; | 1266 | ptrdiff_t val; |
| 1257 | 1267 | ||
| 1258 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 1268 | val = re_search_2 (bufp, |
| 1259 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | 1269 | (char*) (base + off1), s1, |
| 1270 | (char*) (base + off2), s2, | ||
| 1271 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | ||
| 1260 | (NILP (Vinhibit_changing_match_data) | 1272 | (NILP (Vinhibit_changing_match_data) |
| 1261 | ? &search_regs : &search_regs_1), | 1273 | ? &search_regs : &search_regs_1), |
| 1262 | lim_byte - BEGV_BYTE); | 1274 | lim_byte - BEGV_BYTE); |
diff --git a/src/w32heap.c b/src/w32heap.c index 658a8a5d691..443472b4708 100644 --- a/src/w32heap.c +++ b/src/w32heap.c | |||
| @@ -129,18 +129,18 @@ static DWORD_PTR committed = 0; | |||
| 129 | /* The maximum block size that can be handled by a non-growable w32 | 129 | /* The maximum block size that can be handled by a non-growable w32 |
| 130 | heap is limited by the MaxBlockSize value below. | 130 | heap is limited by the MaxBlockSize value below. |
| 131 | 131 | ||
| 132 | This point deserves and explanation. | 132 | This point deserves an explanation. |
| 133 | 133 | ||
| 134 | The W32 heap allocator can be used for a growable | 134 | The W32 heap allocator can be used for a growable heap or a |
| 135 | heap or a non-growable one. | 135 | non-growable one. |
| 136 | 136 | ||
| 137 | A growable heap is not compatible with a fixed base address for the | 137 | A growable heap is not compatible with a fixed base address for the |
| 138 | heap. Only a non-growable one is. One drawback of non-growable | 138 | heap. Only a non-growable one is. One drawback of non-growable |
| 139 | heaps is that they can hold only objects smaller than a certain | 139 | heaps is that they can hold only objects smaller than a certain |
| 140 | size (the one defined below). Most of the largest blocks are GC'ed | 140 | size (the one defined below). Most of the larger blocks are GC'ed |
| 141 | before dumping. In any case and to be safe, we implement a simple | 141 | before dumping. In any case, and to be safe, we implement a simple |
| 142 | first-fit allocation algorithm starting at the end of the | 142 | first-fit allocation algorithm starting at the end of the |
| 143 | dumped_data[] array like depicted below: | 143 | dumped_data[] array as depicted below: |
| 144 | 144 | ||
| 145 | ---------------------------------------------- | 145 | ---------------------------------------------- |
| 146 | | | | | | 146 | | | | | |
| @@ -273,7 +273,7 @@ init_heap (void) | |||
| 273 | else | 273 | else |
| 274 | { | 274 | { |
| 275 | /* Find the RtlCreateHeap function. Headers for this function | 275 | /* Find the RtlCreateHeap function. Headers for this function |
| 276 | are provided with the w32 ddk, but the function is available | 276 | are provided with the w32 DDK, but the function is available |
| 277 | in ntdll.dll since XP. */ | 277 | in ntdll.dll since XP. */ |
| 278 | HMODULE hm_ntdll = LoadLibrary ("ntdll.dll"); | 278 | HMODULE hm_ntdll = LoadLibrary ("ntdll.dll"); |
| 279 | RtlCreateHeap_Proc s_pfn_Rtl_Create_Heap | 279 | RtlCreateHeap_Proc s_pfn_Rtl_Create_Heap |