unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: 17172@debbugs.gnu.org
Subject: bug#17172: 24.3.50; Timeouts when pasting from mouse
Date: Tue, 15 Apr 2014 01:02:34 -0700	[thread overview]
Message-ID: <534CE79A.3030600@cs.ucla.edu> (raw)
In-Reply-To: <87eh1fsved.fsf@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Thanks for the bug report.  I can't reproduce the problem on my Fedora 
20 x86-64 desktop, but in reviewing xgselect.c I see some glitches that 
could explain things.  Please try the attached patch and let us know 
whether it helps with your problem.  Please compile with 
-DENABLE_CHECKING so that the patch's 'eassert' calls have teeth.  Thanks.

[-- Attachment #2: xgselect.diff --]
[-- Type: text/plain, Size: 3504 bytes --]

=== modified file 'src/xgselect.c'
--- src/xgselect.c	2014-03-05 06:31:57 +0000
+++ src/xgselect.c	2014-04-15 07:52:04 +0000
@@ -33,16 +33,15 @@
 xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
 	   struct timespec const *timeout, sigset_t const *sigmask)
 {
-  fd_set all_rfds, all_wfds;
+  fd_set all_rfds, all_wfds, all_efds;
   struct timespec tmo;
   struct timespec const *tmop = timeout;
 
   GMainContext *context;
-  int have_wfds = wfds != NULL;
   GPollFD gfds_buf[128];
   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 n_gfds, retval = 0, all_lim = fds_lim;
   int i, nfds, tmo_in_millisec;
   bool need_to_dispatch;
   USE_SAFE_ALLOCA;
@@ -59,6 +58,8 @@
   else FD_ZERO (&all_rfds);
   if (wfds) all_wfds = *wfds;
   else FD_ZERO (&all_wfds);
+  eassert (!efds);
+  FD_ZERO (&all_efds);
 
   n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,
 				 gfds, gfds_size);
@@ -71,19 +72,28 @@
     }
 
   for (i = 0; i < n_gfds; ++i)
-    {
-      if (gfds[i].events & G_IO_IN)
-        {
-          FD_SET (gfds[i].fd, &all_rfds);
-          if (gfds[i].fd > max_fds) max_fds = gfds[i].fd;
-        }
-      if (gfds[i].events & G_IO_OUT)
-        {
-          FD_SET (gfds[i].fd, &all_wfds);
-          if (gfds[i].fd > max_fds) max_fds = gfds[i].fd;
-          have_wfds = 1;
-        }
-    }
+    if (gfds[i].events & (G_IO_IN | G_IO_OUT | G_IO_PRI))
+      {
+	int fd = gfds[i].fd;
+	eassert (0 <= fd && fd < FD_SETSIZE);
+	for (; all_lim <= fd; all_lim++)
+	  {
+	    FD_CLR (all_lim, &all_rfds);
+	    FD_CLR (all_lim, &all_wfds);
+	  }
+	if (gfds[i].events & G_IO_IN)
+	  {
+	    eassert (! (rfds && fd < fds_lim && FD_ISSET (fd, rfds)));
+	    FD_SET (fd, &all_rfds);
+	  }
+	if (gfds[i].events & G_IO_OUT)
+	  {
+	    eassert (! (wfds && fd < fds_lim && FD_ISSET (fd, wfds)));
+	    FD_SET (fd, &all_wfds);
+	  }
+	if (gfds[i].events & G_IO_PRI)
+	  FD_SET (fd, &all_efds);
+      }
 
   SAFE_FREE ();
 
@@ -95,34 +105,28 @@
 	tmop = &tmo;
     }
 
-  fds_lim = max_fds + 1;
-  nfds = pselect (fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL,
-		  efds, tmop, sigmask);
+  nfds = pselect (all_lim, &all_rfds, &all_wfds, &all_efds, tmop, sigmask);
 
   if (nfds < 0)
     retval = nfds;
-  else if (nfds > 0)
+  else
     {
       for (i = 0; i < fds_lim; ++i)
         {
-          if (FD_ISSET (i, &all_rfds))
-            {
-              if (rfds && FD_ISSET (i, rfds)) ++retval;
-              else ++our_fds;
-            }
-          else if (rfds)
-            FD_CLR (i, rfds);
-
-          if (have_wfds && FD_ISSET (i, &all_wfds))
-            {
-              if (wfds && FD_ISSET (i, wfds)) ++retval;
-              else ++our_fds;
-            }
-          else if (wfds)
-            FD_CLR (i, wfds);
-
-          if (efds && FD_ISSET (i, efds))
-            ++retval;
+	  if (rfds && FD_ISSET (i, rfds))
+	    {
+	      if (FD_ISSET (i, &all_rfds))
+		retval++;
+	      else
+		FD_CLR (i, rfds);
+	    }
+	  if (wfds && FD_ISSET (i, wfds))
+	    {
+	      if (FD_ISSET (i, &all_wfds))
+		retval++;
+	      else
+		FD_CLR (i, wfds);
+	    }
         }
     }
 
@@ -142,7 +146,7 @@
     }
 
   /* To not have to recalculate timeout, return like this.  */
-  if ((our_fds > 0 || (nfds == 0 && tmop == &tmo)) && (retval == 0))
+  if (retval == 0 && (0 < nfds || tmop == &tmo))
     {
       retval = -1;
       errno = EINTR;


  reply	other threads:[~2014-04-15  8:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-02 13:39 bug#17172: 24.3.50; Timeouts when pasting from mouse Alex Bennée
2014-04-15  8:02 ` Paul Eggert [this message]
2014-04-15 10:17   ` Jan D.
2014-04-15 11:10     ` Nicolas Richard
2014-04-15 14:01     ` Alex Bennée
2014-04-15 16:01     ` Paul Eggert
2014-04-15 17:29       ` Jan Djärv
2014-04-15 20:19         ` Paul Eggert
2014-04-15 20:41           ` Jan Djärv
2014-04-17  7:53             ` Jan Djärv
2014-04-17  8:33               ` Nicolas Richard
2014-04-17  9:20                 ` Jan Djärv
2014-04-17 10:19                   ` Nicolas Richard
2014-04-17 12:10                     ` Jan Djärv
2014-04-29  9:22                       ` Nicolas Richard
2014-04-17 16:31                 ` Jan Djärv
2014-04-15 16:00   ` Eli Zaretskii
2014-04-29  9:22   ` Nicolas Richard
2014-12-24 16:58 ` bug#17172: Timeouts when pasting David A. Thompson
2014-12-27 10:39   ` Torsten Bronger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=534CE79A.3030600@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=17172@debbugs.gnu.org \
    --cc=alex.bennee@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).