aboutsummaryrefslogtreecommitdiffstats
path: root/src/search.c
diff options
context:
space:
mode:
authorPaul Eggert2016-11-04 15:01:17 -0700
committerPaul Eggert2016-11-04 15:01:17 -0700
commit6a20bd3579ef87103d5ea37e6b8193dc6385e547 (patch)
treee11a49c3cbb7e72ccfb6689fbad81bcccfd12665 /src/search.c
parent29559361f56c9398dcb69db7396dcfc0887843a2 (diff)
parentdbb341022870ecad4c9177485a6770a355633cc0 (diff)
downloademacs-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/search.c')
-rw-r--r--src/search.c71
1 files changed, 43 insertions, 28 deletions
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 */