summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-12-22 18:59:06 +0100
committerBram Moolenaar <Bram@vim.org>2018-12-22 18:59:06 +0100
commit9123c0b31a283f460ed2b6af95080120cf528118 (patch)
tree275e918901c144e4bfcea65dc761f86f7da27d35
parent4814ccbdf0e99e2d33e1ac926c59f677f5c2afe2 (diff)
patch 8.1.0627: Python cannot handle function name of script-local functionv8.1.0627
Problem: Python cannot handle function name of script-local function. Solution: Use <SNR> instead of the special byte code. (Ozaki Kiichi, closes #3681)
-rw-r--r--src/if_py_both.h30
-rw-r--r--src/testdir/test_python2.vim27
-rw-r--r--src/testdir/test_python3.vim27
-rw-r--r--src/version.c2
4 files changed, 81 insertions, 5 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h
index cdd7460191..1a4ef462ef 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -2922,8 +2922,7 @@ FunctionNew(PyTypeObject *subtype, char_u *name, int argc, typval_T *argv,
{
FunctionObject *self;
- self = (FunctionObject *) subtype->tp_alloc(subtype, 0);
-
+ self = (FunctionObject *)subtype->tp_alloc(subtype, 0);
if (self == NULL)
return NULL;
@@ -2938,15 +2937,36 @@ FunctionNew(PyTypeObject *subtype, char_u *name, int argc, typval_T *argv,
self->name = vim_strsave(name);
}
else
- if ((self->name = get_expanded_name(name,
- vim_strchr(name, AUTOLOAD_CHAR) == NULL))
- == NULL)
+ {
+ char_u *p;
+
+ if ((p = get_expanded_name(name,
+ vim_strchr(name, AUTOLOAD_CHAR) == NULL)) == NULL)
{
PyErr_FORMAT(PyExc_ValueError,
N_("function %s does not exist"), name);
return NULL;
}
+ if (p[0] == K_SPECIAL && p[1] == KS_EXTRA && p[2] == (int)KE_SNR)
+ {
+ char_u *np;
+ size_t len = STRLEN(p) + 1;
+
+ if ((np = alloc(len + 2)) == NULL)
+ {
+ vim_free(p);
+ return NULL;
+ }
+ mch_memmove(np, "<SNR>", 5);
+ mch_memmove(np + 5, p + 3, len - 3);
+ vim_free(p);
+ self->name = np;
+ }
+ else
+ self->name = p;
+ }
+
func_ref(self->name);
self->argc = argc;
self->argv = argv;
diff --git a/src/testdir/test_python2.vim b/src/testdir/test_python2.vim
index c438ba0415..d79400de71 100644
--- a/src/testdir/test_python2.vim
+++ b/src/testdir/test_python2.vim
@@ -36,3 +36,30 @@ func Test_set_cursor()
normal j
call assert_equal([2, 6], [line('.'), col('.')])
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/testdir/test_python3.vim b/src/testdir/test_python3.vim
index 69ad802131..344034af00 100644
--- a/src/testdir/test_python3.vim
+++ b/src/testdir/test_python3.vim
@@ -36,3 +36,30 @@ func Test_set_cursor()
normal j
call assert_equal([2, 6], [line('.'), col('.')])
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
diff --git a/src/version.c b/src/version.c
index 4d39dde9d3..101d7864d1 100644
--- a/src/version.c
+++ b/src/version.c
@@ -800,6 +800,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 627,
+/**/
626,
/**/
625,