Patch 8.2.2254

7 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 31, 2020, 11:42:02 AM12/31/20
to vim...@googlegroups.com

Patch 8.2.2254
Problem: Vim9: bool option type is number.
Solution: Have get_option_value() return a different value for bool and
number options. (closes #7583)
Files: src/option.h, src/option.c, src/proto/option.pro, src/evalvars.c,
src/if_mzsch.c, src/if_ruby.c, src/spell.c, src/typval.c,
src/vim9compile.c, src/testdir/test_vim9_assign.vim,
src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2253/src/option.h 2020-08-11 21:58:12.585968185 +0200
--- src/option.h 2020-12-31 17:02:53.832983464 +0100
***************
*** 60,65 ****
--- 60,76 ----
#define P_RWINONLY 0x10000000L // only redraw current window
#define P_MLE 0x20000000L // under control of 'modelineexpr'

+ // Returned by get_option_value().
+ typedef enum {
+ gov_unknown,
+ gov_bool,
+ gov_number,
+ gov_string,
+ gov_hidden_bool,
+ gov_hidden_number,
+ gov_hidden_string
+ } getoption_T;
+
/*
* Default values for 'errorformat'.
* The "%f|%l| %m" one is used for when the contents of the quickfix window is
*** ../vim-8.2.2253/src/option.c 2020-12-21 19:59:04.565197736 +0100
--- src/option.c 2020-12-31 16:54:06.330813166 +0100
***************
*** 3834,3846 ****
* Get the value for an option.
*
* Returns:
! * Number or Toggle option: 1, *numval gets value.
! * String option: 0, *stringval gets allocated string.
! * Hidden Number or Toggle option: -1.
! * hidden String option: -2.
! * unknown option: -3.
*/
! int
get_option_value(
char_u *name,
long *numval,
--- 3834,3848 ----
* Get the value for an option.
*
* Returns:
! * Number option: gov_number, *numval gets value.
! * Tottle option: gov_bool, *numval gets value.
! * String option: gov_string, *stringval gets allocated string.
! * Hidden Number option: gov_hidden_number.
! * Hidden Toggle option: gov_hidden_bool.
! * Hidden String option: gov_hidden_string.
! * Unknown option: gov_unknown.
*/
! getoption_T
get_option_value(
char_u *name,
long *numval,
***************
*** 3851,3866 ****
char_u *varp;

opt_idx = findoption(name);
! if (opt_idx < 0) // unknown option
{
int key;

if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
! && (key = find_key_option(name, FALSE)) != 0)
{
char_u key_name[2];
char_u *p;

if (key < 0)
{
key_name[0] = KEY2TERMCAP0(key);
--- 3853,3869 ----
char_u *varp;

opt_idx = findoption(name);
! if (opt_idx < 0) // option not in the table
{
int key;

if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
! && (key = find_key_option(name, FALSE)) != 0)
{
char_u key_name[2];
char_u *p;

+ // check for a terminal option
if (key < 0)
{
key_name[0] = KEY2TERMCAP0(key);
***************
*** 3876,3885 ****
{
if (stringval != NULL)
*stringval = vim_strsave(p);
! return 0;
}
}
! return -3;
}

varp = get_varp_scope(&(options[opt_idx]), opt_flags);
--- 3879,3888 ----
{
if (stringval != NULL)
*stringval = vim_strsave(p);
! return gov_string;
}
}
! return gov_unknown;
}

varp = get_varp_scope(&(options[opt_idx]), opt_flags);
***************
*** 3887,3893 ****
if (options[opt_idx].flags & P_STRING)
{
if (varp == NULL) // hidden option
! return -2;
if (stringval != NULL)
{
#ifdef FEAT_CRYPT
--- 3890,3896 ----
if (options[opt_idx].flags & P_STRING)
{
if (varp == NULL) // hidden option
! return gov_hidden_string;
if (stringval != NULL)
{
#ifdef FEAT_CRYPT
***************
*** 3899,3909 ****
#endif
*stringval = vim_strsave(*(char_u **)(varp));
}
! return 0;
}

if (varp == NULL) // hidden option
! return -1;
if (options[opt_idx].flags & P_NUM)
*numval = *(long *)varp;
else
--- 3902,3913 ----
#endif
*stringval = vim_strsave(*(char_u **)(varp));
}
! return gov_string;
}

if (varp == NULL) // hidden option
! return (options[opt_idx].flags & P_NUM)
! ? gov_hidden_number : gov_hidden_bool;
if (options[opt_idx].flags & P_NUM)
*numval = *(long *)varp;
else
***************
*** 3915,3921 ****
else
*numval = (long) *(int *)varp;
}
! return 1;
}
#endif

--- 3919,3925 ----
else
*numval = (long) *(int *)varp;
}
! return (options[opt_idx].flags & P_NUM) ? gov_number : gov_bool;
}
#endif

