1
0
forked from aniani/vim

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)
This commit is contained in:
Bram Moolenaar
2021-06-05 20:51:38 +02:00
parent c6d71532dd
commit 1328bde9d4
9 changed files with 76 additions and 34 deletions

View File

@@ -1927,4 +1927,34 @@ f_job_stop(typval_T *argvars, typval_T *rettv)
rettv->vval.v_number = job_stop(job, argvars, NULL);
}
/*
* Get a string with information about the job in "varp" in "buf".
* "buf" must be at least NUMBUFLEN long.
*/
char_u *
job_to_string_buf(typval_T *varp, char_u *buf)
{
job_T *job = varp->vval.v_job;
char *status;
if (job == NULL)
return (char_u *)"no process";
status = job->jv_status == JOB_FAILED ? "fail"
: job->jv_status >= JOB_ENDED ? "dead"
: "run";
# ifdef UNIX
vim_snprintf((char *)buf, NUMBUFLEN,
"process %ld %s", (long)job->jv_pid, status);
# elif defined(MSWIN)
vim_snprintf((char *)buf, NUMBUFLEN,
"process %ld %s",
(long)job->jv_proc_info.dwProcessId,
status);
# else
// fall-back
vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status);
# endif
return buf;
}
#endif // FEAT_JOB_CHANNEL