From: Tom Tromey Date: Tue, 29 Sep 2009 04:21:31 +0000 (+0200) Subject: Make regular expression match data per-thread. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e2819f5f166bfe15e1bd8b361428e6d3280ccd16;p=emacs.git Make regular expression match data per-thread. --- diff --git a/src/search.c b/src/search.c index e5959460590..5f74a8fffad 100644 --- a/src/search.c +++ b/src/search.c @@ -60,30 +60,6 @@ struct regexp_cache searchbufs[REGEXP_CACHE_SIZE]; struct regexp_cache *searchbuf_head; -/* Every call to re_match, etc., must pass &search_regs as the regs - argument unless you can show it is unnecessary (i.e., if re_match - is certainly going to be called again before region-around-match - can be called). - - Since the registers are now dynamically allocated, we need to make - sure not to refer to the Nth register before checking that it has - been allocated by checking search_regs.num_regs. - - The regex code keeps track of whether it has allocated the search - buffer using bits in the re_pattern_buffer. This means that whenever - you compile a new pattern, it completely forgets whether it has - allocated any registers, and will allocate new registers the next - time you call a searching or matching function. Therefore, we need - to call re_set_registers after compiling a new pattern or after - setting the match registers, so that the regex functions will be - able to free or re-allocate it properly. */ -static struct re_registers search_regs; - -/* The buffer in which the last search was performed, or - Qt if the last search was done in a string; - Qnil if no searching has been done yet. */ -static Lisp_Object last_thing_searched; - /* error condition signaled when regexp compile_pattern fails */ Lisp_Object Qinvalid_regexp; @@ -3162,12 +3138,6 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) return Qnil; } -/* If non-zero the match data have been saved in saved_search_regs - during the execution of a sentinel or filter. */ -static int search_regs_saved; -static struct re_registers saved_search_regs; -static Lisp_Object saved_last_thing_searched; - /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data if asynchronous code (filter or sentinel) is running. */ static void @@ -3294,13 +3264,7 @@ syms_of_search () Fput (Qinvalid_regexp, Qerror_conditions, pure_cons (Qinvalid_regexp, pure_cons (Qerror, Qnil))); Fput (Qinvalid_regexp, Qerror_message, - make_pure_c_string ("Invalid regexp")); - - last_thing_searched = Qnil; - staticpro (&last_thing_searched); - - saved_last_thing_searched = Qnil; - staticpro (&saved_last_thing_searched); + build_string ("Invalid regexp")); DEFVAR_LISP ("search-spaces-regexp", &Vsearch_spaces_regexp, doc: /* Regexp to substitute for bunches of spaces in regexp search. diff --git a/src/thread.c b/src/thread.c index e83793ba765..295d2f66cad 100644 --- a/src/thread.c +++ b/src/thread.c @@ -345,7 +345,7 @@ does not try to get a lock on the current buffer. */) abort (); new_thread = (struct thread_state *) allocate_pseudovector (VECSIZE (struct thread_state), - 2, PVEC_THREAD); + 4, PVEC_THREAD); memset ((char *) new_thread + OFFSETOF (struct thread_state, m_gcprolist), 0, sizeof (struct thread_state) - OFFSETOF (struct thread_state, m_gcprolist)); @@ -354,6 +354,8 @@ does not try to get a lock on the current buffer. */) new_thread->blocked = 0; new_thread->nolock = !EQ (nolock, Qnil); new_thread->initial_specpdl = Qnil; + new_thread->m_last_thing_searched = Qnil; /* copy from parent? */ + new_thread->m_saved_last_thing_searched = Qnil; new_thread->m_current_buffer = current_thread->m_current_buffer; new_thread->stack_bottom = &stack_pos; diff --git a/src/thread.h b/src/thread.h index 066bac7dbf6..fcc42773238 100644 --- a/src/thread.h +++ b/src/thread.h @@ -1,3 +1,4 @@ +#include "regex.h" struct thread_state { @@ -11,6 +12,15 @@ struct thread_state initial specpdl. */ Lisp_Object initial_specpdl; + /* The buffer in which the last search was performed, or + Qt if the last search was done in a string; + Qnil if no searching has been done yet. */ + Lisp_Object m_last_thing_searched; +#define last_thing_searched (current_thread->m_last_thing_searched) + + Lisp_Object m_saved_last_thing_searched; +#define saved_last_thing_searched (current_thread->m_saved_last_thing_searched) + /* Recording what needs to be marked for gc. */ struct gcpro *m_gcprolist; #define gcprolist (current_thread->m_gcprolist) @@ -68,6 +78,34 @@ struct thread_state struct buffer *m_current_buffer; #define current_buffer (current_thread->m_current_buffer) + /* Every call to re_match, etc., must pass &search_regs as the regs + argument unless you can show it is unnecessary (i.e., if re_match + is certainly going to be called again before region-around-match + can be called). + + Since the registers are now dynamically allocated, we need to make + sure not to refer to the Nth register before checking that it has + been allocated by checking search_regs.num_regs. + + The regex code keeps track of whether it has allocated the search + buffer using bits in the re_pattern_buffer. This means that whenever + you compile a new pattern, it completely forgets whether it has + allocated any registers, and will allocate new registers the next + time you call a searching or matching function. Therefore, we need + to call re_set_registers after compiling a new pattern or after + setting the match registers, so that the regex functions will be + able to free or re-allocate it properly. */ + struct re_registers m_search_regs; +#define search_regs (current_thread->m_search_regs) + + /* If non-zero the match data have been saved in saved_search_regs + during the execution of a sentinel or filter. */ + int m_search_regs_saved; +#define search_regs_saved (current_thread->m_search_regs_saved) + + struct re_registers m_saved_search_regs; +#define saved_search_regs (current_thread->m_saved_search_regs) + struct thread_state *next_thread; pthread_t pthread_id;