Skip to content

Commit 46c8543

Browse files
committed
patch 7.4.1422
Problem: Error when reading fails uses wrong errno. Keeping channel open after job stops results in test failing. Solution: Move the error up. Add ch_job_killed.
1 parent c8dcbb1 commit 46c8543

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/channel.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,14 @@ add_channel(void)
307307
}
308308

309309
/*
310-
* Return TRUE if "channel" has a callback.
310+
* Return TRUE if "channel" has a callback and the associated job wasn't
311+
* killed.
311312
*/
312313
static int
313-
channel_has_callback(channel_T *channel)
314+
channel_still_useful(channel_T *channel)
314315
{
316+
if (channel->ch_job_killed && channel->ch_job == NULL)
317+
return FALSE;
315318
return channel->ch_callback != NULL
316319
#ifdef CHANNEL_PIPES
317320
|| channel->ch_part[PART_OUT].ch_callback != NULL
@@ -322,12 +325,13 @@ channel_has_callback(channel_T *channel)
322325

323326
/*
324327
* Close a channel and free all its resources if there is no further action
325-
* possible, there is no callback to be invoked.
328+
* possible, there is no callback to be invoked or the associated job was
329+
* killed.
326330
*/
327331
void
328332
channel_may_free(channel_T *channel)
329333
{
330-
if (!channel_has_callback(channel))
334+
if (!channel_still_useful(channel))
331335
channel_free(channel);
332336
}
333337

@@ -1774,6 +1778,12 @@ channel_read(channel_T *channel, int part, char *func)
17741778
* -> channel_read()
17751779
*/
17761780
ch_errors(channel, "%s(): Cannot read", func);
1781+
if (len < 0)
1782+
{
1783+
ch_error(channel, "channel_read(): cannot read from channel");
1784+
PERROR(_("E896: read from channel"));
1785+
}
1786+
17771787
msg = channel->ch_part[part].ch_mode == MODE_RAW
17781788
|| channel->ch_part[part].ch_mode == MODE_NL
17791789
? DETACH_MSG_RAW : DETACH_MSG_JSON;
@@ -1785,12 +1795,6 @@ channel_read(channel_T *channel, int part, char *func)
17851795
channel_close(channel, TRUE);
17861796
if (channel->ch_nb_close_cb != NULL)
17871797
(*channel->ch_nb_close_cb)();
1788-
1789-
if (len < 0)
1790-
{
1791-
ch_error(channel, "channel_read(): cannot read from channel");
1792-
PERROR(_("E896: read from channel"));
1793-
}
17941798
}
17951799

17961800
#if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK)
@@ -2174,7 +2178,7 @@ channel_parse_messages(void)
21742178

21752179
while (channel != NULL)
21762180
{
2177-
if (channel->ch_refcount == 0 && !channel_has_callback(channel))
2181+
if (channel->ch_refcount == 0 && !channel_still_useful(channel))
21782182
{
21792183
/* channel is no longer useful, free it */
21802184
channel_free(channel);

src/eval.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7770,8 +7770,11 @@ job_free(job_T *job)
77707770
# ifdef FEAT_CHANNEL
77717771
if (job->jv_channel != NULL)
77727772
{
7773-
/* The channel doesn't count as a references for the job, we need to
7774-
* NULL the reference when the job is freed. */
7773+
/* The link from the channel to the job doesn't count as a reference,
7774+
* thus don't decrement the refcount of the job. The reference from
7775+
* the job to the channel does count the refrence, decrement it and
7776+
* NULL the reference. We don't set ch_job_killed, unreferencing the
7777+
* job doesn't mean it stops running. */
77757778
job->jv_channel->ch_job = NULL;
77767779
channel_unref(job->jv_channel);
77777780
}
@@ -15161,7 +15164,14 @@ f_job_stop(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
1516115164
if (mch_stop_job(job, arg) == FAIL)
1516215165
rettv->vval.v_number = 0;
1516315166
else
15167+
{
1516415168
rettv->vval.v_number = 1;
15169+
/* Assume that "hup" does not kill the job. */
15170+
if (job->jv_channel != NULL && STRCMP(arg, "hup") != 0)
15171+
job->jv_channel->ch_job_killed = TRUE;
15172+
}
15173+
/* We don't try freeing the job, obviously the caller still has a
15174+
* reference to it. */
1516515175
}
1516615176
}
1516715177
#endif

src/structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,8 @@ struct channel_S {
13731373
job_T *ch_job; /* Job that uses this channel; this does not
13741374
* count as a reference to avoid a circular
13751375
* reference. */
1376+
int ch_job_killed; /* TRUE when there was a job and it was killed
1377+
* or we know it died. */
13761378

13771379
int ch_refcount; /* reference count */
13781380
};

src/version.c

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

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1422,
751753
/**/
752754
1421,
753755
/**/

0 commit comments

Comments
 (0)