diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval/typval.c | 4 | ||||
-rw-r--r-- | src/nvim/strings.c | 14 | ||||
-rw-r--r-- | src/nvim/testdir/test_python2.vim | 27 | ||||
-rw-r--r-- | src/nvim/testdir/test_python3.vim | 27 |
4 files changed, 67 insertions, 5 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 6a93b20345..912aecafec 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2850,7 +2850,7 @@ const char *tv_get_string_buf_chk(const typval_T *const tv, char *const buf) /// Get the string value of a "stringish" VimL object. /// /// @warning For number and special values it uses a single, static buffer. It -/// may be used only once, next call to get_tv_string may reuse it. Use +/// may be used only once, next call to tv_get_string may reuse it. Use /// tv_get_string_buf() if you need to use tv_get_string() output after /// calling it again. /// @@ -2869,7 +2869,7 @@ const char *tv_get_string_chk(const typval_T *const tv) /// Get the string value of a "stringish" VimL object. /// /// @warning For number and special values it uses a single, static buffer. It -/// may be used only once, next call to get_tv_string may reuse it. Use +/// may be used only once, next call to tv_get_string may reuse it. Use /// tv_get_string_buf() if you need to use tv_get_string() output after /// calling it again. /// diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 87593f577b..4921824316 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -999,7 +999,10 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap, } else if (fmt_spec == 'd') { // signed switch (length_modifier) { - case '\0': + case '\0': { + arg = (int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int)); + break; + } case 'h': { // char and short arguments are passed as int16_t arg = (int16_t)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int)); @@ -1031,11 +1034,16 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap, } else { // unsigned switch (length_modifier) { - case '\0': + case '\0': { + uarg = (unsigned int)(tvs + ? tv_nr(tvs, &arg_idx) + : va_arg(ap, unsigned int)); + break; + } case 'h': { uarg = (uint16_t)(tvs ? tv_nr(tvs, &arg_idx) - : va_arg(ap, unsigned)); + : va_arg(ap, unsigned int)); break; } case 'l': { diff --git a/src/nvim/testdir/test_python2.vim b/src/nvim/testdir/test_python2.vim index 63c38cd5d1..5ba9fd68cf 100644 --- a/src/nvim/testdir/test_python2.vim +++ b/src/nvim/testdir/test_python2.vim @@ -25,3 +25,30 @@ func Test_pydo() bwipe! endif endfunc + +func Test_vim_function() + " Check creating vim.Function object + py import vim + + func s:foo() + return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$') + endfunc + let name = '<SNR>' . s:foo() + + try + py f = vim.bindeval('function("s:foo")') + call assert_equal(name, pyeval('f.name')) + catch + call assert_false(v:exception) + endtry + + try + py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()')) + call assert_equal(name, pyeval('f.name')) + catch + call assert_false(v:exception) + endtry + + py del f + delfunc s:foo +endfunc diff --git a/src/nvim/testdir/test_python3.vim b/src/nvim/testdir/test_python3.vim index f5b2c89853..2e3fc93674 100644 --- a/src/nvim/testdir/test_python3.vim +++ b/src/nvim/testdir/test_python3.vim @@ -25,3 +25,30 @@ func Test_py3do() bwipe! endif endfunc + +func Test_vim_function() + " Check creating vim.Function object + py3 import vim + + func s:foo() + return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$') + endfunc + let name = '<SNR>' . s:foo() + + try + py3 f = vim.bindeval('function("s:foo")') + call assert_equal(name, py3eval('f.name')) + catch + call assert_false(v:exception) + endtry + + try + py3 f = vim.Function(b'\x80\xfdR' + vim.eval('s:foo()').encode()) + call assert_equal(name, py3eval('f.name')) + catch + call assert_false(v:exception) + endtry + + py3 del f + delfunc s:foo +endfunc |