Skip to content

Commit e149440

Browse files
committed
Merge branch 'master' of git://github.com/b4winckler/vim into kaoriya
Conflicts: .hgtags
2 parents 4b3ffb0 + 36d4cc8 commit e149440

File tree

4 files changed

+97
-34
lines changed

4 files changed

+97
-34
lines changed

.hgtags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,9 @@ ffa17de19445569ea573550eef332323d83e70bd v7-0-016
14781478
fff7028d50c8a44a6285ab23b451d975764b8bd5 v7-2-296
14791479
62e8d93241cd15962f895da4788f21b514238b14 v7-3-142
14801480
632f43801ddb568f872599499fdcfd9522f8c13f v7-3-143
1481+
322a5c8d392bd47ceebd24cd21dacf70409fcc91 v7-3-144
1482+
329a9676040c3182f78e2014322125f8839b5cb6 v7-3-145
1483+
2bd574a2ef1c0ad487a0673a5867b09cd332d176 v7-3-146
14811484
1aa9c79ff847cd945974dd6dec5172795ba6ad7a kaoriya-charspace
14821485
fb2739bfd7c786b788ef7bcd988b61071d2ebd82 kaoriya-transparency
14831486
c6ee0daceb5d8ed4c5d6f9c1d29a82c1d37a62f3 kaoriya-migemo

src/eval.c

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ static void list_one_var_a __ARGS((char_u *prefix, char_u *name, int type, char_
790790
static void set_var __ARGS((char_u *name, typval_T *varp, int copy));
791791
static int var_check_ro __ARGS((int flags, char_u *name));
792792
static int var_check_fixed __ARGS((int flags, char_u *name));
793+
static int var_check_func_name __ARGS((char_u *name, int new_var));
794+
static int valid_varname __ARGS((char_u *varname));
793795
static int tv_check_lock __ARGS((int lock, char_u *name));
794796
static int item_copy __ARGS((typval_T *from, typval_T *to, int deep, int copyID));
795797
static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags));
@@ -2717,8 +2719,27 @@ get_lval(name, rettv, lp, unlet, skip, quiet, fne_flags)
27172719
lp->ll_list = NULL;
27182720
lp->ll_dict = lp->ll_tv->vval.v_dict;
27192721
lp->ll_di = dict_find(lp->ll_dict, key, len);
2722+
2723+
/* When assigning to g: check that a function and variable name is
2724+
* valid. */
2725+
if (rettv != NULL && lp->ll_dict == &globvardict)
2726+
{
2727+
if (rettv->v_type == VAR_FUNC
2728+
&& var_check_func_name(key, lp->ll_di == NULL))
2729+
return NULL;
2730+
if (!valid_varname(key))
2731+
return NULL;
2732+
}
2733+
27202734
if (lp->ll_di == NULL)
27212735
{
2736+
/* Can't add "v:" variable. */
2737+
if (lp->ll_dict == &vimvardict)
2738+
{
2739+
EMSG2(_(e_illvar), name);
2740+
return NULL;
2741+
}
2742+
27222743
/* Key does not exist in dict: may need to add it. */
27232744
if (*p == '[' || *p == '.' || unlet)
27242745
{
@@ -2738,6 +2759,10 @@ get_lval(name, rettv, lp, unlet, skip, quiet, fne_flags)
27382759
p = NULL;
27392760
break;
27402761
}
2762+
/* existing variable, need to check if it can be changed */
2763+
else if (var_check_ro(lp->ll_di->di_flags, name))
2764+
return NULL;
2765+
27412766
if (len == -1)
27422767
clear_tv(&var1);
27432768
lp->ll_tv = &lp->ll_di->di_tv;
@@ -19817,7 +19842,6 @@ set_var(name, tv, copy)
1981719842
dictitem_T *v;
1981819843
char_u *varname;
1981919844
hashtab_T *ht;
19820-
char_u *p;
1982119845

1982219846
ht = find_var_ht(name, &varname);
1982319847
if (ht == NULL || *varname == NUL)
@@ -19827,25 +19851,8 @@ set_var(name, tv, copy)
1982719851
}
1982819852
v = find_var_in_ht(ht, varname, TRUE);
1982919853

19830-
if (tv->v_type == VAR_FUNC)
19831-
{
19832-
if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':')
19833-
&& !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
19834-
? name[2] : name[0]))
19835-
{
19836-
EMSG2(_("E704: Funcref variable name must start with a capital: %s"), name);
19837-
return;
19838-
}
19839-
/* Don't allow hiding a function. When "v" is not NULL we might be
19840-
* assigning another function to the same var, the type is checked
19841-
* below. */
19842-
if (v == NULL && function_exists(name))
19843-
{
19844-
EMSG2(_("E705: Variable name conflicts with existing function: %s"),
19845-
name);
19846-
return;
19847-
}
19848-
}
19854+
if (tv->v_type == VAR_FUNC && var_check_func_name(name, v == NULL))
19855+
return;
1984919856

1985019857
if (v != NULL)
1985119858
{
@@ -19911,13 +19918,8 @@ set_var(name, tv, copy)
1991119918
}
1991219919

