Skip to content

Commit 16eb4f8

Browse files
committed
patch 7.4.1319
Problem: Tests fail on MS-Windows and on Unix with GUI. Solution: Fix unregistering.
1 parent 7b3ca76 commit 16eb4f8

File tree

6 files changed

+81
-73
lines changed

6 files changed

+81
-73
lines changed

src/channel.c

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ channel_gui_register_one(channel_T *channel, int which)
339339
* is input on the editor connection socket. */
340340
if (channel->ch_pfd[which].ch_inputHandler == 0)
341341
channel->ch_pfd[which].ch_inputHandler = gdk_input_add(
342-
(gint)channel->ch_pfd[which].ch_fd, (GdkInputCondition)
343-
((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
342+
(gint)channel->ch_pfd[which].ch_fd,
343+
(GdkInputCondition)
344+
((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
344345
messageFromNetbeans,
345346
(gpointer)(long)channel->ch_id);
346347
# else
@@ -362,12 +363,12 @@ channel_gui_register(channel_T *channel)
362363
if (!CH_HAS_GUI)
363364
return;
364365

365-
if (channel->ch_pfd[CHAN_SOCK].ch_fd >= 0)
366+
if (channel->CH_SOCK >= 0)
366367
channel_gui_register_one(channel, CHAN_SOCK);
367368
# ifdef CHANNEL_PIPES
368-
if (channel->ch_pfd[CHAN_OUT].ch_fd >= 0)
369+
if (channel->CH_OUT >= 0)
369370
channel_gui_register_one(channel, CHAN_OUT);
370-
if (channel->ch_pfd[CHAN_ERR].ch_fd >= 0)
371+
if (channel->CH_ERR >= 0)
371372
channel_gui_register_one(channel, CHAN_ERR);
372373
# endif
373374
}
@@ -386,44 +387,40 @@ channel_gui_register_all(void)
386387
}
387388

388389
static void
389-
channel_gui_unregister_one(channel_T *channel, int which)
390+
channel_gui_unregister(channel_T *channel)
390391
{
391-
# ifdef FEAT_GUI_X11
392-
if (channel->ch_pfd[which].ch_inputHandler != (XtInputId)NULL)
392+
int which;
393+
394+
#ifdef CHANNEL_PIPES
395+
for (which = CHAN_SOCK; which < CHAN_IN; ++which)
396+
#else
397+
which = CHAN_SOCK;
398+
#endif
393399
{
394-
XtRemoveInput(channel->ch_pfd[which].ch_inputHandler);
395-
channel->ch_pfd[which].ch_inputHandler = (XtInputId)NULL;
396-
}
400+
# ifdef FEAT_GUI_X11
401+
if (channel->ch_pfd[which].ch_inputHandler != (XtInputId)NULL)
402+
{
403+
XtRemoveInput(channel->ch_pfd[which].ch_inputHandler);
404+
channel->ch_pfd[which].ch_inputHandler = (XtInputId)NULL;
405+
}
397406
# else
398407
# ifdef FEAT_GUI_GTK
399-
if (channel->ch_pfd[which].ch_inputHandler != 0)
400-
{
401-
gdk_input_remove(channel->ch_pfd[which].ch_inputHandler);
402-
channel->ch_pfd[which].ch_inputHandler = 0;
403-
}
408+
if (channel->ch_pfd[which].ch_inputHandler != 0)
409+
{
410+
gdk_input_remove(channel->ch_pfd[which].ch_inputHandler);
411+
channel->ch_pfd[which].ch_inputHandler = 0;
412+
}
404413
# else
405414
# ifdef FEAT_GUI_W32
406-
if (channel->ch_pfd[which].ch_inputHandler == 0)
407-
{
408-
WSAAsyncSelect(channel->ch_pfd[which].ch_fd, s_hwnd, 0, 0);
409-
channel->ch_pfd[which].ch_inputHandler = -1;
410-
}
415+
if (channel->ch_pfd[which].ch_inputHandler == 0)
416+
{
417+
WSAAsyncSelect(channel->ch_pfd[which].ch_fd, s_hwnd, 0, 0);
418+
channel->ch_pfd[which].ch_inputHandler = -1;
419+
}
411420
# endif
412421
# endif
413422
# endif
414-
}
415-
416-
static void
417-
channel_gui_unregister(channel_T *channel)
418-
{
419-
if (channel->ch_pfd[CHAN_SOCK].ch_fd >= 0)
420-
channel_gui_unregister_one(channel, CHAN_SOCK);
421-
# ifdef CHANNEL_PIPES
422-
if (channel->ch_pfd[CHAN_OUT].ch_fd >= 0)
423-
channel_gui_unregister_one(channel, CHAN_OUT);
424-
if (channel->ch_pfd[CHAN_ERR].ch_fd >= 0)
425-
channel_gui_unregister_one(channel, CHAN_ERR);
426-
# endif
423+
}
427424
}
428425

429426
#endif
@@ -1192,16 +1189,14 @@ channel_close(channel_T *channel)
11921189
{
11931190
ch_log(channel, "Closing channel");
11941191

1192+
#ifdef FEAT_GUI
1193+
channel_gui_unregister(channel);
1194+
#endif
1195+
11951196
if (channel->CH_SOCK >= 0)
11961197
{
11971198
sock_close(channel->CH_SOCK);
11981199
channel->CH_SOCK = -1;
1199-
channel->ch_close_cb = NULL;
1200-
#ifdef FEAT_GUI
1201-
channel_gui_unregister(channel);
1202-
#endif
1203-
vim_free(channel->ch_callback);
1204-
channel->ch_callback = NULL;
12051200
}
12061201
#if defined(CHANNEL_PIPES)
12071202
if (channel->CH_IN >= 0)
@@ -1220,6 +1215,10 @@ channel_close(channel_T *channel)
12201215
channel->CH_ERR = -1;
12211216
}
12221217
#endif
1218+
1219+
channel->ch_close_cb = NULL;
1220+
vim_free(channel->ch_callback);
1221+
channel->ch_callback = NULL;
12231222
channel_clear(channel);
12241223
}
12251224

