Mercurial > vim
comparison src/terminal.c @ 25314:7e620652bd13 v8.2.3194
patch 8.2.3194: Vim9: argument types are not checked at compile time
Commit: https://github.com/vim/vim/commit/cd9172077bc8c0aafddf2e5367cc0ae2c00c8ff7
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Wed Jul 21 19:09:09 2021 +0200
patch 8.2.3194: Vim9: argument types are not checked at compile time
Problem: Vim9: argument types are not checked at compile time.
Solution: Add several more type checks, simplify some. (Yegappan
Lakshmanan, closes #8598)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 21 Jul 2021 19:15:04 +0200 |
parents | 4d3c68196d05 |
children | e2be9f3c5907 |
comparison
equal
deleted
inserted
replaced
25313:afe0651cb4aa | 25314:7e620652bd13 |
---|---|
5777 * "term_getline(buf, row)" function | 5777 * "term_getline(buf, row)" function |
5778 */ | 5778 */ |
5779 void | 5779 void |
5780 f_term_getline(typval_T *argvars, typval_T *rettv) | 5780 f_term_getline(typval_T *argvars, typval_T *rettv) |
5781 { | 5781 { |
5782 buf_T *buf = term_get_buf(argvars, "term_getline()"); | 5782 buf_T *buf; |
5783 term_T *term; | 5783 term_T *term; |
5784 int row; | 5784 int row; |
5785 | 5785 |
5786 rettv->v_type = VAR_STRING; | 5786 rettv->v_type = VAR_STRING; |
5787 | |
5788 if (in_vim9script() | |
5789 && (check_for_buffer_arg(argvars, 0) == FAIL | |
5790 || check_for_lnum_arg(argvars, 1) == FAIL)) | |
5791 return; | |
5792 | |
5793 buf = term_get_buf(argvars, "term_getline()"); | |
5787 if (buf == NULL) | 5794 if (buf == NULL) |
5788 return; | 5795 return; |
5789 term = buf->b_term; | 5796 term = buf->b_term; |
5790 row = get_row_number(&argvars[1], term); | 5797 row = get_row_number(&argvars[1], term); |
5791 | 5798 |
5856 * "term_setsize(buf, rows, cols)" function | 5863 * "term_setsize(buf, rows, cols)" function |
5857 */ | 5864 */ |
5858 void | 5865 void |
5859 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | 5866 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
5860 { | 5867 { |
5861 buf_T *buf = term_get_buf(argvars, "term_setsize()"); | 5868 buf_T *buf; |
5862 term_T *term; | 5869 term_T *term; |
5863 varnumber_T rows, cols; | 5870 varnumber_T rows, cols; |
5864 | 5871 |
5872 if (in_vim9script() | |
5873 && (check_for_buffer_arg(argvars, 0) == FAIL | |
5874 || check_for_number_arg(argvars, 1) == FAIL | |
5875 || check_for_number_arg(argvars, 2) == FAIL)) | |
5876 return; | |
5877 | |
5878 buf = term_get_buf(argvars, "term_setsize()"); | |
5865 if (buf == NULL) | 5879 if (buf == NULL) |
5866 { | 5880 { |
5867 emsg(_("E955: Not a terminal buffer")); | 5881 emsg(_("E955: Not a terminal buffer")); |
5868 return; | 5882 return; |
5869 } | 5883 } |
5931 buf_T *buf; | 5945 buf_T *buf; |
5932 char_u *p = NULL; | 5946 char_u *p = NULL; |
5933 int num = 0; | 5947 int num = 0; |
5934 | 5948 |
5935 if (in_vim9script() | 5949 if (in_vim9script() |
5936 && (check_for_string_or_number_arg(argvars, 0) == FAIL | 5950 && (check_for_buffer_arg(argvars, 0) == FAIL |
5937 || check_for_opt_bool_arg(argvars, 1) == FAIL)) | 5951 || check_for_opt_bool_arg(argvars, 1) == FAIL)) |
5938 return; | 5952 return; |
5939 | 5953 |
5940 rettv->v_type = VAR_STRING; | 5954 rettv->v_type = VAR_STRING; |
5941 buf = term_get_buf(argvars, "term_gettty()"); | 5955 buf = term_get_buf(argvars, "term_gettty()"); |
5986 * "term_scrape(buf, row)" function | 6000 * "term_scrape(buf, row)" function |
5987 */ | 6001 */ |
5988 void | 6002 void |
5989 f_term_scrape(typval_T *argvars, typval_T *rettv) | 6003 f_term_scrape(typval_T *argvars, typval_T *rettv) |
5990 { | 6004 { |
5991 buf_T *buf = term_get_buf(argvars, "term_scrape()"); | 6005 buf_T *buf; |
5992 VTermScreen *screen = NULL; | 6006 VTermScreen *screen = NULL; |
5993 VTermPos pos; | 6007 VTermPos pos; |
5994 list_T *l; | 6008 list_T *l; |
5995 term_T *term; | 6009 term_T *term; |
5996 char_u *p; | 6010 char_u *p; |
5997 sb_line_T *line; | 6011 sb_line_T *line; |
5998 | 6012 |
5999 if (rettv_list_alloc(rettv) == FAIL) | 6013 if (rettv_list_alloc(rettv) == FAIL) |
6000 return; | 6014 return; |
6015 | |
6016 if (in_vim9script() | |
6017 && (check_for_buffer_arg(argvars, 0) == FAIL | |
6018 || check_for_lnum_arg(argvars, 1) == FAIL)) | |
6019 return; | |
6020 | |
6021 buf = term_get_buf(argvars, "term_scrape()"); | |
6001 if (buf == NULL) | 6022 if (buf == NULL) |
6002 return; | 6023 return; |
6003 term = buf->b_term; | 6024 term = buf->b_term; |
6004 | 6025 |
6005 l = rettv->vval.v_list; | 6026 l = rettv->vval.v_list; |
6102 buf_T *buf; | 6123 buf_T *buf; |
6103 char_u *msg; | 6124 char_u *msg; |
6104 term_T *term; | 6125 term_T *term; |
6105 | 6126 |
6106 if (in_vim9script() | 6127 if (in_vim9script() |
6107 && (check_for_string_or_number_arg(argvars, 0) == FAIL | 6128 && (check_for_buffer_arg(argvars, 0) == FAIL |
6108 || check_for_string_arg(argvars, 1) == FAIL)) | 6129 || check_for_string_arg(argvars, 1) == FAIL)) |
6109 return; | 6130 return; |
6110 | 6131 |
6111 buf = term_get_buf(argvars, "term_sendkeys()"); | 6132 buf = term_get_buf(argvars, "term_sendkeys()"); |
6112 if (buf == NULL) | 6133 if (buf == NULL) |
6181 { | 6202 { |
6182 buf_T *buf; | 6203 buf_T *buf; |
6183 term_T *term; | 6204 term_T *term; |
6184 | 6205 |
6185 if (in_vim9script() | 6206 if (in_vim9script() |
6186 && (check_for_opt_string_or_number_arg(argvars, 0) == FAIL | 6207 && (check_for_opt_buffer_arg(argvars, 0) == FAIL |
6187 || (argvars[0].v_type != VAR_UNKNOWN | 6208 || (argvars[0].v_type != VAR_UNKNOWN |
6188 && check_for_opt_list_arg(argvars, 1) == FAIL))) | 6209 && check_for_opt_list_arg(argvars, 1) == FAIL))) |
6189 return; | 6210 return; |
6190 | 6211 |
6191 buf = term_get_buf(argvars, "term_setansicolors()"); | 6212 buf = term_get_buf(argvars, "term_setansicolors()"); |
6215 buf_T *buf; | 6236 buf_T *buf; |
6216 term_T *term; | 6237 term_T *term; |
6217 char_u *api; | 6238 char_u *api; |
6218 | 6239 |
6219 if (in_vim9script() | 6240 if (in_vim9script() |
6220 && (check_for_string_or_number_arg(argvars, 0) == FAIL | 6241 && (check_for_buffer_arg(argvars, 0) == FAIL |
6221 || check_for_string_arg(argvars, 1) == FAIL)) | 6242 || check_for_string_arg(argvars, 1) == FAIL)) |
6222 return; | 6243 return; |
6223 | 6244 |
6224 buf = term_get_buf(argvars, "term_setapi()"); | 6245 buf = term_get_buf(argvars, "term_setapi()"); |
6225 if (buf == NULL) | 6246 if (buf == NULL) |
6243 buf_T *buf; | 6264 buf_T *buf; |
6244 term_T *term; | 6265 term_T *term; |
6245 char_u *cmd; | 6266 char_u *cmd; |
6246 | 6267 |
6247 if (in_vim9script() | 6268 if (in_vim9script() |
6248 && (check_for_string_or_number_arg(argvars, 0) == FAIL | 6269 && (check_for_buffer_arg(argvars, 0) == FAIL |
6249 || check_for_string_arg(argvars, 1) == FAIL)) | 6270 || check_for_string_arg(argvars, 1) == FAIL)) |
6250 return; | 6271 return; |
6251 | 6272 |
6252 buf = term_get_buf(argvars, "term_setrestore()"); | 6273 buf = term_get_buf(argvars, "term_setrestore()"); |
6253 if (buf == NULL) | 6274 if (buf == NULL) |
6271 buf_T *buf; | 6292 buf_T *buf; |
6272 term_T *term; | 6293 term_T *term; |
6273 char_u *how; | 6294 char_u *how; |
6274 | 6295 |
6275 if (in_vim9script() | 6296 if (in_vim9script() |
6276 && (check_for_string_or_number_arg(argvars, 0) == FAIL | 6297 && (check_for_buffer_arg(argvars, 0) == FAIL |
6277 || check_for_string_arg(argvars, 1) == FAIL)) | 6298 || check_for_string_arg(argvars, 1) == FAIL)) |
6278 return; | 6299 return; |
6279 | 6300 |
6280 buf = term_get_buf(argvars, "term_setkill()"); | 6301 buf = term_get_buf(argvars, "term_setkill()"); |
6281 if (buf == NULL) | 6302 if (buf == NULL) |
6295 void | 6316 void |
6296 f_term_start(typval_T *argvars, typval_T *rettv) | 6317 f_term_start(typval_T *argvars, typval_T *rettv) |
6297 { | 6318 { |
6298 jobopt_T opt; | 6319 jobopt_T opt; |
6299 buf_T *buf; | 6320 buf_T *buf; |
6321 | |
6322 if (in_vim9script() | |
6323 && (check_for_string_or_list_arg(argvars, 0) == FAIL | |
6324 || check_for_opt_dict_arg(argvars, 1) == FAIL)) | |
6325 return; | |
6300 | 6326 |
6301 init_job_options(&opt); | 6327 init_job_options(&opt); |
6302 if (argvars[1].v_type != VAR_UNKNOWN | 6328 if (argvars[1].v_type != VAR_UNKNOWN |
6303 && get_job_options(&argvars[1], &opt, | 6329 && get_job_options(&argvars[1], &opt, |
6304 JO_TIMEOUT_ALL + JO_STOPONEXIT | 6330 JO_TIMEOUT_ALL + JO_STOPONEXIT |
6324 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | 6350 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) |
6325 { | 6351 { |
6326 buf_T *buf; | 6352 buf_T *buf; |
6327 | 6353 |
6328 if (in_vim9script() | 6354 if (in_vim9script() |
6329 && (check_for_string_or_number_arg(argvars, 0) == FAIL | 6355 && (check_for_buffer_arg(argvars, 0) == FAIL |
6330 || check_for_opt_number_arg(argvars, 1) == FAIL)) | 6356 || check_for_opt_number_arg(argvars, 1) == FAIL)) |
6331 return; | 6357 return; |
6332 | 6358 |
6333 buf = term_get_buf(argvars, "term_wait()"); | 6359 buf = term_get_buf(argvars, "term_wait()"); |
6334 if (buf == NULL) | 6360 if (buf == NULL) |