Subject: Re: Issue with Emacs 23.4

From: Paul Eggert <[email-masked]>
Date: Tue, 15 May 2012 14:51:53 -0700

On 05/15/2012 12:08 PM, Ken Brown wrote:

> I think this bug still exists, in slightly different form, in
> emacs-24.  The call of g_main_context_query in xgselect.c:62 still
> uses the variables gfds and gfds_size, which are not initialized by
> xgselect_initialize if we're running emacs -nw.

They are initialized to NULL and zero, which should work for
all their uses.

> more fundamentally, it doesn't make sense for emacs -nw to be interacting
> with GLib at all.  I suggest the attached patch.

That patch assumes C99's statements before declarations.
I assume the following minor rewrite of it is OK too?

=== modified file 'src/xgselect.c'
--- src/xgselect.c	2012-05-10 05:27:24 +0000
+++ src/xgselect.c	2012-05-15 21:30:36 +0000
@@ -38,17 +38,21 @@ xg_select (int max_fds, SELECT_TYPE *rfd
   SELECT_TYPE all_rfds, all_wfds;
   EMACS_TIME tmo, *tmop = timeout;
 
-  GMainContext *context = g_main_context_default ();
+  GMainContext *context;
   int have_wfds = wfds != NULL;
   int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0;
   int i, nfds, fds_lim, tmo_in_millisec;
 
+  if (inhibit_window_system || !display_arg)
+    return select (max_fds, rfds, wfds, efds, timeout);
+
   if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds));
   else FD_ZERO (&all_rfds);
   if (wfds) memcpy (&all_wfds, wfds, sizeof (all_rfds));
   else FD_ZERO (&all_wfds);
 
   /* Update event sources in GLib. */
+  context = g_main_context_default ();
   g_main_context_pending (context);
 
   do {