@@ -1383,7 +1382,7 @@ channel_get_id(void)
13831382

13841383
/*
13851384
* Get the file descriptor to read from, either the socket or stdout.
1386-
* TODO: never gets stderr.
1385+
* TODO: should have a way to read stderr.
13871386
*/
13881387
static int
13891388
get_read_fd(channel_T *channel)
@@ -1400,7 +1399,8 @@ get_read_fd(channel_T *channel)
14001399

14011400
/*
14021401
* Read from channel "channel" for as long as there is something to read.
1403-
* "which" is CHAN_SOCK, CHAN_OUT or CHAN_ERR. When -1 guess.
1402+
* "which" is CHAN_SOCK, CHAN_OUT or CHAN_ERR. When -1 use CHAN_SOCK or
1403+
* CHAN_OUT, the one that is open.
14041404
* The data is put in the read queue.
14051405
*/
14061406
void
@@ -1475,19 +1475,12 @@ channel_read(channel_T *channel, int which, char *func)
14751475
ch_errors(channel, "%s(): Cannot read\n", func);
14761476
channel_save(channel, (char_u *)DETACH_MSG, (int)STRLEN(DETACH_MSG));
14771477

1478-
if (use_socket)
1479-
{
1480-
channel_close(channel);
1481-
if (channel->ch_close_cb != NULL)
1482-
(*channel->ch_close_cb)();
1483-
}
1484-
#if defined(CHANNEL_PIPES)
1485-
else
1486-
{
1487-
close(fd);
1488-
channel->CH_OUT = -1;
1489-
}
1490-
#endif
1478+
/* TODO: When reading from stdout is not possible, should we try to
1479+
* keep stdin and stderr open? Probably not, assume the other side
1480+
* has died. */
1481+
channel_close(channel);
1482+
if (channel->ch_close_cb != NULL)
1483+
(*channel->ch_close_cb)();
14911484

