diff options
| author | Paul Eggert | 2016-11-04 15:01:17 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-11-04 15:01:17 -0700 |
| commit | 6a20bd3579ef87103d5ea37e6b8193dc6385e547 (patch) | |
| tree | e11a49c3cbb7e72ccfb6689fbad81bcccfd12665 /src | |
| parent | 29559361f56c9398dcb69db7396dcfc0887843a2 (diff) | |
| parent | dbb341022870ecad4c9177485a6770a355633cc0 (diff) | |
| download | emacs-6a20bd3579ef87103d5ea37e6b8193dc6385e547.tar.gz emacs-6a20bd3579ef87103d5ea37e6b8193dc6385e547.zip | |
Merge from origin/emacs-25
dbb3410 python.el: Fix detection of native completion in Python 3 (bu...
91c97b6 * Makefile.in (install-arch-indep): Skip etc/refcards/emacsve...
9c1cb8d * lisp/subr.el (set-transient-map): Exit for unbound events (...
9c247d2 Update category-table for Chinese characters
43986d1 Inhibit buffer relocation during regex searches
fee4cef Revert fixes to allocation of regex matching
Diffstat (limited to 'src')
| -rw-r--r-- | src/dired.c | 4 | ||||
| -rw-r--r-- | src/regex.c | 73 | ||||
| -rw-r--r-- | src/regex.h | 4 | ||||
| -rw-r--r-- | src/search.c | 71 |
4 files changed, 45 insertions, 107 deletions
diff --git a/src/dired.c b/src/dired.c index c69164b2a1f..e468147e8b2 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -253,11 +253,9 @@ 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_match_object = name, | 256 | || re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0); |
| 257 | re_search (bufp, SSDATA (name), len, 0, len, 0) >= 0)); | ||
| 258 | 257 | ||
| 259 | immediate_quit = 0; | 258 | immediate_quit = 0; |
| 260 | re_match_object = Qnil; /* Stop protecting name from GC. */ | ||
| 261 | 259 | ||
| 262 | if (wanted) | 260 | if (wanted) |
| 263 | { | 261 | { |
diff --git a/src/regex.c b/src/regex.c index 8d769cc6c82..1c6c9e5c18b 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -1365,62 +1365,11 @@ typedef struct | |||
| 1365 | #define NEXT_FAILURE_HANDLE(h) fail_stack.stack[(h) - 3].integer | 1365 | #define NEXT_FAILURE_HANDLE(h) fail_stack.stack[(h) - 3].integer |
| 1366 | #define TOP_FAILURE_HANDLE() fail_stack.frame | 1366 | #define TOP_FAILURE_HANDLE() fail_stack.frame |
| 1367 | 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 | ||
| 1376 | 1368 | ||
| 1377 | #define ENSURE_FAIL_STACK(space) \ | 1369 | #define ENSURE_FAIL_STACK(space) \ |
| 1378 | while (REMAINING_AVAIL_SLOTS <= space) { \ | 1370 | 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 | } \ | ||
| 1402 | if (!GROW_FAIL_STACK (fail_stack)) \ | 1371 | if (!GROW_FAIL_STACK (fail_stack)) \ |
| 1403 | return -2; \ | 1372 | 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 | } \ | ||
| 1424 | DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\ | 1373 | DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\ |
| 1425 | DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\ | 1374 | DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\ |
| 1426 | } | 1375 | } |
| @@ -4346,11 +4295,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4346 | /* Loop through the string, looking for a place to start matching. */ | 4295 | /* Loop through the string, looking for a place to start matching. */ |
| 4347 | for (;;) | 4296 | for (;;) |
| 4348 | { | 4297 | { |
| 4349 | ptrdiff_t offset1; | ||
| 4350 | ptrdiff_t offset2 UNINIT; /* The UNINIT works around GCC bug 78081. */ | ||
| 4351 | re_char *orig_base; | ||
| 4352 | bool might_relocate; | ||
| 4353 | |||
| 4354 | /* If the pattern is anchored, | 4298 | /* If the pattern is anchored, |
| 4355 | skip quickly past places we cannot match. | 4299 | skip quickly past places we cannot match. |
| 4356 | We don't bother to treat startpos == 0 specially | 4300 | We don't bother to treat startpos == 0 specially |
| @@ -4467,16 +4411,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4467 | && !bufp->can_be_null) | 4411 | && !bufp->can_be_null) |
| 4468 | return -1; | 4412 | return -1; |
| 4469 | 4413 | ||
| 4470 | /* re_match_2_internal may allocate, relocating the Lisp text | ||
| 4471 | object that we're searching. */ | ||
| 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 | |||
| 4480 | val = re_match_2_internal (bufp, string1, size1, string2, size2, | 4414 | val = re_match_2_internal (bufp, string1, size1, string2, size2, |
| 4481 | startpos, regs, stop); | 4415 | startpos, regs, stop); |
| 4482 | 4416 | ||
| @@ -4486,13 +4420,6 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, | |||
| 4486 | if (val == -2) | 4420 | if (val == -2) |
| 4487 | return -2; | 4421 | return -2; |
| 4488 | 4422 | ||
| 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 | |||
| 4496 | advance: | 4423 | advance: |
| 4497 | if (!range) | 4424 | if (!range) |
| 4498 | break; | 4425 | break; |
diff --git a/src/regex.h b/src/regex.h index cb0796fe9cb..4922440e472 100644 --- a/src/regex.h +++ b/src/regex.h | |||
| @@ -176,9 +176,7 @@ extern reg_syntax_t re_syntax_options; | |||
| 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 are matching. | 178 | /* In Emacs, this is the string or buffer in which we are matching. |
| 179 | It is used for looking up syntax properties, and also to recompute | 179 | It is used for looking up syntax properties. |
| 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 | 180 | ||
| 183 | If the value is a Lisp string object, we are matching text in that | 181 | 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 | 182 | string; if it's nil, we are matching text in the current buffer; if |
diff --git a/src/search.c b/src/search.c index 92bfa88eb82..25d81f2baf6 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -280,10 +280,8 @@ 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 that make up the | 283 | /* Get pointers and sizes of the two strings |
| 284 | visible portion of the buffer. Note that we can use pointers | 284 | that make up the visible portion of the buffer. */ |
| 285 | here, unlike in search_buffer, because we only call re_match_2 | ||
| 286 | once, after which we never use the pointers again. */ | ||
| 287 | 285 | ||
| 288 | p1 = BEGV_ADDR; | 286 | p1 = BEGV_ADDR; |
| 289 | s1 = GPT_BYTE - BEGV_BYTE; | 287 | s1 = GPT_BYTE - BEGV_BYTE; |
| @@ -303,12 +301,20 @@ looking_at_1 (Lisp_Object string, bool posix) | |||
| 303 | 301 | ||
| 304 | re_match_object = Qnil; | 302 | re_match_object = Qnil; |
| 305 | 303 | ||
| 304 | #ifdef REL_ALLOC | ||
| 305 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 306 | searching it. */ | ||
| 307 | r_alloc_inhibit_buffer_relocation (1); | ||
| 308 | #endif | ||
| 306 | i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 309 | i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 307 | PT_BYTE - BEGV_BYTE, | 310 | PT_BYTE - BEGV_BYTE, |
| 308 | (NILP (Vinhibit_changing_match_data) | 311 | (NILP (Vinhibit_changing_match_data) |
| 309 | ? &search_regs : NULL), | 312 | ? &search_regs : NULL), |
| 310 | ZV_BYTE - BEGV_BYTE); | 313 | ZV_BYTE - BEGV_BYTE); |
| 311 | immediate_quit = 0; | 314 | immediate_quit = 0; |
| 315 | #ifdef REL_ALLOC | ||
| 316 | r_alloc_inhibit_buffer_relocation (0); | ||
| 317 | #endif | ||
| 312 | 318 | ||
| 313 | if (i == -2) | 319 | if (i == -2) |
| 314 | matcher_overflow (); | 320 | matcher_overflow (); |
| @@ -402,7 +408,6 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, | |||
| 402 | (NILP (Vinhibit_changing_match_data) | 408 | (NILP (Vinhibit_changing_match_data) |
| 403 | ? &search_regs : NULL)); | 409 | ? &search_regs : NULL)); |
| 404 | immediate_quit = 0; | 410 | immediate_quit = 0; |
| 405 | re_match_object = Qnil; /* Stop protecting string from GC. */ | ||
| 406 | 411 | ||
| 407 | /* Set last_thing_searched only when match data is changed. */ | 412 | /* Set last_thing_searched only when match data is changed. */ |
| 408 | if (NILP (Vinhibit_changing_match_data)) | 413 | if (NILP (Vinhibit_changing_match_data)) |
| @@ -473,7 +478,6 @@ fast_string_match_internal (Lisp_Object regexp, Lisp_Object string, | |||
| 473 | SBYTES (string), 0, | 478 | SBYTES (string), 0, |
| 474 | SBYTES (string), 0); | 479 | SBYTES (string), 0); |
| 475 | immediate_quit = 0; | 480 | immediate_quit = 0; |
| 476 | re_match_object = Qnil; /* Stop protecting string from GC. */ | ||
| 477 | return val; | 481 | return val; |
| 478 | } | 482 | } |
| 479 | 483 | ||
| @@ -558,10 +562,17 @@ fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 558 | 562 | ||
| 559 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); | 563 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); |
| 560 | immediate_quit = 1; | 564 | immediate_quit = 1; |
| 565 | #ifdef REL_ALLOC | ||
| 566 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 567 | searching it. */ | ||
| 568 | r_alloc_inhibit_buffer_relocation (1); | ||
| 569 | #endif | ||
| 561 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, | 570 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, |
| 562 | pos_byte, NULL, limit_byte); | 571 | pos_byte, NULL, limit_byte); |
| 572 | #ifdef REL_ALLOC | ||
| 573 | r_alloc_inhibit_buffer_relocation (0); | ||
| 574 | #endif | ||
| 563 | immediate_quit = 0; | 575 | immediate_quit = 0; |
| 564 | re_match_object = Qnil; /* Stop protecting string from GC. */ | ||
| 565 | 576 | ||
| 566 | return len; | 577 | return len; |
| 567 | } | 578 | } |
| @@ -1176,8 +1187,8 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1176 | 1187 | ||
| 1177 | if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) | 1188 | if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) |
| 1178 | { | 1189 | { |
| 1179 | unsigned char *base; | 1190 | unsigned char *p1, *p2; |
| 1180 | ptrdiff_t off1, off2, s1, s2; | 1191 | ptrdiff_t s1, s2; |
| 1181 | struct re_pattern_buffer *bufp; | 1192 | struct re_pattern_buffer *bufp; |
| 1182 | 1193 | ||
| 1183 | bufp = compile_pattern (string, | 1194 | bufp = compile_pattern (string, |
| @@ -1191,19 +1202,16 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1191 | can take too long. */ | 1202 | can take too long. */ |
| 1192 | QUIT; /* Do a pending quit right away, | 1203 | QUIT; /* Do a pending quit right away, |
| 1193 | to avoid paradoxical behavior */ | 1204 | to avoid paradoxical behavior */ |
| 1194 | /* Get offsets and sizes of the two strings that make up the | 1205 | /* Get pointers and sizes of the two strings |
| 1195 | visible portion of the buffer. We compute offsets instead of | 1206 | that make up the visible portion of the buffer. */ |
| 1196 | pointers because re_search_2 may call malloc and therefore | ||
| 1197 | change the buffer text address. */ | ||
| 1198 | 1207 | ||
| 1199 | base = current_buffer->text->beg; | 1208 | p1 = BEGV_ADDR; |
| 1200 | off1 = BEGV_ADDR - base; | ||
| 1201 | s1 = GPT_BYTE - BEGV_BYTE; | 1209 | s1 = GPT_BYTE - BEGV_BYTE; |
| 1202 | off2 = GAP_END_ADDR - base; | 1210 | p2 = GAP_END_ADDR; |
| 1203 | s2 = ZV_BYTE - GPT_BYTE; | 1211 | s2 = ZV_BYTE - GPT_BYTE; |
| 1204 | if (s1 < 0) | 1212 | if (s1 < 0) |
| 1205 | { | 1213 | { |
| 1206 | off2 = off1; | 1214 | p2 = p1; |
| 1207 | s2 = ZV_BYTE - BEGV_BYTE; | 1215 | s2 = ZV_BYTE - BEGV_BYTE; |
| 1208 | s1 = 0; | 1216 | s1 = 0; |
| 1209 | } | 1217 | } |
| @@ -1214,20 +1222,22 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1214 | } | 1222 | } |
| 1215 | re_match_object = Qnil; | 1223 | re_match_object = Qnil; |
| 1216 | 1224 | ||
| 1225 | #ifdef REL_ALLOC | ||
| 1226 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 1227 | searching it. */ | ||
| 1228 | r_alloc_inhibit_buffer_relocation (1); | ||
| 1229 | #endif | ||
| 1230 | |||
| 1217 | while (n < 0) | 1231 | while (n < 0) |
| 1218 | { | 1232 | { |
| 1219 | ptrdiff_t val; | 1233 | ptrdiff_t val; |
| 1220 | 1234 | ||
| 1221 | val = re_search_2 (bufp, | 1235 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 1222 | (char*) (base + off1), s1, | ||
| 1223 | (char*) (base + off2), s2, | ||
| 1224 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | 1236 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
| 1225 | (NILP (Vinhibit_changing_match_data) | 1237 | (NILP (Vinhibit_changing_match_data) |
| 1226 | ? &search_regs : &search_regs_1), | 1238 | ? &search_regs : &search_regs_1), |
| 1227 | /* Don't allow match past current point */ | 1239 | /* Don't allow match past current point */ |
| 1228 | pos_byte - BEGV_BYTE); | 1240 | pos_byte - BEGV_BYTE); |
| 1229 | /* Update 'base' due to possible relocation inside re_search_2. */ | ||
| 1230 | base = current_buffer->text->beg; | ||
| 1231 | if (val == -2) | 1241 | if (val == -2) |
| 1232 | { | 1242 | { |
| 1233 | matcher_overflow (); | 1243 | matcher_overflow (); |
| @@ -1259,6 +1269,9 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1259 | else | 1269 | else |
| 1260 | { | 1270 | { |
| 1261 | immediate_quit = 0; | 1271 | immediate_quit = 0; |
| 1272 | #ifdef REL_ALLOC | ||
| 1273 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1274 | #endif | ||
| 1262 | return (n); | 1275 | return (n); |
| 1263 | } | 1276 | } |
| 1264 | n++; | 1277 | n++; |
| @@ -1267,15 +1280,11 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1267 | { | 1280 | { |
| 1268 | ptrdiff_t val; | 1281 | ptrdiff_t val; |
| 1269 | 1282 | ||
| 1270 | val = re_search_2 (bufp, | 1283 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 1271 | (char*) (base + off1), s1, | 1284 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
| 1272 | (char*) (base + off2), s2, | ||
| 1273 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | ||
| 1274 | (NILP (Vinhibit_changing_match_data) | 1285 | (NILP (Vinhibit_changing_match_data) |
| 1275 | ? &search_regs : &search_regs_1), | 1286 | ? &search_regs : &search_regs_1), |
| 1276 | lim_byte - BEGV_BYTE); | 1287 | lim_byte - BEGV_BYTE); |
| 1277 | /* Update 'base' due to possible relocation inside re_search_2. */ | ||
| 1278 | base = current_buffer->text->beg; | ||
| 1279 | if (val == -2) | 1288 | if (val == -2) |
| 1280 | { | 1289 | { |
| 1281 | matcher_overflow (); | 1290 | matcher_overflow (); |
| @@ -1305,11 +1314,17 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1305 | else | 1314 | else |
| 1306 | { | 1315 | { |
| 1307 | immediate_quit = 0; | 1316 | immediate_quit = 0; |
| 1317 | #ifdef REL_ALLOC | ||
| 1318 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1319 | #endif | ||
| 1308 | return (0 - n); | 1320 | return (0 - n); |
| 1309 | } | 1321 | } |
| 1310 | n--; | 1322 | n--; |
| 1311 | } | 1323 | } |
| 1312 | immediate_quit = 0; | 1324 | immediate_quit = 0; |
| 1325 | #ifdef REL_ALLOC | ||
| 1326 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1327 | #endif | ||
| 1313 | return (pos); | 1328 | return (pos); |
| 1314 | } | 1329 | } |
| 1315 | else /* non-RE case */ | 1330 | else /* non-RE case */ |