*** ../vim-8.2.2253/src/proto/option.pro 2020-12-21 19:59:04.565197736 +0100
--- src/proto/option.pro 2020-12-31 17:25:37.395243058 +0100
***************
*** 24,30 ****
void set_term_option_sctx_idx(char *name, int opt_idx);
void check_redraw(long_u flags);
int findoption(char_u *arg);
! int get_option_value(char_u *name, long *numval, char_u **stringval, int opt_flags);
int get_option_value_strict(char_u *name, long *numval, char_u **stringval, int opt_type, void *from);
char_u *option_iter_next(void **option, int opt_type);
long_u get_option_flags(int opt_idx);
--- 24,30 ----
void set_term_option_sctx_idx(char *name, int opt_idx);
void check_redraw(long_u flags);
int findoption(char_u *arg);
! getoption_T get_option_value(char_u *name, long *numval, char_u **stringval, int opt_flags);
int get_option_value_strict(char_u *name, long *numval, char_u **stringval, int opt_type, void *from);
char_u *option_iter_next(void **option, int opt_type);
long_u get_option_flags(int opt_idx);
*** ../vim-8.2.2253/src/evalvars.c 2020-12-27 13:39:44.659044653 +0100
--- src/evalvars.c 2020-12-31 16:41:49.313321631 +0100
***************
*** 1354,1360 ****
else
{
long n = 0;
! int opt_type;
long numval;
char_u *stringval = NULL;
char_u *s = NULL;
--- 1354,1360 ----
else
{
long n = 0;
! getoption_T opt_type;
long numval;
char_u *stringval = NULL;
char_u *s = NULL;
***************
*** 1364,1370 ****
*p = NUL;

opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
! if ((opt_type == 1 || opt_type == -1)
&& (tv->v_type != VAR_STRING || !in_vim9script()))
// number, possibly hidden
n = (long)tv_get_number(tv);
--- 1364,1373 ----
*p = NUL;

opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
! if ((opt_type == gov_bool
! || opt_type == gov_number
! || opt_type == gov_hidden_bool
! || opt_type == gov_hidden_number)
&& (tv->v_type != VAR_STRING || !in_vim9script()))
// number, possibly hidden
n = (long)tv_get_number(tv);
***************
*** 1377,1384 ****

if (op != NULL && *op != '=')
{
! if ((opt_type == 1 && *op == '.')
! || (opt_type == 0 && *op != '.'))
{
semsg(_(e_letwrong), op);
failed = TRUE; // don't set the value
--- 1380,1388 ----

if (op != NULL && *op != '=')
{
! if (((opt_type == gov_bool || opt_type == gov_number)
! && *op == '.')
! || (opt_type == gov_string && *op != '.'))
{
semsg(_(e_letwrong), op);
failed = TRUE; // don't set the value
***************
*** 1386,1392 ****
}
else
{
! if (opt_type == 1) // number
{
switch (*op)
{
--- 1390,1398 ----
}
else
{
! // number, in legacy script also bool
! if (opt_type == gov_number
! || (opt_type == gov_bool && !in_vim9script()))
{
switch (*op)
{
***************
*** 1397,1403 ****
case '%': n = (long)num_modulus(numval, n); break;
}
}
! else if (opt_type == 0 && stringval != NULL && s != NULL)
{
// string
s = concat_str(stringval, s);
--- 1403,1410 ----
case '%': n = (long)num_modulus(numval, n); break;
}
}
! else if (opt_type == gov_string
! && stringval != NULL && s != NULL)
{
// string
s = concat_str(stringval, s);
***************
*** 1409,1415 ****

if (!failed)
{
! if (opt_type != 0 || s != NULL)
{
set_option_value(arg, n, s, opt_flags);
arg_end = p;
--- 1416,1422 ----

if (!failed)
{
! if (opt_type != gov_string || s != NULL)
{
set_option_value(arg, n, s, opt_flags);
arg_end = p;
*** ../vim-8.2.2253/src/if_mzsch.c 2020-08-11 21:58:12.581968226 +0200
--- src/if_mzsch.c 2020-12-31 16:43:14.917035733 +0100
***************
*** 1712,1718 ****
Vim_Prim *prim = (Vim_Prim *)data;
long value;
char *strval;
! int rc;
Scheme_Object *rval = NULL;
Scheme_Object *name = NULL;
int opt_flags = 0;
--- 1712,1718 ----
Vim_Prim *prim = (Vim_Prim *)data;
long value;
char *strval;
! getoption_T rc;
Scheme_Object *rval = NULL;
Scheme_Object *name = NULL;
int opt_flags = 0;
***************
*** 1754,1780 ****
scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
}

! rc = get_option_value(BYTE_STRING_VALUE(name), &value, (char_u **)&strval, opt_flags);
curbuf = save_curb;
curwin = save_curw;

switch (rc)
{
! case 1:
MZ_GC_UNREG();
return scheme_make_integer_value(value);
! case 0:
rval = scheme_make_byte_string(strval);
MZ_GC_CHECK();
vim_free(strval);
MZ_GC_UNREG();
return rval;
! case -1:
! case -2:
MZ_GC_UNREG();
raise_vim_exn(_("hidden option"));
//NOTREACHED
! case -3:
MZ_GC_UNREG();
raise_vim_exn(_("unknown option"));
//NOTREACHED
--- 1754,1783 ----
scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
}

! rc = get_option_value(BYTE_STRING_VALUE(name), &value, (char_u **)&strval,
! opt_flags);
curbuf = save_curb;
curwin = save_curw;

switch (rc)
{
! case gov_bool:
! case gov_number:
MZ_GC_UNREG();
return scheme_make_integer_value(value);
! case gov_string:
rval = scheme_make_byte_string(strval);
MZ_GC_CHECK();
vim_free(strval);
MZ_GC_UNREG();
return rval;
! case gov_hidden_bool:
! case gov_hidden_number:
! case gov_hidden_string:
MZ_GC_UNREG();
raise_vim_exn(_("hidden option"));
//NOTREACHED
! case gov_unknown:
MZ_GC_UNREG();
raise_vim_exn(_("unknown option"));
//NOTREACHED
*** ../vim-8.2.2253/src/if_ruby.c 2020-12-28 15:07:42.129637933 +0100
--- src/if_ruby.c 2020-12-31 16:45:05.168664765 +0100
***************
*** 865,877 ****
vim_str2rb_enc_str(const char *s)
{
#if RUBY_VERSION >= 19
- int isnum;
long lval;
char_u *sval;
rb_encoding *enc;

! isnum = get_option_value((char_u *)"enc", &lval, &sval, 0);
! if (isnum == 0)
{
enc = rb_enc_find((char *)sval);
vim_free(sval);
--- 865,875 ----
vim_str2rb_enc_str(const char *s)
{
#if RUBY_VERSION >= 19
long lval;
char_u *sval;
rb_encoding *enc;

! if (get_option_value((char_u *)"enc", &lval, &sval, 0) == gov_string)
{
enc = rb_enc_find((char *)sval);
vim_free(sval);
***************
*** 886,899 ****
eval_enc_string_protect(const char *str, int *state)
{
#if RUBY_VERSION >= 19
- int isnum;
long lval;
char_u *sval;
rb_encoding *enc;
VALUE v;

! isnum = get_option_value((char_u *)"enc", &lval, &sval, 0);
! if (isnum == 0)
{
enc = rb_enc_find((char *)sval);
vim_free(sval);
--- 884,895 ----
eval_enc_string_protect(const char *str, int *state)
{
#if RUBY_VERSION >= 19
long lval;
char_u *sval;
rb_encoding *enc;
VALUE v;

! if (get_option_value((char_u *)"enc", &lval, &sval, 0) == gov_string)
{
enc = rb_enc_find((char *)sval);
vim_free(sval);
*** ../vim-8.2.2253/src/spell.c 2020-10-30 19:25:06.829693344 +0100
--- src/spell.c 2020-12-31 16:54:12.534791736 +0100
***************
*** 3813,3819 ****

if (no_spell_checking(curwin))
return;
! get_option_value((char_u*)"spl", &dummy, &spl, OPT_LOCAL);

// Create a new empty buffer in a new window.
do_cmdline_cmd((char_u *)"new");
--- 3813,3819 ----

if (no_spell_checking(curwin))
return;
! (void)get_option_value((char_u*)"spl", &dummy, &spl, OPT_LOCAL);

// Create a new empty buffer in a new window.
do_cmdline_cmd((char_u *)"new");
*** ../vim-8.2.2253/src/typval.c 2020-12-21 21:58:42.603687817 +0100
--- src/typval.c 2020-12-31 16:59:50.633620275 +0100
***************
*** 1083,1089 ****
char_u *option_end;
long numval;
char_u *stringval;
! int opt_type;
int c;
int working = (**arg == '+'); // has("+option")
int ret = OK;
--- 1083,1089 ----
char_u *option_end;
long numval;
char_u *stringval;
! getoption_T opt_type;
int c;
int working = (**arg == '+'); // has("+option")
int ret = OK;
***************
*** 1109,1115 ****
opt_type = get_option_value(*arg, &numval,
rettv == NULL ? NULL : &stringval, opt_flags);

! if (opt_type == -3) // invalid name
{
if (rettv != NULL)
semsg(_(e_unknown_option), *arg);
--- 1109,1115 ----
opt_type = get_option_value(*arg, &numval,
rettv == NULL ? NULL : &stringval, opt_flags);

! if (opt_type == gov_unknown)
{
if (rettv != NULL)
semsg(_(e_unknown_option), *arg);
***************
*** 1117,1136 ****
}
else if (rettv != NULL)
{
! if (opt_type == -2) // hidden string option
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
}
! else if (opt_type == -1) // hidden number option
{
! rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
}
! else if (opt_type == 1) // number option
{
! rettv->v_type = VAR_NUMBER;
! rettv->vval.v_number = numval;
}
else // string option
{
--- 1117,1145 ----
}
else if (rettv != NULL)
{
! if (opt_type == gov_hidden_string)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
}
! else if (opt_type == gov_hidden_bool || opt_type == gov_hidden_number)
{
! rettv->v_type = in_vim9script() && opt_type == gov_hidden_bool
! ? VAR_BOOL : VAR_NUMBER;
rettv->vval.v_number = 0;
}
! else if (opt_type == gov_bool || opt_type == gov_number)
{
! if (in_vim9script() && opt_type == gov_bool)
! {
! rettv->v_type = VAR_BOOL;
! rettv->vval.v_number = numval ? VVAL_TRUE : VVAL_FALSE;
! }
! else
! {
! rettv->v_type = VAR_NUMBER;
! rettv->vval.v_number = numval;
! }
}
else // string option
{
***************
*** 1138,1144 ****
rettv->vval.v_string = stringval;
}
}
! else if (working && (opt_type == -2 || opt_type == -1))
ret = FAIL;

*option_end = c; // put back for error messages
--- 1147,1155 ----
rettv->vval.v_string = stringval;
}
}
! else if (working && (opt_type == gov_hidden_bool
! || opt_type == gov_hidden_number
! || opt_type == gov_hidden_string))
ret = FAIL;

*option_end = c; // put back for error messages
*** ../vim-8.2.2253/src/vim9compile.c 2020-12-31 13:31:20.521507996 +0100
--- src/vim9compile.c 2020-12-31 17:02:33.297054888 +0100
***************
*** 5191,5199 ****

if (*name == '&')
{
! int cc;
! long numval;
! int opt_type;

*dest = dest_option;
if (cmdidx == CMD_final || cmdidx == CMD_const)
--- 5191,5199 ----

if (*name == '&')
{
! int cc;
! long numval;
! getoption_T opt_type;

*dest = dest_option;
if (cmdidx == CMD_final || cmdidx == CMD_const)
***************
*** 5214,5228 ****
opt_type = get_option_value(skip_option_env_lead(name),
&numval, NULL, *opt_flags);
*p = cc;
! if (opt_type == -3)
{
! semsg(_(e_unknown_option), name);
! return FAIL;
}
- if (opt_type == -2 || opt_type == 0)
- *type = &t_string;
- else
- *type = &t_number; // both number and boolean option
}
else if (*name == '$')
{
--- 5214,5237 ----
opt_type = get_option_value(skip_option_env_lead(name),
&numval, NULL, *opt_flags);
*p = cc;
! switch (opt_type)
{
! case gov_unknown:
! semsg(_(e_unknown_option), name);
! return FAIL;
! case gov_string:
! case gov_hidden_string:
! *type = &t_string;
! break;
! case gov_bool:
! case gov_hidden_bool:
! *type = &t_bool;
! break;
! case gov_number:
! case gov_hidden_number:
! *type = &t_number;
! break;
}
}
else if (*name == '$')
{
*** ../vim-8.2.2253/src/testdir/test_vim9_assign.vim 2020-12-25 15:24:19.902942195 +0100
--- src/testdir/test_vim9_assign.vim 2020-12-31 17:39:05.368375992 +0100
***************
*** 45,50 ****
--- 45,53 ----
assert_equal(true, flag)
flag = 1 && false
assert_equal(false, flag)
+
+ var cp: bool = &cp
+ var fen: bool = &l:fen
END
CheckScriptSuccess(lines)
CheckDefAndScriptFailure(['var x: bool = 2'], 'E1012:')
***************
*** 118,123 ****
--- 121,128 ----
assert_equal('new', s:newVar)

set ts=7
+ var ts: number = &ts
+ assert_equal(7, ts)
&ts += 1
assert_equal(8, &ts)
&ts -= 3
*** ../vim-8.2.2253/src/testdir/test_vim9_cmd.vim 2020-12-29 11:14:58.444606193 +0100
--- src/testdir/test_vim9_cmd.vim 2020-12-31 17:36:23.332824435 +0100
***************
*** 590,596 ****
unlet g:readFile

noswapfile edit XnoSwap
! assert_equal(0, &l:swapfile)
bwipe!

var caught = false
--- 590,596 ----
unlet g:readFile

noswapfile edit XnoSwap
! assert_equal(false, &l:swapfile)
bwipe!

var caught = false
*** ../vim-8.2.2253/src/version.c 2020-12-31 13:39:50.611835025 +0100
--- src/version.c 2020-12-31 17:40:24.412175370 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2254,
/**/

--
Creating the world with Emacs: M-x let-there-be-light
Creating the world with Vim: :make world

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christ van Willegen

unread,
Dec 31, 2020, 1:19:06 PM12/31/20
to vim...@googlegroups.com
Hi,

Op do 31 dec. 2020 17:42 schreef Bram Moolenaar <Br...@moolenaar.net>:

Patch 8.2.2254
Problem:    Vim9: bool option type is number.
Solution:   Have get_option_value() return a different value for bool and
            number options. (closes #7583)

--- src/option.c        2020-12-31 16:54:06.330813166 +0100
***************
*** 3834,3846 ****
   * Get the value for an option.
   *
   * Returns:
!  * Number or Toggle option: 1, *numval gets value.
!  *         String option: 0, *stringval gets allocated string.
!  * Hidden Number or Toggle option: -1.
!  *         hidden String option: -2.
!  *               unknown option: -3.
   */
!     int
  get_option_value(
      char_u    *name,
      long      *numval,
--- 3834,3848 ----
   * Get the value for an option.
   *
   * Returns:
!  * Number option: gov_number, *numval gets value.
!  * Tottle option: gov_bool,   *numval gets value.


Toggle option meant here??

Christ van Willegen

Bram Moolenaar

unread,
Dec 31, 2020, 4:36:18 PM12/31/20
to vim...@googlegroups.com, Christ van Willegen
Most likely. Or it could be "Tuttle"
( https://en.wikipedia.org/wiki/Brazil_(1985_film)#:~:text=Robert%20De%20Niro%20as%20Archibald,the%20smaller%20role%20of%20Tuttle ) ?

--
hundred-and-one symptoms of being an internet addict:
63. You start using smileys in your snail mail.
Reply all
Reply to author
Forward
0 new messages