commit 53d5bd786130a937a0e691e0c470675fe9c55485 (HEAD, refs/remotes/origin/master) Author: Ken Raeburn Date: Fri Dec 30 17:51:35 2016 -0500 Don't call xg_select for a NextStep build. NextStep builds use glib but don't use xg_select. * src/process.c (wait_reading_process_output): Don't call xg_select for a NextStep build. diff --git a/src/process.c b/src/process.c index c0c52c232b..0d88b2ce28 100644 --- a/src/process.c +++ b/src/process.c @@ -5341,8 +5341,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, } #endif -/* HAVE_GLIB builds call thread_select in xgselect.c. */ -#ifdef HAVE_GLIB +/* Non-macOS HAVE_GLIB builds call thread_select in xgselect.c. */ +#if defined HAVE_GLIB && !defined HAVE_NS nfds = xg_select (max_desc + 1, &Available, (check_write ? &Writeok : 0), NULL, &timeout, NULL); commit 064701dc2048722a7ebd5b602e8c060bf3da538e Author: Ken Raeburn Date: Fri Dec 30 17:41:26 2016 -0500 Increase the obarray size. In a typical GNU/Linux/X11 build, we wind up with over 15k symbols by the time we've started. The old obarray size ensured an average chain length of 10 or more. * src/lread.c (OBARRAY_SIZE): Increase to 15121. diff --git a/src/lread.c b/src/lread.c index 35348f1ddb..6005a7ce2d 100644 --- a/src/lread.c +++ b/src/lread.c @@ -4116,7 +4116,7 @@ OBARRAY defaults to the value of `obarray'. */) return Qnil; } -#define OBARRAY_SIZE 1511 +#define OBARRAY_SIZE 15121 void init_obarray (void) commit b0239945a36dafae908259a9a29c2a166ff53cee Author: Ken Raeburn Date: Thu Dec 29 20:56:31 2016 -0500 Initialize thread support for Xlib. * src/xterm.c (x_initialize) [THREADS_ENABLED]: Call XInitThreads before doing anything else with X. diff --git a/src/xterm.c b/src/xterm.c index bdc21e6de0..67bd13a042 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -12762,6 +12762,13 @@ x_initialize (void) /* Try to use interrupt input; if we can't, then start polling. */ Fset_input_interrupt_mode (Qt); +#if THREADS_ENABLED + /* This must be called before any other Xlib routines. */ + if (XInitThreads () == 0) + fprintf (stderr, + "Warning: An error occurred initializing X11 thread support!\n"); +#endif + #ifdef USE_X_TOOLKIT XtToolkitInitialize (); commit 108ef8033be79e9e5567002e85a316ecb5e77cad Author: Paul Eggert Date: Fri Dec 30 13:42:38 2016 -0800 Rename primary_thread to main_thread This avoids the confusion of using two different phrases "main thread" and "primary thread" internally to mean the same thing. See: http://lists.gnu.org/archive/html/emacs-devel/2016-12/msg01142.html * src/thread.c (main_thread): Rename from primary_thread, since the new name no longer clashes with main_thread_id and Emacs internals normally call this the "main thread". (init_main_thread): Rename from init_primary_thread. (main_thread_p): Rename from primary_thread_p. All uses changed. diff --git a/src/alloc.c b/src/alloc.c index 121d704235..d74c4bec7e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6404,7 +6404,7 @@ mark_object (Lisp_Object arg) #ifdef GC_CHECK_MARKED_OBJECTS m = mem_find (po); - if (m == MEM_NIL && !SUBRP (obj) && !primary_thread_p (po)) + if (m == MEM_NIL && !SUBRP (obj) && !main_thread_p (po)) emacs_abort (); #endif /* GC_CHECK_MARKED_OBJECTS */ @@ -6416,7 +6416,7 @@ mark_object (Lisp_Object arg) if (pvectype != PVEC_SUBR && pvectype != PVEC_BUFFER - && !primary_thread_p (po)) + && !main_thread_p (po)) CHECK_LIVE (live_vector_p); switch (pvectype) diff --git a/src/thread.c b/src/thread.c index 560d2cfa74..9a1198a0cc 100644 --- a/src/thread.c +++ b/src/thread.c @@ -26,11 +26,11 @@ along with GNU Emacs. If not, see . */ #include "coding.h" #include "syssignal.h" -static struct thread_state primary_thread; +static struct thread_state main_thread; -struct thread_state *current_thread = &primary_thread; +struct thread_state *current_thread = &main_thread; -static struct thread_state *all_threads = &primary_thread; +static struct thread_state *all_threads = &main_thread; static sys_mutex_t global_lock; @@ -927,41 +927,41 @@ thread_check_current_buffer (struct buffer *buffer) static void -init_primary_thread (void) +init_main_thread (void) { - primary_thread.header.size + main_thread.header.size = PSEUDOVECSIZE (struct thread_state, m_stack_bottom); - XSETPVECTYPE (&primary_thread, PVEC_THREAD); - primary_thread.m_last_thing_searched = Qnil; - primary_thread.m_saved_last_thing_searched = Qnil; - primary_thread.name = Qnil; - primary_thread.function = Qnil; - primary_thread.error_symbol = Qnil; - primary_thread.error_data = Qnil; - primary_thread.event_object = Qnil; + XSETPVECTYPE (&main_thread, PVEC_THREAD); + main_thread.m_last_thing_searched = Qnil; + main_thread.m_saved_last_thing_searched = Qnil; + main_thread.name = Qnil; + main_thread.function = Qnil; + main_thread.error_symbol = Qnil; + main_thread.error_data = Qnil; + main_thread.event_object = Qnil; } bool -primary_thread_p (void *ptr) +main_thread_p (void *ptr) { - return (ptr == &primary_thread) ? true : false; + return ptr == &main_thread; } void init_threads_once (void) { - init_primary_thread (); + init_main_thread (); } void init_threads (void) { - init_primary_thread (); - sys_cond_init (&primary_thread.thread_condvar); + init_main_thread (); + sys_cond_init (&main_thread.thread_condvar); sys_mutex_init (&global_lock); sys_mutex_lock (&global_lock); - current_thread = &primary_thread; - primary_thread.thread_id = sys_thread_self (); + current_thread = &main_thread; + main_thread.thread_id = sys_thread_self (); } void diff --git a/src/thread.h b/src/thread.h index 9472ae3051..e6dc668f95 100644 --- a/src/thread.h +++ b/src/thread.h @@ -285,7 +285,7 @@ extern void maybe_reacquire_global_lock (void); extern void init_threads_once (void); extern void init_threads (void); extern void syms_of_threads (void); -extern bool primary_thread_p (void *); +extern bool main_thread_p (void *); typedef int select_func (int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *); diff --git a/src/w32.h b/src/w32.h index c73ff302c0..03dee099c0 100644 --- a/src/w32.h +++ b/src/w32.h @@ -89,7 +89,7 @@ typedef struct _child_process terminate it by sys_kill. */ HWND hwnd; /* Information about subprocess returned by CreateProcess. Includes - handles to the subprocess and its primary thread, and the + handles to the subprocess and its main thread, and the corresponding process ID and thread ID numbers. The PID is mirrored by the 'pid' member above. The process handle is used to wait on it. */ commit 966d51592f07ad9de6afebcd828e667cce0f6a27 Author: Paul Eggert Date: Fri Dec 30 13:01:39 2016 -0800 Rename main_thread to main_thread_id and simplify * src/emacs-module.c: Include syssignal.h, for main_thread_id. [HAVE_PTHREAD]: Do not include pthread.h. (main_thread): Remove. All uses replaced by main_thread_id, or by dwMainThreadId on NT. Since the HAVE_PTHREAD code is now using the main_thread_id established by sysdep.c, there is no need for a separate copy of the main thread ID here. (module_init): Remove. All uses removed. * src/sysdep.c (main_thread_id) [HAVE_PTHREAD]: Rename from main_thread. All uses changed. Now extern. diff --git a/src/emacs-module.c b/src/emacs-module.c index 68aeb0ce70..280c0550c9 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "dynlib.h" #include "coding.h" +#include "syssignal.h" #include #include @@ -41,15 +42,9 @@ enum { module_has_cleanup = true }; enum { module_has_cleanup = false }; #endif -/* Handle to the main thread. Used to verify that modules call us in - the right thread. */ -#ifdef HAVE_PTHREAD -# include -static pthread_t main_thread; -#elif defined WINDOWSNT +#ifdef WINDOWSNT #include #include "w32term.h" -static DWORD main_thread; #endif /* True if Lisp_Object and emacs_value have the same representation. @@ -751,9 +746,9 @@ static void check_main_thread (void) { #ifdef HAVE_PTHREAD - eassert (pthread_equal (pthread_self (), main_thread)); + eassert (pthread_equal (pthread_self (), main_thread_id)); #elif defined WINDOWSNT - eassert (GetCurrentThreadId () == main_thread); + eassert (GetCurrentThreadId () == dwMainThreadId); #endif } @@ -1062,20 +1057,3 @@ syms_of_module (void) DEFSYM (Qinternal__module_call, "internal--module-call"); defsubr (&Sinternal_module_call); } - -/* Unlike syms_of_module, this initializer is called even from an - initialized (dumped) Emacs. */ - -void -module_init (void) -{ - /* It is not guaranteed that dynamic initializers run in the main thread, - therefore detect the main thread here. */ -#ifdef HAVE_PTHREAD - main_thread = pthread_self (); -#elif defined WINDOWSNT - /* The 'main' function already recorded the main thread's thread ID, - so we need just to use it . */ - main_thread = dwMainThreadId; -#endif -} diff --git a/src/emacs.c b/src/emacs.c index eff3f9dcb8..d461fe241c 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -738,8 +738,6 @@ main (int argc, char **argv) non-ASCII file names during startup. */ w32_init_file_name_codepage (); #endif - /* This has to be done before module_init is called below, so that - the latter could use the thread ID of the main thread. */ w32_init_main_thread (); #endif @@ -757,10 +755,6 @@ main (int argc, char **argv) init_standard_fds (); atexit (close_output_streams); -#ifdef HAVE_MODULES - module_init (); -#endif - sort_args (argc, argv); argc = 0; while (argv[argc]) argc++; diff --git a/src/lisp.h b/src/lisp.h index 1a586cab0d..8496308621 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3880,7 +3880,6 @@ extern bool let_shadows_global_binding_p (Lisp_Object symbol); extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p); /* Defined in emacs-module.c. */ -extern void module_init (void); extern void syms_of_module (void); #endif diff --git a/src/sysdep.c b/src/sysdep.c index 1ba336e387..1227afc8db 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1612,7 +1612,7 @@ emacs_sigaction_init (struct sigaction *action, signal_handler_t handler) } #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD -static pthread_t main_thread; +pthread_t main_thread_id; #endif /* SIG has arrived at the current process. Deliver it to the main @@ -1636,13 +1636,13 @@ deliver_process_signal (int sig, signal_handler_t handler) bool on_main_thread = true; #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD - if (! pthread_equal (pthread_self (), main_thread)) + if (! pthread_equal (pthread_self (), main_thread_id)) { sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, sig); pthread_sigmask (SIG_BLOCK, &blocked, 0); - pthread_kill (main_thread, sig); + pthread_kill (main_thread_id, sig); on_main_thread = false; } #endif @@ -1668,12 +1668,12 @@ deliver_thread_signal (int sig, signal_handler_t handler) int old_errno = errno; #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD - if (! pthread_equal (pthread_self (), main_thread)) + if (! pthread_equal (pthread_self (), main_thread_id)) { thread_backtrace_npointers = backtrace (thread_backtrace_buffer, BACKTRACE_LIMIT_MAX); sigaction (sig, &process_fatal_action, 0); - pthread_kill (main_thread, sig); + pthread_kill (main_thread_id, sig); /* Avoid further damage while the main thread is exiting. */ while (1) @@ -1796,7 +1796,7 @@ handle_sigsegv (int sig, siginfo_t *siginfo, void *arg) bool fatal = gc_in_progress; #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD - if (!fatal && !pthread_equal (pthread_self (), main_thread)) + if (!fatal && !pthread_equal (pthread_self (), main_thread_id)) fatal = true; #endif @@ -1888,7 +1888,7 @@ init_signals (bool dumping) sigemptyset (&empty_mask); #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD - main_thread = pthread_self (); + main_thread_id = pthread_self (); #endif #if !HAVE_DECL_SYS_SIGLIST && !defined _sys_siglist diff --git a/src/syssignal.h b/src/syssignal.h index 62704fc351..215aafe314 100644 --- a/src/syssignal.h +++ b/src/syssignal.h @@ -32,6 +32,7 @@ extern void unblock_tty_out_signal (sigset_t const *); #ifdef HAVE_PTHREAD #include +extern pthread_t main_thread_id; /* If defined, asynchronous signals delivered to a non-main thread are forwarded to the main thread. */ #define FORWARD_SIGNAL_TO_MAIN_THREAD commit aef40049e3b81972703d3bde47b0961bcb08d7e1 Author: Michael Albinus Date: Fri Dec 30 20:04:33 2016 +0100 * src/gfilenotify.c (Fgfile_monitor_name): Return a symbol. diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 1ad989a0d9..18ccfe4c46 100644 --- a/src/gfilenotify.c +++ b/src/gfilenotify.c @@ -281,8 +281,8 @@ invalid. */) DEFUN ("gfile-monitor-name", Fgfile_monitor_name, Sgfile_monitor_name, 1, 1, 0, doc: /* Return the internal monitor name for WATCH-DESCRIPTOR. -The result is a string, either "GInotifyFileMonitor", -"GKqueueFileMonitor", or "GPollFileMonitor". +The result is a symbol, either `GInotifyFileMonitor', +`GKqueueFileMonitor', `GFamFileMonitor', or `GPollFileMonitor'. WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. If WATCH-DESCRIPTOR is not valid, nil is returned. */) @@ -292,9 +292,8 @@ If WATCH-DESCRIPTOR is not valid, nil is returned. */) return Qnil; else { - Lisp_Object watch_object = Fassoc (watch_descriptor, watch_list); GFileMonitor *monitor = XINTPTR (watch_descriptor); - return build_string (G_OBJECT_TYPE_NAME (monitor)); + return Fmake_symbol (build_string (G_OBJECT_TYPE_NAME (monitor))); } } commit 83cc8a19b45cb2279c128b781e79d81bb91aac58 Author: Paul Eggert Date: Fri Dec 30 09:45:46 2016 -0800 * src/sysdep.c (deliver_process_signal): Improve comment. diff --git a/src/sysdep.c b/src/sysdep.c index 86d420f66c..1ba336e387 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1616,14 +1616,17 @@ static pthread_t main_thread; #endif /* SIG has arrived at the current process. Deliver it to the main - thread, which should handle it with HANDLER. + thread, which should handle it with HANDLER. (Delivering the + signal to some other thread might not work if the other thread is + about to exit.) If we are on the main thread, handle the signal SIG with HANDLER. Otherwise, redirect the signal to the main thread, blocking it from this thread. POSIX says any thread can receive a signal that is associated with a process, process group, or asynchronous event. - On GNU/Linux that is not true, but for other systems (FreeBSD at - least) it is. */ + On GNU/Linux the main thread typically gets a process signal unless + it's blocked, but other systems (FreeBSD at least) can deliver the + signal to other threads. */ void deliver_process_signal (int sig, signal_handler_t handler) { commit a285645b8ba0b01e559a26258035ae1a70e3fad2 Author: Alan Mackenzie Date: Fri Dec 30 15:31:42 2016 +0000 CC Mode: Fix the fontification of a spuriously recognised enum member. The "enum" was in an argument list, but triggered the fontification of a following identifier in the function block as though it were in an enum declaration. * lisp/progmodes/cc-fonts.el (c-font-lock-enum-body): New function. (c-basic-matchers-after): Replace the inline stanza for enum elements with a call to c-font-lock-enum-body. * lisp/progmodes/cc-langs.el (c-enum-clause-introduction-re): New language variable. diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 39e68f0b87..c213f1f198 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1493,6 +1493,22 @@ casts and declarations are fontified. Used on level 2 and higher." nil))) +(defun c-font-lock-enum-body (limit) + ;; Fontify the identifiers of each enum we find by searching forward. + ;; + ;; This function will be called from font-lock for a region bounded by POINT + ;; and LIMIT, as though it were to identify a keyword for + ;; font-lock-keyword-face. It always returns NIL to inhibit this and + ;; prevent a repeat invocation. See elisp/lispref page "Search-based + ;; Fontification". + (while (search-forward-regexp c-enum-clause-introduction-re limit t) + (when (save-excursion + (backward-char) + (c-backward-over-enum-header)) + (c-forward-syntactic-ws) + (c-font-lock-declarators limit t nil t))) + nil) + (defun c-font-lock-enum-tail (limit) ;; Fontify an enum's identifiers when POINT is within the enum's brace ;; block. @@ -2020,29 +2036,14 @@ on level 2 only and so aren't combined with `c-complex-decl-matchers'." generic casts and declarations are fontified. Used on level 2 and higher." - t `(,@(when (c-lang-const c-brace-id-list-kwds) + t `(,@(when (c-lang-const c-brace-list-decl-kwds) ;; Fontify the remaining identifiers inside an enum list when we start ;; inside it. `(c-font-lock-enum-tail ;; Fontify the identifiers inside enum lists. (The enum type ;; name is handled by `c-simple-decl-matchers' or ;; `c-complex-decl-matchers' below. - (,(c-make-font-lock-search-function - (concat - "\\<\\(" - (c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds)) - "\\)\\>" - ;; Disallow various common punctuation chars that can't come - ;; before the '{' of the enum list, to avoid searching too far. - "[^][{};/#=]*" - "{") - '((c-font-lock-declarators limit t nil t) - (save-match-data - (goto-char (match-end 0)) - (c-put-char-property (1- (point)) 'c-type - 'c-decl-id-start) - (c-forward-syntactic-ws)) - (goto-char (match-end 0))))))) + c-font-lock-enum-body)) ;; Fontify labels after goto etc. ,@(when (c-lang-const c-before-label-kwds) diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 83b8db3657..e80dc922e5 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -3292,6 +3292,24 @@ the invalidity of the putative template construct." c++ "[<;{},>()]") (c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re)) +(c-lang-defconst c-enum-clause-introduction-re + ;; A regexp loosely matching the start of an enum clause, starting at the + ;; keyword itself, and extending up to the "{". It may match text which + ;; isn't such a construct; more accurate tests will rule these out when + ;; needed. + t (if (c-lang-const c-brace-list-decl-kwds) + (concat + "\\<\\(" + (c-make-keywords-re nil (c-lang-const c-brace-list-decl-kwds)) + "\\)\\>" + ;; Disallow various common punctuation chars that can't come + ;; before the '{' of the enum list, to avoid searching too far. + "[^][{};/#=]*" + "{") + "\\<\\>")) +(c-lang-defvar c-enum-clause-introduction-re + (c-lang-const c-enum-clause-introduction-re)) + (c-lang-defconst c-enums-contain-decls "Non-nil means that an enum structure can contain declarations." t nil