Re: [Ctags-devel] Infinite loop in vim.c
Brought to you by:
dhiebert
|
From: Alexey R. <ale...@gm...> - 2014-01-12 21:16:28
|
Hi David.
Today i encountered same issue again. (Infinite loop in ctags). This time
the issue was due to presence of external code in viml. Here is content of
abusing code:
python<<EOF
# We register openers with PandocRegisterExecutor.
# We take its first argument as the name of a vim ex command, the second
# argument as a mapping, and the rest as the description of a command,
# which we'll pass to pandoc_open.
# pandoc_register_executor(...) adds a tuple of those elements to a list of
#executors. This list will be # read from by ftplugin/pandoc.vim and
commands
#and mappings will be created from it.
pandoc_executors = []
def pandoc_register_executor(com_ref):
args = com_ref.split()
name = args[0]
mapping = args[1]
type = args[2]
command = args[3:]
pandoc_executors.append((name, mapping, type, " ".join(command)))
EOF
command! -nargs=? PandocRegisterExecutor exec 'py
pandoc_register_executor("<args>")'
" We register here some default executors. The user can define other custom
" commands in his .vimrc.
"
" Generate html and open in default html viewer
PandocRegisterExecutor PandocHtml <LocalLeader>html html pandoc -t html -Ss
-o %:r.html %%
" Generate pdf w/ citeproc and open in default pdf viewer
PandocRegisterExecutor PandocPdf <LocalLeader>pdf pdf markdown2pdf
PANDOC#P_BIBS -o %:r.pdf %%
" Generate odt w/ citeproc and open in default odt viewer
PandocRegisterExecutor PandocOdt <LocalLeader>odt odt pandoc -t odt
PANDOC#P_BIBS -o %:r.odt %%
This was taken from vim pandoc plugin. Try to do
ctags -f - --format=2 --excmd=pattern --fields=nksSa --extra= --sort=yes
--language-force=vim --vim-kinds=vfacm pandoc.vim
and you'll get infinite loop!
I attached a patch that will fix it: readVimLine() checks whether it is
inside external code context and skips until the endmarker found. There is
a new auxiliary function skipExternalCode() for that. I also reimplemented
function isMap() as far as skipExternalCode() is very similar and i found
that checks like
strncmp ((const char*) line, "nno", (size_t) 3) == 0 ||
strncmp ((const char*) line, "nnor", (size_t) 4) == 0 ||
strncmp ((const char*) line, "nnore", (size_t) 5) == 0 ||
strncmp ((const char*) line, "nnorem", (size_t) 6) == 0 ||
strncmp ((const char*) line, "nnorema", (size_t) 7) == 0 ||
strncmp ((const char*) line, "nnoremap", (size_t) 8) == 0 ||
have little sense because if last condition triggers then all the previous
must also trigger. Additionally the new version checks that the word is a
lexem (i.e. is a complete word). I tested the patch on my large .vimrc and
all worked fine.
Cheers, Alexey.
2012/6/20 Alexey Radkov <ale...@gm...>
> Hi David.
>
> Your change works really well:
>
>
> ./ctags -f - --format=2 --excmd=pattern --fields=nksSa --extra= --sort=yes
> --language-force=vim --vim-kinds=vfacm /home/lyokha/.vim/Align.vba
>
> (no output, no delay)
>
> ./ctags -f - --format=2 --excmd=pattern --fields=nksSa --extra= --sort=yes
> --language-force=vim --vim-kinds=vfacmn /home/lyokha/.vim/Align.vba
> autoload/Align.vim /home/lyokha/.vim/Align.vba
> /^autoload\/Align.vim [[[1$/;" n line:2432
> autoload/AlignMaps.vim /home/lyokha/.vim/Align.vba
> /^autoload\/AlignMaps.vim [[[1$/;" n line:3562
> doc/Align.txt /home/lyokha/.vim/Align.vba /^doc\/Align.txt
> [[[1$/;" n line:836
> plugin/AlignMapsPlugin.vim /home/lyokha/.vim/Align.vba
> /^plugin\/AlignMapsPlugin.vim [[[1$/;" n line:47
> plugin/AlignPlugin.vim /home/lyokha/.vim/Align.vba
> /^plugin\/AlignPlugin.vim [[[1$/;" n line:4
> plugin/cecutil.vim /home/lyokha/.vim/Align.vba
> /^plugin\/cecutil.vim [[[1$/;" n line:298
>
> (listed all files to be installed).
>
> Probably author of tagbar would like to add the new option 'n' by default.
>
> Thank you, Alexey.
>
>
>
> 2012/6/20 David Fishburn <dfi...@gm...>
>
>> Good Morning Alexey.
>>
>> I have checked in a change for this.
>>
>> Now, when .vba files (Vimball Archive) are used, they are parsed
>> differently from .vim files.
>> I also added a new kind:
>> { TRUE, 'n', "filename", "vimball filename" },
>>
>> So the full list is:
>> Vim
>> a autocommand groups
>> c user-defined commands
>> f function definitions
>> m maps
>> v variable definitions
>> n vimball filename
>>
>>
>> If you use the taglist or tagbar plugins, then you will want to add the
>> following to your vimrc, so these new kinds show up automatically.
>>
>> let g:tlist_vim_settings = 'vim;p:Project;a:autocommand
>> groups;c:user-defined commands;f:function definitions;m:maps;v:variable
>> definitions;n:vimball filename'
>>
>> let g:tagbar_type_vim = {
>> \ 'ctagstype' : 'vim',
>> \ 'kinds' : [
>> \ 'p:Project',
>> \ 'a:autocommand groups',
>> \ 'c:user-defined commands',
>> \ 'f:function definitions',
>> \ 'm:maps',
>> \ 'v:variable definitions',
>> \ 'n:vimball filename'
>> \ ]
>> \ }
>>
>>
>> Opening the Align.vba file will now show the following tags:
>> vimball filename
>> autoload/Align.vim
>> autoload/AlignMaps.vim
>> doc/Align.txt
>> plugin/AlignMapsPlugin.vim
>> plugin/AlignPlugin.vim
>> plugin/cecutil.vim
>>
>> Thanks for reporting the problem.
>>
>> If you wouldn't mind verifying the fix and if you have suggested changes,
>> feel free to mention them.
>> I will post this information to the Vim_use list in a couple of days.
>>
>> Dave
>>
>>
>>
>> On 19/06/2012 10:20 AM, Alexey Radkov wrote:
>>
>> Hi David.
>>
>> Here is the link (from official vim scripts page):
>>
>> http://www.vim.org/scripts/download_script.php?src_id=18148
>>
>> Downoad it, then unzip it and do the ctags command on it
>>
>> Cheers, Alexey.
>>
>>
>> 2012/6/19 David Fishburn <dfi...@gm...>
>>
>>> Thanks for the report Alexey.
>>>
>>> Could you send me the Align.vba script and I will try it out.
>>>
>>> Dave
>>>
>>>
>>> On 19/06/2012 5:15 AM, Alexey Radkov wrote:
>>>
>>> Hi.
>>>
>>> Recently i tried to update latest Align.vba in vim and my vim hung. I
>>> found that this was due to the autoopen feature of plugin tagbar during
>>> which following command takes place:
>>>
>>> /usr/local/bin/ctags -f - --format=2 --excmd=pattern --fields=nksSa
>>> --extra= --sort=yes --language-force=vim --vim-kinds=vfacm
>>> /home/lyokha/.vim/Align.vba
>>>
>>> I tried to issue it in command-line and it hung. The backtrace of the
>>> hung command is:
>>>
>>> (gdb) bt
>>> #0 0x00000000004242a5 in parseCommand (line=<optimized out>, line@entry=0xbb6c13
>>> "command (ie. they are left justified, too).") at vim.c:396
>>> #1 0x0000000000424f90 in parseVimLine (line=0xbb6c13 "command (ie. they
>>> are left justified, too).") at vim.c:584
>>> #2 parseVimFile (line=<optimized out>) at vim.c:618
>>> #3 findVimTags () at vim.c:633
>>> #4 0x000000000041aee7 in createTagsForFile (passCount=1, language=40,
>>> fileName=0x7fffbd832f22 "/home/lyokha/.vim/Align.vba") at parse.c:617
>>> #5 createTagsWithFallback (language=40, fileName=0x7fffbd832f22
>>> "/home/lyokha/.vim/Align.vba") at parse.c:639
>>> #6 parseFile (fileName=fileName@entry=0x7fffbd832f22
>>> "/home/lyokha/.vim/Align.vba") at parse.c:666
>>> #7 0x0000000000413f87 in createTagsForEntry (entryName=0x7fffbd832f22
>>> "/home/lyokha/.vim/Align.vba") at main.c:303
>>> #8 0x00000000004024c0 in createTagsForArgs (args=0xb68120) at main.c:348
>>> #9 makeTags (args=0xb68120) at main.c:494
>>> #10 main (argc=<optimized out>, argv=<optimized out>) at main.c:562
>>> (gdb) l
>>> 391 * Strip off any spaces and options which are part of the
>>> command.
>>> 392 * These should preceed the command name.
>>> 393 */
>>> 394 do
>>> 395 {
>>> 396 if (isspace ((int) *cp))
>>> 397 {
>>> 398 ++cp;
>>> 399 }
>>> 400 else if (*cp == '-')
>>> (gdb)
>>> 401 {
>>> 402 /*
>>> 403 * Read until the next space which separates options
>>> or the name
>>> 404 */
>>> 405 while (*cp && !isspace ((int) *cp))
>>> 406 ++cp;
>>> 407 }
>>> 408 } while ( *cp && !isalnum ((int) *cp) );
>>> 409
>>> 410 if ( ! *cp )
>>>
>>> Evidently it tries to parse line
>>>
>>> "command (ie. they are left justified, too)."
>>>
>>> in Align.vba source (the line is not correct vim command of course, but
>>> rather some comment or help), and ctags is unable to go over the do-loop
>>> with check for !isalnum() (*cp is '(' here and the pointer never changes).
>>>
>>> Btw current release version works fine with it, i suppose it changed
>>> after revision r762:
>>>
>>> ------------------------------------------------------------------------
>>> r762 | dfishburn | 2010-07-28 15:38:19 +0400 (Ср., 28 июля 2010) | 9
>>> lines
>>>
>>> VIM Parser updates for bug 3032253.
>>>
>>> Vim parser did not handle an invalid 'command' format and hung".
>>> Now it handles and checks for these formats:
>>> command.
>>> command!.
>>> comma!.
>>> comma! ThisIsValid
>>>
>>>
>>> Cheers, Alexey.
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Live Security Virtual Conference
>>> Exclusive live event will cover all the ways today's security and
>>> threat landscape has changed and how IT managers can respond. Discussions
>>> will include endpoint security, mobile security and the latest in malware
>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>>
>>>
>>>
>>> _______________________________________________
>>> Ctags-devel mailing lis...@li...://lists.sourceforge.net/lists/listinfo/ctags-devel
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Live Security Virtual Conference
>>> Exclusive live event will cover all the ways today's security and
>>> threat landscape has changed and how IT managers can respond. Discussions
>>> will include endpoint security, mobile security and the latest in malware
>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>> _______________________________________________
>>> Ctags-devel mailing list
>>> Cta...@li...
>>> https://lists.sourceforge.net/lists/listinfo/ctags-devel
>>>
>>>
>>
>>
>>
>
|