I was recently hacking around X11 selections and I stumbled upon a
repeatable sequence of events that will make vim hang.

[burrows@flx src]$ uname -a
Linux flx 3.18.6-1-ARCH #1 SMP PREEMPT Sat Feb 7 08:44:05 CET 2015 x86_64
GNU/Linux

[burrows@flx src]$ ./vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar  8 2015 03:16:19)
Included patches: 1-622
Compiled by burrows@flx
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
+balloon_eval    +float           +mouse_urxvt     -tag_any_white
+browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
+clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      +toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con_gui  -lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      +X11
+dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     +xim
+emacs_tags      +mouseshape      -sniff           +xsmp_interact
+eval            +mouse_dec       +startuptime     +xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    +xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread
-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1
-I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16
-I/usr/include/pango-1.0 -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -I/usr/include/freetype2
-I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/freetype2
-I/usr/include/libpng16 -I/usr/include/harfbuzz    -g -O2 -U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro
-fstack-protector -rdynamic -Wl,-export-dynamic  -L/usr/local/lib
-Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0
-latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0
-lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype  -lSM -lICE -lXpm -lXt
-lX11 -lXdmcp -lSM -lICE  -lm -lncurses -lelf -lnsl   -lacl -lattr -lgpm
-ldl    -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm
-Xlinker -export-dynamic   -lruby -lpthread -lgmp -ldl -lcrypt -lm
 -L/usr/lib


Follow these steps to hang vim.
0. download + compile this file:
https://github.com/burrows-labs/clipboard/blob/master/src/owner.c
if you download the whole repository you can just do `make`
1.  Then start the owner program and vim.
2. Now do :reg in vim

vim should hang after a few seconds.  Here is a backtrace from hanging vim

Program received signal SIGABRT, Aborted.


0x00007ffff489b4d0 in __poll_nocancel () from /usr/lib/libc.so.6


(gdb) bt


#0  0x00007ffff489b4d0 in __poll_nocancel () from /usr/lib/libc.so.6


#1  0x00007ffff64b2c68 in _XtWaitForSomething () from /usr/lib/libXt.so.6


#2  0x00007ffff64b40a7 in XtAppNextEvent () from /usr/lib/libXt.so.6


#3  0x0000000000521191 in xterm_update () at os_unix.c:7101


#4  0x00000000005248ec in RealWaitForChar (fd=0, msec=msec@entry=-1,
check_for_gpm=check_for_gpm@entry=0x7fffffffe31c) at os_unix.c:5469

#5  0x0000000000524cef in WaitForChar (msec=<optimized out>) at
os_unix.c:5168

#6  0x0000000000524f5b in mch_inchar (buf=buf@entry=0x8751a0
<typebuf_init+32> "", maxlen=maxlen@entry=77, wtime=wtime@entry=-1,
tb_change_cnt=tb_change_cnt@entry=22)
    at os_unix.c:450


#7  0x000000000059e8c8 in ui_inchar (buf=buf@entry=0x8751a0
<typebuf_init+32> "", maxlen=maxlen@entry=77, wtime=wtime@entry=-1,
tb_change_cnt=tb_change_cnt@entry=22)
    at ui.c:199


#8  0x00000000004b972f in inchar (buf=0x8751a0 <typebuf_init+32> "",
maxlen=232, wait_time=-1, tb_change_cnt=22) at getchar.c:3098

#9  0x00000000004bb715 in vgetorpeek (advance=advance@entry=1) at
getchar.c:2873

#10 0x00000000004bbe8e in vgetc () at getchar.c:1638


#11 0x00000000004bc2e9 in safe_vgetc () at getchar.c:1843


#12 0x0000000000453d95 in edit (cmdchar=<optimized out>, startln=<optimized
out>, count=1) at edit.c:763

#13 0x00000000004fb60a in invoke_edit (repl=<optimized out>, cmd=<optimized
out>, startln=<optimized out>, cap=<optimized out>, cap=<optimized out>) at
normal.c:9123
#14 0x00000000005076ce in normal_cmd (oap=oap@entry=0x7fffffffe7a0,
toplevel=toplevel@entry=1) at normal.c:1160

#15 0x00000000005d63dd in main_loop (cmdwin=0, noexmode=0) at main.c:1334


#16 0x000000000043776f in main (argc=0, argv=0x1) at main.c:1034




I think vim is having the same problem discussed here:
https://groups.google.com/forum/#!topic/comp.windows.x.motif/kD56Irjd8Tk

ie, XtAppPending is returning with mask of XtIMTimer then XtAppNextEvent is
polling indefinitely because it's expecting mask XtIMXEvent.  The patch at
the bottom of this email calls XtAppProcessEvent when we don't get
XtIMXEvent, otherwise it does everything the same  way it's currently being
done.

All of the tests seem to still be passing; `vim --servername serv
--remote-send ':reg<CR>'` also seems to work with this patch.
The gui version of vim is unaffected by this issue.


diff -r cd5eff09c1ae src/os_unix.c
--- a/src/os_unix.c Thu Feb 05 20:29:59 2015 +0100
+++ b/src/os_unix.c Sun Mar 08 03:54:44 2015 -0400
@@ -7096,19 +7096,23 @@
 {
     XEvent event;

-    while (XtAppPending(app_context) && !vim_is_input_buf_full())
-    {
- XtAppNextEvent(app_context, &event);
+    for (;;) {
+        const XtInputMask mask = XtAppPending(app_context);
+        if (!(mask && !vim_is_input_buf_full())) break;
+
+        if (XtIMXEvent == (mask | XtIMXEvent)) {
+            XtAppNextEvent(app_context, &event);
 #ifdef FEAT_CLIENTSERVER
- {
-    XPropertyEvent *e = (XPropertyEvent *)&event;
-
-    if (e->type == PropertyNotify && e->window == commWindow
-   && e->atom == commProperty && e->state == PropertyNewValue)
- serverEventProc(xterm_dpy, &event);
- }
-#endif
- XtDispatchEvent(&event);
+            const XPropertyEvent *const e = (XPropertyEvent *)&event;
+
+            if (e->type == PropertyNotify && e->window == commWindow
+                   && e->atom == commProperty && e->state ==
PropertyNewValue)
+                serverEventProc(xterm_dpy, &event);
+#endif
+            XtDispatchEvent(&event);
+        } else {
+            XtAppProcessEvent(app_context, mask);
+        }
     }
 }

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui