Patch 8.2.3879

3 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 24, 2021, 5:49:06 AM12/24/21
to vim...@googlegroups.com

Patch 8.2.3879
Problem: getreg() and getregtype() contain dead code.
Solution: Remove the needless check. (closes #9392) Also refactor to put
common code in a shared function.
Files: src/evalfunc.c


*** ../vim-8.2.3878/src/evalfunc.c 2021-12-22 18:45:25.251852546 +0000
--- src/evalfunc.c 2021-12-24 10:45:22.564794453 +0000
***************
*** 4675,4690 ****
}

/*
* "getreg()" function
*/
static void
f_getreg(typval_T *argvars, typval_T *rettv)
{
- char_u *strregname;
int regname;
int arg2 = FALSE;
int return_list = FALSE;
- int error = FALSE;

if (in_vim9script()
&& (check_for_opt_string_arg(argvars, 0) == FAIL
--- 4675,4716 ----
}

/*
+ * Common between getreg() and getregtype(): get the register name from the
+ * first argument.
+ * Returns zero on error.
+ */
+ static int
+ getreg_get_regname(typval_T *argvars)
+ {
+ char_u *strregname;
+
+ if (argvars[0].v_type != VAR_UNKNOWN)
+ {
+ strregname = tv_get_string_chk(&argvars[0]);
+ if (strregname != NULL && in_vim9script() && STRLEN(strregname) > 1)
+ {
+ semsg(_(e_register_name_must_be_one_char_str), strregname);
+ strregname = NULL;
+ }
+ if (strregname == NULL) // type error; errmsg already given
+ return 0;
+ }
+ else
+ // Default to v:register
+ strregname = get_vim_var_str(VV_REG);
+
+ return *strregname == 0 ? '"' : *strregname;
+ }
+
+ /*
* "getreg()" function
*/
static void
f_getreg(typval_T *argvars, typval_T *rettv)
{
int regname;
int arg2 = FALSE;
int return_list = FALSE;

if (in_vim9script()
&& (check_for_opt_string_arg(argvars, 0) == FAIL
***************
*** 4694,4725 ****
&& check_for_opt_bool_arg(argvars, 2) == FAIL)))))
return;

! if (argvars[0].v_type != VAR_UNKNOWN)
{
! strregname = tv_get_string_chk(&argvars[0]);
! if (strregname == NULL)
! error = TRUE;
! else if (in_vim9script() && STRLEN(strregname) > 1)
! {
! semsg(_(e_register_name_must_be_one_char_str), strregname);
! error = TRUE;
! }
! if (argvars[1].v_type != VAR_UNKNOWN)
! {
! arg2 = (int)tv_get_bool_chk(&argvars[1], &error);
! if (!error && argvars[2].v_type != VAR_UNKNOWN)
! return_list = (int)tv_get_bool_chk(&argvars[2], &error);
! }
! }
! else
! strregname = get_vim_var_str(VV_REG);

! if (error)
! return;

! regname = (strregname == NULL ? '"' : *strregname);
! if (regname == 0)
! regname = '"';

if (return_list)
{
--- 4720,4740 ----
&& check_for_opt_bool_arg(argvars, 2) == FAIL)))))
return;

! regname = getreg_get_regname(argvars);
! if (regname == 0)
! return;
!
! if (argvars[0].v_type != VAR_UNKNOWN && argvars[1].v_type != VAR_UNKNOWN)
{
! int error = FALSE;

! arg2 = (int)tv_get_bool_chk(&argvars[1], &error);

! if (!error && argvars[2].v_type != VAR_UNKNOWN)
! return_list = (int)tv_get_bool_chk(&argvars[2], &error);
! if (error)
! return;
! }

if (return_list)
{
***************
*** 4745,4780 ****
static void
f_getregtype(typval_T *argvars, typval_T *rettv)
{
- char_u *strregname;
int regname;
char_u buf[NUMBUFLEN + 2];
long reglen = 0;

if (in_vim9script() && check_for_opt_string_arg(argvars, 0) == FAIL)
return;

! if (argvars[0].v_type != VAR_UNKNOWN)
! {
! strregname = tv_get_string_chk(&argvars[0]);
! if (strregname != NULL && in_vim9script() && STRLEN(strregname) > 1)
! {
! semsg(_(e_register_name_must_be_one_char_str), strregname);
! strregname = NULL;
! }
! if (strregname == NULL) // type error; errmsg already given
! {
! rettv->v_type = VAR_STRING;
! rettv->vval.v_string = NULL;
! return;
! }
! }
! else
! // Default to v:register
! strregname = get_vim_var_str(VV_REG);
!
! regname = (strregname == NULL ? '"' : *strregname);
if (regname == 0)
! regname = '"';

buf[0] = NUL;
buf[1] = NUL;
--- 4760,4779 ----
static void
f_getregtype(typval_T *argvars, typval_T *rettv)
{
int regname;
char_u buf[NUMBUFLEN + 2];
long reglen = 0;

+ // on error return an empty string
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = NULL;
+
if (in_vim9script() && check_for_opt_string_arg(argvars, 0) == FAIL)
return;

! regname = getreg_get_regname(argvars);
if (regname == 0)
! return;

buf[0] = NUL;
buf[1] = NUL;
*** ../vim-8.2.3878/src/version.c 2021-12-23 21:14:34.368204908 +0000
--- src/version.c 2021-12-24 10:46:32.936602305 +0000
***************
*** 751,752 ****
--- 751,754 ----
{ /* Add new patch number below this line */
+ /**/
+ 3879,
/**/

--
A fool learns from his mistakes, a wise man from someone else's.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages