To: vim_dev@googlegroups.com Subject: Patch 8.0.0022 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ 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) Files: src/channel.c, src/testdir/test_channel.vim *** ../vim-8.0.0021/src/channel.c 2016-09-29 15:18:51.351768068 +0200 --- src/channel.c 2016-10-03 21:35:54.516547182 +0200 *************** *** 2355,2362 **** typval_T *listtv = NULL; typval_T argv[CH_JSON_MAX_ARGS]; int seq_nr = -1; ! ch_mode_T ch_mode = channel->ch_part[part].ch_mode; ! cbq_T *cbhead = &channel->ch_part[part].ch_cb_head; cbq_T *cbitem; char_u *callback = NULL; partial_T *partial = NULL; --- 2355,2363 ---- typval_T *listtv = NULL; typval_T argv[CH_JSON_MAX_ARGS]; int seq_nr = -1; ! chanpart_T *ch_part = &channel->ch_part[part]; ! ch_mode_T ch_mode = ch_part->ch_mode; ! cbq_T *cbhead = &ch_part->ch_cb_head; cbq_T *cbitem; char_u *callback = NULL; partial_T *partial = NULL; *************** *** 2376,2385 **** callback = cbitem->cq_callback; partial = cbitem->cq_partial; } ! else if (channel->ch_part[part].ch_callback != NULL) { ! callback = channel->ch_part[part].ch_callback; ! partial = channel->ch_part[part].ch_partial; } else { --- 2377,2386 ---- callback = cbitem->cq_callback; partial = cbitem->cq_partial; } ! else if (ch_part->ch_callback != NULL) { ! callback = ch_part->ch_callback; ! partial = ch_part->ch_partial; } else { *************** *** 2387,2397 **** partial = channel->ch_partial; } ! buffer = channel->ch_part[part].ch_bufref.br_buf; ! if (buffer != NULL && !bufref_valid(&channel->ch_part[part].ch_bufref)) { /* buffer was wiped out */ ! channel->ch_part[part].ch_bufref.br_buf = NULL; buffer = NULL; } --- 2388,2398 ---- partial = channel->ch_partial; } ! buffer = ch_part->ch_bufref.br_buf; ! if (buffer != NULL && !bufref_valid(&ch_part->ch_bufref)) { /* buffer was wiped out */ ! ch_part->ch_bufref.br_buf = NULL; buffer = NULL; } *************** *** 2452,2458 **** if (ch_mode == MODE_NL) { ! char_u *nl; char_u *buf; readq_T *node; --- 2453,2459 ---- if (ch_mode == MODE_NL) { ! char_u *nl = NULL; char_u *buf; readq_T *node; *************** *** 2465,2474 **** --- 2466,2490 ---- if (nl != NULL) break; if (channel_collapse(channel, part, TRUE) == FAIL) + { + if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0) + break; return FALSE; /* incomplete message */ + } } buf = node->rq_buffer; + if (nl == NULL) + { + /* Flush remaining message that is missing a NL. */ + buf = vim_realloc(buf, node->rq_buflen + 1); + if (buf == NULL) + return FALSE; + node->rq_buffer = buf; + nl = buf + node->rq_buflen++; + *nl = NUL; + } + /* Convert NUL to NL, the internal representation. */ for (p = buf; p < nl && p < buf + node->rq_buflen; ++p) if (*p == NUL) *** ../vim-8.0.0021/src/testdir/test_channel.vim 2016-09-26 22:36:50.615386371 +0200 --- src/testdir/test_channel.vim 2016-10-03 21:31:14.246500828 +0200 *************** *** 1484,1489 **** --- 1484,1510 ---- bwipe! endfunc + func MyLineCountCb(ch, msg) + let g:linecount += 1 + endfunc + + func Test_read_nonl_line() + if !has('job') + return + endif + + let g:linecount = 0 + if has('win32') + " workaround: 'shellescape' does improper escaping double quotes + let arg = 'import sys;sys.stdout.write(\"1\n2\n3\")' + else + let arg = 'import sys;sys.stdout.write("1\n2\n3")' + endif + call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) + call WaitFor('3 <= g:linecount') + call assert_equal(3, g:linecount) + endfunc + function Ch_test_close_lambda(port) let handle = ch_open('localhost:' . a:port, s:chopt) if ch_status(handle) == "fail" *** ../vim-8.0.0021/src/version.c 2016-10-02 23:09:27.643153731 +0200 --- src/version.c 2016-10-03 21:33:11.837681063 +0200 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 22, /**/ -- "It's so simple to be wise. Just think of something stupid to say and then don't say it." -- Sam Levenson /// 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 ///