Skip to content

Commit ec68a99

Browse files
committed
patch 8.0.0022
Problem: If a channel in NL mode is missing the NL at the end the remaining characters are dropped. Solution: When the channel is closed use the remaining text. (Ozaki Kiichi)
1 parent 84dbd49 commit ec68a99

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/channel.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,8 +2355,9 @@ may_invoke_callback(channel_T *channel, int part)
23552355
typval_T *listtv = NULL;
23562356
typval_T argv[CH_JSON_MAX_ARGS];
23572357
int seq_nr = -1;
2358-
ch_mode_T ch_mode = channel->ch_part[part].ch_mode;
2359-
cbq_T *cbhead = &channel->ch_part[part].ch_cb_head;
2358+
chanpart_T *ch_part = &channel->ch_part[part];
2359+
ch_mode_T ch_mode = ch_part->ch_mode;
2360+
cbq_T *cbhead = &ch_part->ch_cb_head;
23602361
cbq_T *cbitem;
23612362
char_u *callback = NULL;
23622363
partial_T *partial = NULL;
@@ -2376,22 +2377,22 @@ may_invoke_callback(channel_T *channel, int part)
23762377
callback = cbitem->cq_callback;
23772378
partial = cbitem->cq_partial;
23782379
}
2379-
else if (channel->ch_part[part].ch_callback != NULL)
2380+
else if (ch_part->ch_callback != NULL)
23802381
{
2381-
callback = channel->ch_part[part].ch_callback;
2382-
partial = channel->ch_part[part].ch_partial;
2382+
callback = ch_part->ch_callback;
2383+
partial = ch_part->ch_partial;
23832384
}
23842385
else
23852386
{
23862387
callback = channel->ch_callback;
23872388
partial = channel->ch_partial;
23882389
}
23892390

2390-
buffer = channel->ch_part[part].ch_bufref.br_buf;
2391-
if (buffer != NULL && !bufref_valid(&channel->ch_part[part].ch_bufref))
2391+
buffer = ch_part->ch_bufref.br_buf;
2392+
if (buffer != NULL && !bufref_valid(&ch_part->ch_bufref))
23922393
{
23932394
/* buffer was wiped out */
2394-
channel->ch_part[part].ch_bufref.br_buf = NULL;
2395+
ch_part->ch_bufref.br_buf = NULL;
23952396
buffer = NULL;
23962397
}
23972398

@@ -2452,7 +2453,7 @@ may_invoke_callback(channel_T *channel, int part)
24522453

24532454
if (ch_mode == MODE_NL)
24542455
{
2455-
char_u *nl;
2456+
char_u *nl = NULL;
24562457
char_u *buf;
24572458
readq_T *node;
24582459

@@ -2465,10 +2466,25 @@ may_invoke_callback(channel_T *channel, int part)
24652466
if (nl != NULL)
24662467
break;
24672468
if (channel_collapse(channel, part, TRUE) == FAIL)
2469+
{
2470+
if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0)
2471+
break;
24682472
return FALSE; /* incomplete message */
2473+
}
24692474
}
24702475
buf = node->rq_buffer;
24712476

2477+
if (nl == NULL)
2478+
{
2479+
/* Flush remaining message that is missing a NL. */
2480+
buf = vim_realloc(buf, node->rq_buflen + 1);
2481+
if (buf == NULL)
2482+
return FALSE;
2483+
node->rq_buffer = buf;
2484+
nl = buf + node->rq_buflen++;
2485+
*nl = NUL;
2486+
}
2487+
24722488
/* Convert NUL to NL, the internal representation. */
24732489
for (p = buf; p < nl && p < buf + node->rq_buflen; ++p)
24742490
if (*p == NUL)

src/testdir/test_channel.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,27 @@ func Test_raw_passes_nul()
14841484
bwipe!
14851485
endfunc
14861486

1487+
func MyLineCountCb(ch, msg)
1488+
let g:linecount += 1
1489+
endfunc
1490+
1491+
func Test_read_nonl_line()
1492+
if !has('job')
1493+
return
1494+
endif
1495+
1496+
let g:linecount = 0
1497+
if has('win32')
1498+
" workaround: 'shellescape' does improper escaping double quotes
1499+
let arg = 'import sys;sys.stdout.write(\"1\n2\n3\")'
1500+
else
1501+
let arg = 'import sys;sys.stdout.write("1\n2\n3")'
1502+
endif
1503+
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
1504+
call WaitFor('3 <= g:linecount')
1505+
call assert_equal(3, g:linecount)
1506+
endfunc
1507+
14871508
function Ch_test_close_lambda(port)
14881509
let handle = ch_open('localhost:' . a:port, s:chopt)
14891510
if ch_status(handle) == "fail"

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
22,
767769
/**/
768770
21,
769771
/**/

0 commit comments

Comments
 (0)