14921485
if (len < 0)
14931486
{
@@ -1587,6 +1580,7 @@ channel_fd2channel(sock_T fd, int *whichp)
15871580
if (fd >= 0)
15881581
for (channel = first_channel; channel != NULL;
15891582
channel = channel->ch_next)
1583+
{
15901584
# ifdef CHANNEL_PIPES
15911585
for (i = CHAN_SOCK; i < CHAN_IN; ++i)
15921586
# else
@@ -1595,8 +1589,9 @@ channel_fd2channel(sock_T fd, int *whichp)
15951589
if (channel->ch_pfd[i].ch_fd == fd)
15961590
{
15971591
*whichp = i;
1598-
return channel
1592+
return channel;
15991593
}
1594+
}
16001595
return NULL;
16011596
}
16021597
# endif
@@ -1638,7 +1633,7 @@ channel_send(channel_T *channel, char_u *buf, char *fun)
16381633
{
16391634
ch_log_lead("SEND ", channel);
16401635
fprintf(log_fd, "'");
1641-
ignored = fwrite(buf, len, 1, log_fd);
1636+
ignored = (int)fwrite(buf, len, 1, log_fd);
16421637
fprintf(log_fd, "'\n");
16431638
fflush(log_fd);
16441639
}
@@ -1677,11 +1672,13 @@ channel_poll_setup(int nfd_in, void *fds_in)
16771672
int which;
16781673

16791674
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
1675+
{
16801676
# ifdef CHANNEL_PIPES
16811677
for (which = CHAN_SOCK; which < CHAN_IN; ++which)
16821678
# else
16831679
which = CHAN_SOCK;
16841680
# endif
1681+
{
16851682
if (channel->ch_pfd[which].ch_fd >= 0)
16861683
{
16871684
channel->ch_pfd[which].ch_poll_idx = nfd;
@@ -1691,6 +1688,8 @@ channel_poll_setup(int nfd_in, void *fds_in)
16911688
}
16921689
else
16931690
channel->ch_pfd[which].ch_poll_idx = -1;
1691+
}
1692+
}
16941693

16951694
return nfd;
16961695
}
@@ -1707,8 +1706,9 @@ channel_poll_check(int ret_in, void *fds_in)
17071706
int which;
17081707

17091708
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
1709+
{
17101710
# ifdef CHANNEL_PIPES
1711-
for (which = CHAN_SOCK; which < CHAN_IN; ++which)
1711+
for (which = CHAN_SOCK; which < CH_IN; ++which)
17121712
# else
17131713
which = CHAN_SOCK;
17141714
# endif
@@ -1721,6 +1721,7 @@ channel_poll_check(int ret_in, void *fds_in)
17211721
--ret;
17221722
}
17231723
}
1724+
}
17241725

17251726
return ret;
17261727
}
@@ -1739,6 +1740,7 @@ channel_select_setup(int maxfd_in, void *rfds_in)
17391740
int which;
17401741

17411742
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
1743+
{
17421744
# ifdef CHANNEL_PIPES
17431745
for (which = CHAN_SOCK; which < CHAN_IN; ++which)
17441746
# else
@@ -1754,6 +1756,7 @@ channel_select_setup(int maxfd_in, void *rfds_in)
17541756
maxfd = fd;
17551757
}
17561758
}
1759+
}
17571760

17581761
return maxfd;
17591762
}
@@ -1770,6 +1773,7 @@ channel_select_check(int ret_in, void *rfds_in)
17701773
int which;
17711774

17721775
for (channel = first_channel; channel != NULL; channel = channel->ch_next)
1776+
{
17731777
# ifdef CHANNEL_PIPES
17741778
for (which = CHAN_SOCK; which < CHAN_IN; ++which)
17751779
# else
@@ -1784,6 +1788,7 @@ channel_select_check(int ret_in, void *rfds_in)
17841788
--ret;
17851789
}
17861790
}
1791+
}
17871792

17881793
return ret;
17891794
}

src/os_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5043,7 +5043,7 @@ mch_start_job(char **argv, job_T *job)
50435043
int fd_in[2]; /* for stdin */
50445044
int fd_out[2]; /* for stdout */
50455045
int fd_err[2]; /* for stderr */
5046-
channel_T *channel;
5046+
channel_T *channel = NULL;
50475047

