From 1328bde9d406aa1292e92673fa8a026889424e79 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 5 Jun 2021 20:51:38 +0200 Subject: patch 8.2.2944: Vim9: no error when using job or channel as a string Problem: Vim9: no error when using job or channel as a string. Solution: Be more strict about conversion to string. (closes #8312) --- src/channel.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/channel.c') diff --git a/src/channel.c b/src/channel.c index fa329bdba3..2a93e2578c 100644 --- a/src/channel.c +++ b/src/channel.c @@ -5015,4 +5015,22 @@ f_ch_status(typval_T *argvars, typval_T *rettv) rettv->vval.v_string = vim_strsave((char_u *)channel_status(channel, part)); } +/* + * Get a string with information about the channel in "varp" in "buf". + * "buf" must be at least NUMBUFLEN long. + */ + char_u * +channel_to_string_buf(typval_T *varp, char_u *buf) +{ + channel_T *channel = varp->vval.v_channel; + char *status = channel_status(channel, -1); + + if (channel == NULL) + vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status); + else + vim_snprintf((char *)buf, NUMBUFLEN, + "channel %d %s", channel->ch_id, status); + return buf; +} + #endif // FEAT_JOB_CHANNEL -- cgit v1.2.3