Skip to content

Commit b6a4fee

Browse files
committed
patch 7.4.1303
Problem: A Funcref is not accepted as a callback. Solution: Make a Funcref work. (Damien)
1 parent 6119e61 commit b6a4fee

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

src/eval.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9871,12 +9871,13 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98719871

98729872
if (argvars[1].v_type == VAR_DICT)
98739873
{
9874-
/* parse argdict */
9875-
dict_T *dict = argvars[1].vval.v_dict;
9874+
dict_T *dict = argvars[1].vval.v_dict;
9875+
dictitem_T *item;
98769876

9877-
if (dict_find(dict, (char_u *)"mode", -1) != NULL)
9877+
/* parse argdict */
9878+
if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL)
98789879
{
9879-
mode = get_dict_string(dict, (char_u *)"mode", FALSE);
9880+
mode = get_tv_string(&item->di_tv);
98809881
if (STRCMP(mode, "raw") == 0)
98819882
ch_mode = MODE_RAW;
98829883
else if (STRCMP(mode, "js") == 0)
@@ -9889,12 +9890,12 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98899890
return;
98909891
}
98919892
}
9892-
if (dict_find(dict, (char_u *)"waittime", -1) != NULL)
9893-
waittime = get_dict_number(dict, (char_u *)"waittime");
9894-
if (dict_find(dict, (char_u *)"timeout", -1) != NULL)
9895-
timeout = get_dict_number(dict, (char_u *)"timeout");
9896-
if (dict_find(dict, (char_u *)"callback", -1) != NULL)
9897-
callback = get_dict_string(dict, (char_u *)"callback", FALSE);
9893+
if ((item = dict_find(dict, (char_u *)"waittime", -1)) != NULL)
9894+
waittime = get_tv_number(&item->di_tv);
9895+
if ((item = dict_find(dict, (char_u *)"timeout", -1)) != NULL)
9896+
timeout = get_tv_number(&item->di_tv);
9897+
if ((item = dict_find(dict, (char_u *)"callback", -1)) != NULL)
9898+
callback = get_callback(&item->di_tv);
98989899
}
98999900
if (waittime < 0 || timeout < 0)
99009901
{

src/testdir/test_channel.vim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ func s:communicate(port)
118118
call assert_equal(handle, s:responseHandle)
119119
call assert_equal('got it', s:responseMsg)
120120

121+
let s:responseHandle = -1
122+
let s:responseMsg = ''
123+
call ch_sendexpr(handle, 'hello!', function('s:RequestHandler'))
124+
sleep 10m
125+
call assert_equal(handle, s:responseHandle)
126+
call assert_equal('got it', s:responseMsg)
127+
121128
" Send an eval request that works.
122129
call assert_equal('ok', ch_sendexpr(handle, 'eval-works'))
123130
sleep 10m
@@ -206,13 +213,12 @@ endfunc
206213

207214
let s:reply = ""
208215
func s:Handler(chan, msg)
216+
unlet s:reply
209217
let s:reply = a:msg
210218
endfunc
211219

212220
func s:channel_handler(port)
213-
let chopt = copy(s:chopt)
214-
let chopt['callback'] = 's:Handler'
215-
let handle = ch_open('localhost:' . a:port, chopt)
221+
let handle = ch_open('localhost:' . a:port, s:chopt)
216222
if handle < 0
217223
call assert_false(1, "Can't open channel")
218224
return
@@ -230,7 +236,11 @@ func s:channel_handler(port)
230236
endfunc
231237

232238
func Test_channel_handler()
239+
let s:chopt.callback = 's:Handler'
240+
call s:run_server('s:channel_handler')
241+
let s:chopt.callback = function('s:Handler')
233242
call s:run_server('s:channel_handler')
243+
unlet s:chopt.callback
234244
endfunc
235245

236246
" Test that trying to connect to a non-existing port fails quickly.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ static char *(features[]) =
747747

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1303,
750752
/**/
751753
1302,
752754
/**/

0 commit comments

Comments
 (0)