Skip to content

Commit 1e00286

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 70d6f82 + dc0ccae commit 1e00286

File tree

10 files changed

+371
-312
lines changed

10 files changed

+371
-312
lines changed

src/channel.c

Lines changed: 114 additions & 108 deletions
Large diffs are not rendered by default.

src/eval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5622,15 +5622,15 @@ set_ref_in_item(
56225622
else if (tv->v_type == VAR_CHANNEL)
56235623
{
56245624
channel_T *ch =tv->vval.v_channel;
5625-
int part;
5625+
ch_part_T part;
56265626
typval_T dtv;
56275627
jsonq_T *jq;
56285628
cbq_T *cq;
56295629

56305630
if (ch != NULL && ch->ch_copyID != copyID)
56315631
{
56325632
ch->ch_copyID = copyID;
5633-
for (part = PART_SOCK; part <= PART_IN; ++part)
5633+
for (part = PART_SOCK; part < PART_COUNT; ++part)
56345634
{
56355635
for (jq = ch->ch_part[part].ch_json_head.jq_next; jq != NULL;
56365636
jq = jq->jq_next)

src/proto/channel.pro

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ channel_T *channel_open_func(typval_T *argvars);
1414
void channel_set_pipes(channel_T *channel, sock_T in, sock_T out, sock_T err);
1515
void channel_set_job(channel_T *channel, job_T *job, jobopt_T *options);
1616
void channel_set_options(channel_T *channel, jobopt_T *opt);
17-
void channel_set_req_callback(channel_T *channel, int part, char_u *callback, partial_T *partial, int id);
17+
void channel_set_req_callback(channel_T *channel, ch_part_T part, char_u *callback, partial_T *partial, int id);
1818
void channel_buffer_free(buf_T *buf);
1919
void channel_write_any_lines(void);
2020
void channel_write_new_lines(buf_T *buf);
21-
readq_T *channel_peek(channel_T *channel, int part);
21+
readq_T *channel_peek(channel_T *channel, ch_part_T part);
2222
char_u *channel_first_nl(readq_T *node);
23-
char_u *channel_get(channel_T *channel, int part);
24-
void channel_consume(channel_T *channel, int part, int len);
25-
int channel_collapse(channel_T *channel, int part, int want_nl);
23+
char_u *channel_get(channel_T *channel, ch_part_T part);
24+
void channel_consume(channel_T *channel, ch_part_T part, int len);
25+
int channel_collapse(channel_T *channel, ch_part_T part, int want_nl);
2626
int channel_can_write_to(channel_T *channel);
2727
int channel_is_open(channel_T *channel);
2828
char *channel_status(channel_T *channel, int req_part);
@@ -31,13 +31,12 @@ void channel_close(channel_T *channel, int invoke_close_cb);
3131
void channel_close_in(channel_T *channel);
3232
void channel_clear(channel_T *channel);
3333
void channel_free_all(void);
34-
char_u *channel_read_block(channel_T *channel, int part, int timeout);
35-
int channel_read_json_block(channel_T *channel, int part, int timeout_arg, int id, typval_T **rettv);
34+
char_u *channel_read_block(channel_T *channel, ch_part_T part, int timeout);
35+
int channel_read_json_block(channel_T *channel, ch_part_T part, int timeout_arg, int id, typval_T **rettv);
3636
void common_channel_read(typval_T *argvars, typval_T *rettv, int raw);
37-
channel_T *channel_fd2channel(sock_T fd, int *partp);
37+
channel_T *channel_fd2channel(sock_T fd, ch_part_T *partp);
3838
void channel_handle_events(void);
39-
int channel_send(channel_T *channel, int part, char_u *buf, int len, char *fun);
40-
channel_T *send_common(typval_T *argvars, char_u *text, int id, int eval, jobopt_T *opt, char *fun, int *part_read);
39+
int channel_send(channel_T *channel, ch_part_T part, char_u *buf, int len, char *fun);
4140
void ch_expr_common(typval_T *argvars, typval_T *rettv, int eval);
4241
void ch_raw_common(typval_T *argvars, typval_T *rettv, int eval);
4342
int channel_poll_setup(int nfd_in, void *fds_in);
@@ -46,14 +45,14 @@ int channel_select_setup(int maxfd_in, void *rfds_in, void *wfds_in);
4645
int channel_select_check(int ret_in, void *rfds_in, void *wfds_in);
4746
int channel_parse_messages(void);
4847
int set_ref_in_channel(int copyID);
49-
int channel_part_send(channel_T *channel);
50-
int channel_part_read(channel_T *channel);
51-
ch_mode_T channel_get_mode(channel_T *channel, int part);
52-
int channel_get_timeout(channel_T *channel, int part);
48+
ch_part_T channel_part_send(channel_T *channel);
49+
ch_part_T channel_part_read(channel_T *channel);
50+
ch_mode_T channel_get_mode(channel_T *channel, ch_part_T part);
51+
int channel_get_timeout(channel_T *channel, ch_part_T part);
5352
void clear_job_options(jobopt_T *opt);
5453
void free_job_options(jobopt_T *opt);
5554
int get_job_options(typval_T *tv, jobopt_T *opt, int supported);
56-
channel_T *get_channel_arg(typval_T *tv, int check_open, int reading, int part);
55+
channel_T *get_channel_arg(typval_T *tv, int check_open, int reading, ch_part_T part);
5756
void job_free_all(void);
5857
int set_ref_in_job(int copyID);
5958
void job_unref(job_T *job);

src/quickfix.c

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,39 +1010,42 @@ qf_parse_line(
10101010
}
10111011
else if (vim_strchr((char_u *)"CZ", idx) != NULL)
10121012
{ /* continuation of multi-line msg */
1013-
qfline_T *qfprev = qi->qf_lists[qi->qf_curlist].qf_last;
1014-
1015-
if (qfprev == NULL)
1016-
return QF_FAIL;
1017-
if (*fields->errmsg && !qi->qf_multiignore)
1013+
if (!qi->qf_multiignore)
10181014
{
1019-
len = (int)STRLEN(qfprev->qf_text);
1020-
if ((ptr = alloc((unsigned)(len + STRLEN(fields->errmsg) + 2)))
1021-
== NULL)
1015+
qfline_T *qfprev = qi->qf_lists[qi->qf_curlist].qf_last;
1016+
1017+
if (qfprev == NULL)
10221018
return QF_FAIL;
1023-
STRCPY(ptr, qfprev->qf_text);
1024-
vim_free(qfprev->qf_text);
1025-
qfprev->qf_text = ptr;
1026-
*(ptr += len) = '\n';
1027-
STRCPY(++ptr, fields->errmsg);
1019+
if (*fields->errmsg && !qi->qf_multiignore)
1020+
{
1021+
len = (int)STRLEN(qfprev->qf_text);
1022+
if ((ptr = alloc((unsigned)(len + STRLEN(fields->errmsg) + 2)))
1023+
== NULL)
1024+
return QF_FAIL;
1025+
STRCPY(ptr, qfprev->qf_text);
1026+
vim_free(qfprev->qf_text);
1027+
qfprev->qf_text = ptr;
1028+
*(ptr += len) = '\n';
1029+
STRCPY(++ptr, fields->errmsg);
1030+
}
1031+
if (qfprev->qf_nr == -1)
1032+
qfprev->qf_nr = fields->enr;
1033+
if (vim_isprintc(fields->type) && !qfprev->qf_type)
1034+
/* only printable chars allowed */
1035+
qfprev->qf_type = fields->type;
1036+
1037+
if (!qfprev->qf_lnum)
1038+
qfprev->qf_lnum = fields->lnum;
1039+
if (!qfprev->qf_col)
1040+
qfprev->qf_col = fields->col;
1041+
qfprev->qf_viscol = fields->use_viscol;
1042+
if (!qfprev->qf_fnum)
1043+
qfprev->qf_fnum = qf_get_fnum(qi, qi->qf_directory,
1044+
*fields->namebuf || qi->qf_directory != NULL
1045+
? fields->namebuf
1046+
: qi->qf_currfile != NULL && fields->valid
1047+
? qi->qf_currfile : 0);
10281048
}
1029-
if (qfprev->qf_nr == -1)
1030-
qfprev->qf_nr = fields->enr;
1031-
if (vim_isprintc(fields->type) && !qfprev->qf_type)
1032-
/* only printable chars allowed */
1033-
qfprev->qf_type = fields->type;
1034-
1035-
if (!qfprev->qf_lnum)
1036-
qfprev->qf_lnum = fields->lnum;
1037-
if (!qfprev->qf_col)
1038-
qfprev->qf_col = fields->col;
1039-
qfprev->qf_viscol = fields->use_viscol;
1040-
if (!qfprev->qf_fnum)
1041-
qfprev->qf_fnum = qf_get_fnum(qi, qi->qf_directory,
1042-
*fields->namebuf || qi->qf_directory != NULL
1043-
? fields->namebuf
1044-
: qi->qf_currfile != NULL && fields->valid
1045-
? qi->qf_currfile : 0);
10461049
if (idx == 'Z')
10471050
qi->qf_multiline = qi->qf_multiignore = FALSE;
10481051
line_breakcheck();

src/structs.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,19 +1499,21 @@ typedef enum {
14991499

15001500
/* Ordering matters, it is used in for loops: IN is last, only SOCK/OUT/ERR
15011501
* are polled. */
1502-
#define PART_SOCK 0
1502+
typedef enum {
1503+
PART_SOCK = 0,
15031504
#define CH_SOCK_FD ch_part[PART_SOCK].ch_fd
1504-
15051505
#ifdef FEAT_JOB_CHANNEL
1506-
# define INVALID_FD (-1)
1507-
1508-
# define PART_OUT 1
1509-
# define PART_ERR 2
1510-
# define PART_IN 3
1506+
PART_OUT,
15111507
# define CH_OUT_FD ch_part[PART_OUT].ch_fd
1508+
PART_ERR,
15121509
# define CH_ERR_FD ch_part[PART_ERR].ch_fd
1510+
PART_IN,
15131511
# define CH_IN_FD ch_part[PART_IN].ch_fd
15141512
#endif
1513+
PART_COUNT
1514+
} ch_part_T;
1515+
1516+
#define INVALID_FD (-1)
15151517

15161518
/* The per-fd info for a channel. */
15171519
typedef struct {
@@ -1569,14 +1571,14 @@ struct channel_S {
15691571
int ch_id; /* ID of the channel */
15701572
int ch_last_msg_id; /* ID of the last message */
15711573

1572-
chanpart_T ch_part[4]; /* info for socket, out, err and in */
1574+
chanpart_T ch_part[PART_COUNT]; /* info for socket, out, err and in */
15731575

15741576
char *ch_hostname; /* only for socket, allocated */
15751577
int ch_port; /* only for socket */
15761578

1577-
int ch_to_be_closed; /* When TRUE reading or writing failed and
1578-
* the channel must be closed when it's safe
1579-
* to invoke callbacks. */
1579+
int ch_to_be_closed; /* bitset of readable fds to be closed.
1580+
* When all readable fds have been closed,
1581+
* set to (1 << PART_COUNT). */
15801582
int ch_to_be_freed; /* When TRUE channel must be freed when it's
15811583
* safe to invoke callbacks. */
15821584
int ch_error; /* When TRUE an error was reported. Avoids

src/testdir/test_channel.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,23 @@ func Test_read_nonl_line()
15051505
call assert_equal(3, g:linecount)
15061506
endfunc
15071507

1508+
func Test_read_from_terminated_job()
1509+
if !has('job')
1510+
return
1511+
endif
1512+
1513+
let g:linecount = 0
1514+
if has('win32')
1515+
" workaround: 'shellescape' does improper escaping double quotes
1516+
let arg = 'import os,sys;os.close(1);sys.stderr.write(\"test\n\")'
1517+
else
1518+
let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
1519+
endif
1520+
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
1521+
call WaitFor('1 <= g:linecount')
1522+
call assert_equal(1, g:linecount)
1523+
endfunc
1524+
15081525
function Ch_test_close_lambda(port)
15091526
let handle = ch_open('localhost:' . a:port, s:chopt)
15101527
if ch_status(handle) == "fail"

0 commit comments

Comments
 (0)