comparison src/vim9compile.c @ 21473:8bcd1ee2630b v8.2.1287

patch 8.2.1287: Vim9: crash when using an imported function Commit: https://github.com/vim/vim/commit/40f4f7a48cae491f83bd3cdbf7e9b5a23ed870ef Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 23 22:41:43 2020 +0200 patch 8.2.1287: Vim9: crash when using an imported function Problem: Vim9: crash when using an imported function. Solution: Add the function type to the imported entry. (closes https://github.com/vim/vim/issues/6522)
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 Jul 2020 22:45:04 +0200
parents 4d156aead799
children afc8cc1a291f
comparison
equal deleted inserted replaced
21472:d17bb9011c44 21473:8bcd1ee2630b
712 if ((isn = generate_instr(cctx, isn_type)) == NULL) 712 if ((isn = generate_instr(cctx, isn_type)) == NULL)
713 return NULL; 713 return NULL;
714 714
715 if (ga_grow(stack, 1) == FAIL) 715 if (ga_grow(stack, 1) == FAIL)
716 return NULL; 716 return NULL;
717 ((type_T **)stack->ga_data)[stack->ga_len] = type; 717 ((type_T **)stack->ga_data)[stack->ga_len] = type == NULL ? &t_any : type;
718 ++stack->ga_len; 718 ++stack->ga_len;
719 719
720 return isn; 720 return isn;
721 } 721 }
722 722
1176 isn_T *isn; 1176 isn_T *isn;
1177 1177
1178 RETURN_OK_IF_SKIP(cctx); 1178 RETURN_OK_IF_SKIP(cctx);
1179 if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL) 1179 if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
1180 return FAIL; 1180 return FAIL;
1181 isn->isn_arg.string = name; 1181 isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name);
1182 1182
1183 return OK; 1183 return OK;
1184 } 1184 }
1185 1185
1186 /* 1186 /*
2805 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, 2805 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
2806 import->imp_sid, 2806 import->imp_sid,
2807 idx, 2807 idx,
2808 type); 2808 type);
2809 } 2809 }
2810 else if (import->imp_funcname != NULL)
2811 generate_PUSHFUNC(cctx, import->imp_funcname, import->imp_type);
2810 else 2812 else
2811 {
2812 // TODO: check this is a variable, not a function?
2813 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, 2813 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
2814 import->imp_sid, 2814 import->imp_sid,
2815 import->imp_var_vals_idx, 2815 import->imp_var_vals_idx,
2816 import->imp_type); 2816 import->imp_type);
2817 }
2818 return OK; 2817 return OK;
2819 } 2818 }
2820 2819
2821 if (error) 2820 if (error)
2822 semsg(_("E1050: Item not found: %s"), name); 2821 semsg(_("E1050: Item not found: %s"), name);
2833 2832
2834 // Need to compile any default values to get the argument types. 2833 // Need to compile any default values to get the argument types.
2835 if (ufunc->uf_def_status == UF_TO_BE_COMPILED) 2834 if (ufunc->uf_def_status == UF_TO_BE_COMPILED)
2836 if (compile_def_function(ufunc, TRUE, NULL) == FAIL) 2835 if (compile_def_function(ufunc, TRUE, NULL) == FAIL)
2837 return FAIL; 2836 return FAIL;
2838 return generate_PUSHFUNC(cctx, vim_strsave(ufunc->uf_name), 2837 return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type);
2839 ufunc->uf_func_type);
2840 } 2838 }
2841 2839
2842 /* 2840 /*
2843 * Compile a variable name into a load instruction. 2841 * Compile a variable name into a load instruction.
2844 * "end" points to just after the name. 2842 * "end" points to just after the name.