50485048
/* default is to fail */
50495049
job->jv_status = JOB_FAILED;

src/os_win32.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5039,13 +5039,13 @@ mch_start_job(char *cmd, job_T *job)
50395039
STARTUPINFO si;
50405040
PROCESS_INFORMATION pi;
50415041
HANDLE jo;
5042-
#ifdef FEAT_CHANNEL
5043-
channel_T *channel;
5042+
# ifdef FEAT_CHANNEL
5043+
channel_T *channel;
50445044

50455045
channel = add_channel();
50465046
if (channel == NULL)
50475047
return;
5048-
#endif
5048+
# endif
50495049

50505050
jo = CreateJobObject(NULL, NULL);
50515051
if (jo == NULL)
@@ -5085,24 +5085,24 @@ mch_start_job(char *cmd, job_T *job)
50855085
job->jv_job_object = jo;
50865086
job->jv_status = JOB_STARTED;
50875087

5088-
#ifdef FEAT_CHANNEL
5089-
# if 0
5088+
# ifdef FEAT_CHANNEL
5089+
# if 0
50905090
/* TODO: connect stdin/stdout/stderr */
50915091
job->jv_channel = channel;
50925092
channel_set_pipes(channel, fd_in[1], fd_out[0], fd_err[0]);
50935093
channel_set_job(channel, job);
50945094

5095-
# ifdef FEAT_GUI
5095+
# ifdef FEAT_GUI
50965096
channel_gui_register(channel);
5097+
# endif
50975098
# endif
50985099
# endif
5099-
#endif
51005100
return;
51015101

51025102
failed:
5103-
#ifdef FEAT_CHANNEL
5103+
# ifdef FEAT_CHANNEL
51045104
channel_free(channel);
5105-
#endif
5105+
# endif
51065106
}
51075107

51085108
char *

src/proto/channel.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ char_u *channel_peek(channel_T *channel);
2222
void channel_clear(channel_T *channel);
2323
void channel_free_all(void);
2424
int channel_get_id(void);
25-
void channel_read(channel_T *channel, int what, char *func);
25+
void channel_read(channel_T *channel, int which, char *func);
2626
char_u *channel_read_block(channel_T *channel);
2727
int channel_read_json_block(channel_T *channel, int id, typval_T **rettv);
28-
channel_T *channel_fd2channel(sock_T fd, int *what);
28+
channel_T *channel_fd2channel(sock_T fd, int *whichp);
2929
int channel_send(channel_T *channel, char_u *buf, char *fun);
3030
int channel_poll_setup(int nfd_in, void *fds_in);
3131
int channel_poll_check(int ret_in, void *fds_in);

src/structs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,8 @@ typedef enum
13011301
MODE_JS
13021302
} ch_mode_T;
13031303

1304-
/* Ordering matters: IN is last, only SOCK/OUT/ERR are polled */
1305-
1304+
/* Ordering matters, it is used in for loops: IN is last, only SOCK/OUT/ERR
1305+
* are polled. */
13061306
#define CHAN_SOCK 0
13071307
#define CH_SOCK ch_pfd[CHAN_SOCK].ch_fd
13081308

@@ -1342,7 +1342,7 @@ struct channel_S {
13421342

13431343
int ch_id; /* ID of the channel */
13441344

1345-
chan_fd_T ch_pfd[4]; /* info for socket, in, out and err */
1345+
chan_fd_T ch_pfd[4]; /* info for socket, out, err and in */
13461346

13471347
readq_T ch_head; /* dummy node, header for circular queue */
13481348

@@ -1351,6 +1351,7 @@ struct channel_S {
13511351
* the other side has exited, only mention the
13521352
* first error until the connection works
13531353
* again. */
1354+
13541355
void (*ch_close_cb)(void); /* callback for when channel is closed */
13551356

13561357
int ch_block_id; /* ID that channel_read_json_block() is

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+
1319,
750752
/**/
751753
1318,
752754
/**/

0 commit comments

Comments
 (0)