1991319920
/* Make sure the variable name is valid. */
19914-
for (p = varname; *p != NUL; ++p)
19915-
if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
19916-
&& *p != AUTOLOAD_CHAR)
19917-
{
19918-
EMSG2(_(e_illvar), varname);
19919-
return;
19920-
}
19921+
if (!valid_varname(varname))
19922+
return;
1992119923

1992219924
v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
1992319925
+ STRLEN(varname)));
@@ -19981,6 +19983,55 @@ var_check_fixed(flags, name)
1998119983
return FALSE;
1998219984
}
1998319985

19986+
/*
19987+
* Check if a funcref is assigned to a valid variable name.
19988+
* Return TRUE and give an error if not.
19989+
*/
19990+
static int
19991+
var_check_func_name(name, new_var)
19992+
char_u *name; /* points to start of variable name */
19993+
int new_var; /* TRUE when creating the variable */
19994+
{
19995+
if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':')
19996+
&& !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
19997+
? name[2] : name[0]))
19998+
{
19999+
EMSG2(_("E704: Funcref variable name must start with a capital: %s"),
20000+
name);
20001+
return TRUE;
20002+
}
20003+
/* Don't allow hiding a function. When "v" is not NULL we might be
20004+
* assigning another function to the same var, the type is checked
20005+
* below. */
20006+
if (new_var && function_exists(name))
20007+
{
20008+
EMSG2(_("E705: Variable name conflicts with existing function: %s"),
20009+
name);
20010+
return TRUE;
20011+
}
20012+
return FALSE;
20013+
}
20014+
20015+
/*
20016+
* Check if a variable name is valid.
20017+
* Return FALSE and give an error if not.
20018+
*/
20019+
static int
20020+
valid_varname(varname)
20021+
char_u *varname;
20022+
{
20023+
char_u *p;
20024+
20025+
for (p = varname; *p != NUL; ++p)
20026+
if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
20027+
&& *p != AUTOLOAD_CHAR)
20028+
{
20029+
EMSG2(_(e_illvar), varname);
20030+
return FALSE;
20031+
}
20032+
return TRUE;
20033+
}
20034+
1998420035
/*
1998520036
* Return TRUE if typeval "tv" is set to be locked (immutable).
1998620037
* Also give an error message, using "name".

src/if_python.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct PyMethodDef { Py_ssize_t a; };
165165
# define PySys_SetObject dll_PySys_SetObject
166166
# define PySys_SetArgv dll_PySys_SetArgv
167167
# define PyType_Type (*dll_PyType_Type)
168+
# define PyType_Ready (*dll_PyType_Ready)
168169
# define Py_BuildValue dll_Py_BuildValue
169170
# define Py_FindMethod dll_Py_FindMethod
170171
# define Py_InitModule4 dll_Py_InitModule4
@@ -224,6 +225,7 @@ static PyTypeObject* dll_PyString_Type;
224225
static int(*dll_PySys_SetObject)(char *, PyObject *);
225226
static int(*dll_PySys_SetArgv)(int, char **);
226227
static PyTypeObject* dll_PyType_Type;
228+
static int (*dll_PyType_Ready)(PyTypeObject *type);
227229
static PyObject*(*dll_Py_BuildValue)(char *, ...);
228230
static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *);
229231
static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int);
@@ -305,6 +307,7 @@ static struct
305307
{"PySys_SetObject", (PYTHON_PROC*)&dll_PySys_SetObject},
306308
{"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv},
307309
{"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type},
310+
{"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready},
308311
{"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue},
309312
{"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod},
310313
# if (PY_VERSION_HEX >= 0x02050000) && SIZEOF_SIZE_T != SIZEOF_INT
@@ -780,7 +783,7 @@ OutputSetattr(PyObject *self, char *name, PyObject *val)
780783
PythonIO_Init(void)
781784
{
782785
/* Fixups... */
783-
OutputType.ob_type = &PyType_Type;
786+
PyType_Ready(&OutputType);
784787

785788
return PythonIO_Init_io();
786789
}
@@ -1402,12 +1405,12 @@ PythonMod_Init(void)
14021405
static char *(argv[2]) = {"/must>not&exist/foo", NULL};
14031406

14041407
/* Fixups... */
1405-
BufferType.ob_type = &PyType_Type;
1406-
RangeType.ob_type = &PyType_Type;
1407-
WindowType.ob_type = &PyType_Type;
1408-
BufListType.ob_type = &PyType_Type;
1409-
WinListType.ob_type = &PyType_Type;
1410-
CurrentType.ob_type = &PyType_Type;
1408+
PyType_Ready(&BufferType);
1409+
PyType_Ready(&RangeType);
1410+
PyType_Ready(&WindowType);
1411+
PyType_Ready(&BufListType);
1412+
PyType_Ready(&WinListType);
1413+
PyType_Ready(&CurrentType);
14111414

14121415
/* Set sys.argv[] to avoid a crash in warn(). */
14131416
PySys_SetArgv(1, argv);

src/version.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,12 @@ static char *(features[]) =
725725

726726
static int included_patches[] =
727727
{ /* Add new patch number below this line */
728+
/**/
729+
146,
730+
/**/
731+
145,
732+
/**/
733+
144,
728734
/**/
729735
143,
730736
/**/

0 commit comments

Comments
 (0)