unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Maciej Marcin Piechotka <maciej.piechotka08@imperial.ac.uk>
To: 10629@debbugs.gnu.org
Subject: bug#10629: Infinite loop in emacs 23 on terminal (-nw option) on xgselect.c:58-59 when compiled with gtk+ or gconf support
Date: Sat, 28 Jan 2012 17:01:34 +0000	[thread overview]
Message-ID: <1327770094.1921.2.camel@localhost.localdomain> (raw)
In-Reply-To: <1327767888.1934.14.camel@localhost.localdomain>


[-- Attachment #1.1: Type: text/plain, Size: 1007 bytes --]

On Sat, 2012-01-28 at 16:24 +0000, Maciej Marcin Piechotka wrote:
> I hit an infinite loop on gselect.c:58-59. After quick debugging I found
> that the problem is in loop xgselect.c:58-59:
> 
> while(n_gfds > gfds_size)
>   gfds_size *= 2;
> 
> Problem is that:
> 
> (gdb) p n_gfds
> $3 = 1
> (gdb) p gfds_size
> $4 = 0
> 
> 1. It seems that xgselect_initialize was not called as X system is
> initialized.
> 
> 2. Is there a reason why the code is not using (much more efficient but
> equivalent) such code in the first place:
> 
> if (ngfds > gfds_size)
>   {
>     gfds_size = 1 << g_bit_storage (ngfds);
>     xfree (gfds);
>     gfds = xmalloc (sizeof (*gfds) * gfds_size);
>   }
> 
> 3. The attached file get rids of initialization at all initializing at
> the cost of conditional freeing of gfds (and starting mallocing from 1
> instead of 128).
> 
> Best regards
> 

Ups. Sorry - I forgot to add one file to git index. Corrected patch
attached.

Best regards


[-- Attachment #1.2: 0001-Fix-infinit-loop-when-emacs-is-compiled-with-GTK-sup.patch --]
[-- Type: text/x-patch, Size: 2091 bytes --]

From 3a06fc2b48eb7e55834d8e5e4adda1f2286758db Mon Sep 17 00:00:00 2001
From: Maciej Piechotka <uzytkownik2@gmail.com>
Date: Sat, 28 Jan 2012 16:12:45 +0000
Subject: [PATCH] Fix infinit loop when emacs is compiled with GTK+ support
 and used in no-window mode

---
 src/xgselect.c |   17 +++++------------
 src/xgselect.h |    2 --
 src/xterm.c    |    2 --
 3 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/src/xgselect.c b/src/xgselect.c
index 333f7b1..4301eee 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -55,9 +55,11 @@ xg_select (max_fds, rfds, wfds, efds, timeout)
   do {
     if (n_gfds > gfds_size) 
       {
-        while (n_gfds > gfds_size) 
-          gfds_size *= 2;
-        xfree (gfds);
+        gfds_size = 1 << g_bit_storage (n_gfds);
+        if (gfds)
+          {
+            xfree (gfds);
+          }
         gfds = xmalloc (sizeof (*gfds) * gfds_size);
       }
 
@@ -152,14 +154,5 @@ xg_select (max_fds, rfds, wfds, efds, timeout)
 }
 #endif /* defined (USE_GTK) || defined (HAVE_GCONF) */
 
-void
-xgselect_initialize ()
-{
-#if defined (USE_GTK) || defined (HAVE_GCONF)
-  gfds_size = 128;
-  gfds = xmalloc (sizeof (*gfds)*gfds_size);
-#endif /* defined (USE_GTK) || defined (HAVE_GCONF) */
-}
-
 /* arch-tag: c5873ee3-d1f6-44f9-9f3b-b14f70fd0e6a
    (do not change this comment) */
diff --git a/src/xgselect.h b/src/xgselect.h
index 14488d6..3bb5428 100644
--- a/src/xgselect.h
+++ b/src/xgselect.h
@@ -30,8 +30,6 @@ extern int xg_select P_ ((int max_fds,
                           SELECT_TYPE *efds,
                           EMACS_TIME *timeout));
 
-extern void xgselect_initialize P_ ((void));
-
 #endif /* XGSELECT_H */
 
 /* arch-tag: 0c5392a8-3a41-41eb-839c-58e6595926f0
diff --git a/src/xterm.c b/src/xterm.c
index af8af50..83412ae 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10989,8 +10989,6 @@ x_initialize ()
   XSetIOErrorHandler (x_io_error_quitter);
 
   signal (SIGPIPE, x_connection_signal);
-
-  xgselect_initialize ();
 }
 
 
-- 
1.7.8.4


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

       reply	other threads:[~2012-01-28 17:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1327767888.1934.14.camel@localhost.localdomain>
2012-01-28 17:01 ` Maciej Marcin Piechotka [this message]
2012-01-28 18:51   ` bug#10629: Infinite loop in emacs 23 on terminal (-nw option) on xgselect.c:58-59 when compiled with gtk+ or gconf support Glenn Morris
2012-01-28 18:46 ` bug#10631: Update of patch Maciej Marcin Piechotka
2012-01-28 19:04   ` Glenn Morris

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=1327770094.1921.2.camel@localhost.localdomain \
    --to=maciej.piechotka08@imperial.ac.uk \
    --cc=10629@debbugs.gnu.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).