summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0627
blob: c3b1524df83be4158bf4ec84aefaa04081c10e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0627
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.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)
Files:	    src/if_py_both.h, src/testdir/test_python2.vim,
            src/testdir/test_python3.vim


*** ../vim-8.1.0626/src/if_py_both.h	2018-08-07 19:45:22.619218432 +0200
--- src/if_py_both.h	2018-12-22 18:54:43.284392984 +0100
***************
*** 2922,2929 ****
  {
      FunctionObject	*self;
  
!     self = (FunctionObject *) subtype->tp_alloc(subtype, 0);
! 
      if (self == NULL)
  	return NULL;
  
--- 2922,2928 ----
  {
      FunctionObject	*self;
  
!     self = (FunctionObject *)subtype->tp_alloc(subtype, 0);
      if (self == NULL)
  	return NULL;
  
***************
*** 2938,2952 ****
  	self->name = vim_strsave(name);
      }
      else
! 	if ((self->name = get_expanded_name(name,
! 				    vim_strchr(name, AUTOLOAD_CHAR) == NULL))
! 		== NULL)
  	{
  	    PyErr_FORMAT(PyExc_ValueError,
  		    N_("function %s does not exist"), name);
  	    return NULL;
  	}
  
      func_ref(self->name);
      self->argc = argc;
      self->argv = argv;
--- 2937,2972 ----
  	self->name = vim_strsave(name);
      }
      else
!     {
! 	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;
*** ../vim-8.1.0626/src/testdir/test_python2.vim	2018-07-25 22:02:32.235966277 +0200
--- src/testdir/test_python2.vim	2018-12-22 18:54:43.284392984 +0100
***************
*** 36,38 ****
--- 36,65 ----
    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
*** ../vim-8.1.0626/src/testdir/test_python3.vim	2018-07-25 22:02:32.235966277 +0200
--- src/testdir/test_python3.vim	2018-12-22 18:54:43.284392984 +0100
***************
*** 36,38 ****
--- 36,65 ----
    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
*** ../vim-8.1.0626/src/version.c	2018-12-22 18:44:49.104612525 +0100
--- src/version.c	2018-12-22 18:58:31.154751073 +0100
***************
*** 801,802 ****
--- 801,804 ----
  {   /* Add new patch number below this line */
+ /**/
+     627,
  /**/

-- 
Portable Computer:  A device invented to force businessmen
to work at home, on vacation, and on business trips.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///