]> git.eshelyaron.com Git - emacs.git/commitdiff
* src/xgselect.c (xg_select): Use g_main_context_acquire.
authorDima Kogan <dima@secretsauce.net>
Thu, 6 Nov 2014 03:02:11 +0000 (22:02 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 6 Nov 2014 03:02:11 +0000 (22:02 -0500)
Fixes: debbugs:18861
src/ChangeLog
src/xgselect.c

index f7088fce56336a6b4ab17ef04b65da474d90ef74..0b2f511d61f03382433c167d465552e2b0309c09 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-06  Dima Kogan  <dima@secretsauce.net>
+
+       * xgselect.c (xg_select): Use g_main_context_acquire (bug#18861).
+
 2014-11-05  Michael Albinus  <michael.albinus@gmx.de>
 
        * dired.c (Ffile_attributes): Return Qnil, if Fexpand_file_name
index 42fdfed0d3448c1311de48424c3ea5ae471e7095..6b22f3d1376cb66cc21c10d6db034ff80851e7f6 100644 (file)
@@ -55,19 +55,28 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
   GPollFD *gfds = gfds_buf;
   int gfds_size = sizeof gfds_buf / sizeof *gfds_buf;
   int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
-  int i, nfds, tmo_in_millisec;
+  bool context_acquired = false;
+  int i, nfds, tmo_in_millisec = -1;
   bool need_to_dispatch;
   USE_SAFE_ALLOCA;
 
   context = g_main_context_default ();
+  context_acquired = g_main_context_acquire (context);
+  /* FIXME: If we couldn't acquire the context, we just silently proceed
+     because this function handles more than just glib file descriptors.
+     Note that, as implemented, this failure is completely silent: there is
+     no feedback to the caller.  */
 
   if (rfds) all_rfds = *rfds;
   else FD_ZERO (&all_rfds);
   if (wfds) all_wfds = *wfds;
   else FD_ZERO (&all_wfds);
 
-  n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,
-                                gfds, gfds_size);
+  n_gfds = (context_acquired
+           ? g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,
+                                   gfds, gfds_size)
+           : -1);
+
   if (gfds_size < n_gfds)
     {
       SAFE_NALLOCA (gfds, sizeof *gfds, n_gfds);
@@ -152,6 +161,9 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
       errno = pselect_errno;
     }
 
+  if (context_acquired)
+    g_main_context_release (context);
+
   /* To not have to recalculate timeout, return like this.  */
   if ((our_fds > 0 || (nfds == 0 && tmop == &tmo)) && (retval == 0))
     {