Skip to content

Commit

Permalink
- Fixed SEGV when buffer name is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Sep 23, 2011
1 parent 6c7f355 commit e3a1a3b
Showing 1 changed file with 54 additions and 50 deletions.
104 changes: 54 additions & 50 deletions autoload/neocomplcache/sources/clang_complete.vim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


" Variables initialize. " Variables initialize.
if !exists('g:neocomplcache_clang_use_library') if !exists('g:neocomplcache_clang_use_library')
let g:neocomplcache_clang_use_library = 0 let g:neocomplcache_clang_use_library = 0
endif endif
if !exists('g:neocomplcache_clang_macros') if !exists('g:neocomplcache_clang_macros')
let g:neocomplcache_clang_macros = 0 let g:neocomplcache_clang_macros = 0
Expand All @@ -39,30 +39,30 @@ if !exists('g:neocomplcache_clang_debug')
endif endif


let s:source = { let s:source = {
\ 'name': 'clang_complete', \ 'name': 'clang_complete',
\ 'kind': 'ftplugin', \ 'kind': 'ftplugin',
\ 'filetypes': { 'c': 1, 'cpp': 1, 'objc': 1, 'objcpp': 1 }, \ 'filetypes': { 'c': 1, 'cpp': 1, 'objc': 1, 'objcpp': 1 },
\ } \ }


" Store plugin path, as this is available only when sourcing the file, " Store plugin path, as this is available only when sourcing the file,
" not during a function call. " not during a function call.
let s:plugin_path = escape(expand('<sfile>:p:h'), '\') let s:plugin_path = escape(expand('<sfile>:p:h'), '\')


function! s:init_ClangCompletePython() function! s:init_ClangCompletePython()
python import sys python import sys


if exists('g:neocomplcache_clang_library_path') if exists('g:neocomplcache_clang_library_path')
" Load the library from the given library path. " Load the library from the given library path.
execute 'python sys.argv = ["' . escape(g:neocomplcache_clang_library_path, '\') . '"]' execute 'python sys.argv = ["' . escape(g:neocomplcache_clang_library_path, '\') . '"]'
else else
" By setting argv[0] to '' force the python bindings to load the library " By setting argv[0] to '' force the python bindings to load the library
" from the normal system search path. " from the normal system search path.
python sys.argv[0] = '' python sys.argv[0] = ''
endif endif


execute 'python sys.path = ["' . s:plugin_path . '/clang_complete"] + sys.path' execute 'python sys.path = ["' . s:plugin_path . '/clang_complete"] + sys.path'
execute 'pyfile ' . s:plugin_path . '/clang_complete/libclang.py' execute 'pyfile ' . s:plugin_path . '/clang_complete/libclang.py'
python initClangComplete(vim.eval('g:neocomplcache_clang_lib_flags')) python initClangComplete(vim.eval('g:neocomplcache_clang_lib_flags'))
endfunction endfunction


function! s:init_ClangComplete() function! s:init_ClangComplete()
Expand Down Expand Up @@ -97,15 +97,15 @@ function! s:init_ClangComplete()


" Load the python bindings of libclang. " Load the python bindings of libclang.
if g:neocomplcache_clang_use_library if g:neocomplcache_clang_use_library
if has('python') if has('python')
call s:init_ClangCompletePython() call s:init_ClangCompletePython()
else else
echoe 'clang_complete: No python support available.' echoe 'clang_complete: No python support available.'
echoe 'Cannot use clang library, using executable' echoe 'Cannot use clang library, using executable'
echoe 'Compile vim with python support to use libclang' echoe 'Compile vim with python support to use libclang'
let g:neocomplcache_clang_use_library = 0 let g:neocomplcache_clang_use_library = 0
return return
endif endif
endif endif
endfunction endfunction


Expand Down Expand Up @@ -257,6 +257,10 @@ function! s:source.get_keyword_pos(cur_text)
endfunction endfunction


function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)
if bufname('%') == ''
return []
endif

if g:neocomplcache_clang_use_library if g:neocomplcache_clang_use_library
python vim.command('let clang_output = ' + str(getCurrentCompletions(vim.eval('a:cur_keyword_str'), int(vim.eval('a:cur_keyword_pos+1'))))) python vim.command('let clang_output = ' + str(getCurrentCompletions(vim.eval('a:cur_keyword_str'), int(vim.eval('a:cur_keyword_pos+1')))))
" echomsg string(clang_output) " echomsg string(clang_output)
Expand Down Expand Up @@ -349,34 +353,34 @@ function! s:complete_from_clang_binary(cur_keyword_pos, cur_keyword_str)
endfunction endfunction


function! s:GetKind(proto) function! s:GetKind(proto)
if a:proto == '' if a:proto == ''
return 't' return 't'
endif endif
let ret = match(a:proto, '^\[#') let ret = match(a:proto, '^\[#')
let params = match(a:proto, '(') let params = match(a:proto, '(')
if ret == -1 && params == -1 if ret == -1 && params == -1
return 't' return 't'
endif endif
if ret != -1 && params == -1 if ret != -1 && params == -1
return 'v' return 'v'
endif endif
if params != -1 if params != -1
return 'f' return 'f'
endif endif
return 'm' return 'm'
endfunction endfunction


function! s:DemangleProto(prototype) function! s:DemangleProto(prototype)
let proto = substitute(a:prototype, '[#', '', 'g') let proto = substitute(a:prototype, '[#', '', 'g')
let proto = substitute(proto, '#]', ' ', 'g') let proto = substitute(proto, '#]', ' ', 'g')
let proto = substitute(proto, '#>', '', 'g') let proto = substitute(proto, '#>', '', 'g')
let proto = substitute(proto, '<#', '', 'g') let proto = substitute(proto, '<#', '', 'g')
let proto = substitute(proto, '{#.*#}', '', 'g') let proto = substitute(proto, '{#.*#}', '', 'g')
return proto return proto
endfunction endfunction


function! neocomplcache#sources#clang_complete#define() function! neocomplcache#sources#clang_complete#define()
return s:source return s:source
endfunction endfunction


" vim: expandtab:ts=4:sts=4:sw=4 " vim: expandtab:ts=2:sts=2:sw=2

0 comments on commit e3a1a3b

Please sign in to comment.