Mercurial > vim
comparison src/if_lua.c @ 21108:43e82e8133b9 v8.2.1105
patch 8.2.1105: insufficient test coverage for Lua
Commit: https://github.com/vim/vim/commit/e49b8e8d7589e85e75aedefab7ce97da47adbf74
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 1 13:52:55 2020 +0200
patch 8.2.1105: insufficient test coverage for Lua
Problem: Insufficient test coverage for Lua.
Solution: Add tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6368) Fix uncovered
memory leak. Avoid unnecessary copy/free.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 01 Jul 2020 14:00:05 +0200 |
parents | 89aba7895bb2 |
children | 985e61894bb4 |
comparison
equal
deleted
inserted
replaced
21107:149a89396e3d | 21108:43e82e8133b9 |
---|---|
934 else | 934 else |
935 { | 935 { |
936 typval_T v; | 936 typval_T v; |
937 luaV_checktypval(L, 3, &v, "setting list item"); | 937 luaV_checktypval(L, 3, &v, "setting list item"); |
938 clear_tv(&li->li_tv); | 938 clear_tv(&li->li_tv); |
939 copy_tv(&v, &li->li_tv); | 939 li->li_tv = v; |
940 clear_tv(&v); | |
941 } | 940 } |
942 } | 941 } |
943 return 0; | 942 return 0; |
944 } | 943 } |
945 | 944 |
1082 luaV_dict_newindex(lua_State *L) | 1081 luaV_dict_newindex(lua_State *L) |
1083 { | 1082 { |
1084 dict_T *d = luaV_unbox(L, luaV_Dict, 1); | 1083 dict_T *d = luaV_unbox(L, luaV_Dict, 1); |
1085 char_u *key = (char_u *) luaL_checkstring(L, 2); | 1084 char_u *key = (char_u *) luaL_checkstring(L, 2); |
1086 dictitem_T *di; | 1085 dictitem_T *di; |
1087 typval_T v; | 1086 typval_T tv; |
1088 | 1087 |
1089 if (d->dv_lock) | 1088 if (d->dv_lock) |
1090 luaL_error(L, "dict is locked"); | 1089 luaL_error(L, "dict is locked"); |
1091 if (key == NULL) | 1090 if (key == NULL) |
1092 return 0; | 1091 return 0; |
1093 if (*key == NUL) | 1092 if (*key == NUL) |
1094 luaL_error(L, "empty key"); | 1093 luaL_error(L, "empty key"); |
1095 if (!lua_isnil(L, 3)) // read value? | 1094 if (!lua_isnil(L, 3)) // read value? |
1096 { | 1095 { |
1097 luaV_checktypval(L, 3, &v, "setting dict item"); | 1096 luaV_checktypval(L, 3, &tv, "setting dict item"); |
1098 if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC) | 1097 if (d->dv_scope == VAR_DEF_SCOPE && tv.v_type == VAR_FUNC) |
1098 { | |
1099 clear_tv(&tv); | |
1099 luaL_error(L, "cannot assign funcref to builtin scope"); | 1100 luaL_error(L, "cannot assign funcref to builtin scope"); |
1101 } | |
1100 } | 1102 } |
1101 di = dict_find(d, key, -1); | 1103 di = dict_find(d, key, -1); |
1102 if (di == NULL) // non-existing key? | 1104 if (di == NULL) // non-existing key? |
1103 { | 1105 { |
1104 if (lua_isnil(L, 3)) | 1106 if (lua_isnil(L, 3)) |
1105 return 0; | 1107 return 0; |
1106 di = dictitem_alloc(key); | 1108 di = dictitem_alloc(key); |
1107 if (di == NULL) | 1109 if (di == NULL) |
1110 { | |
1111 clear_tv(&tv); | |
1108 return 0; | 1112 return 0; |
1113 } | |
1109 if (dict_add(d, di) == FAIL) | 1114 if (dict_add(d, di) == FAIL) |
1110 { | 1115 { |
1111 vim_free(di); | 1116 vim_free(di); |
1117 clear_tv(&tv); | |
1112 return 0; | 1118 return 0; |
1113 } | 1119 } |
1114 } | 1120 } |
1115 else | 1121 else |
1116 clear_tv(&di->di_tv); | 1122 clear_tv(&di->di_tv); |
1119 hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key); | 1125 hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key); |
1120 hash_remove(&d->dv_hashtab, hi); | 1126 hash_remove(&d->dv_hashtab, hi); |
1121 dictitem_free(di); | 1127 dictitem_free(di); |
1122 } | 1128 } |
1123 else | 1129 else |
1124 { | 1130 di->di_tv = tv; |
1125 copy_tv(&v, &di->di_tv); | |
1126 clear_tv(&v); | |
1127 } | |
1128 return 0; | 1131 return 0; |
1129 } | 1132 } |
1130 | 1133 |
1131 static const luaL_Reg luaV_Dict_mt[] = { | 1134 static const luaL_Reg luaV_Dict_mt[] = { |
1132 {"__tostring", luaV_dict_tostring}, | 1135 {"__tostring", luaV_dict_tostring}, |
1439 if (curwin->w_cursor.lnum > n) | 1442 if (curwin->w_cursor.lnum > n) |
1440 { | 1443 { |
1441 curwin->w_cursor.lnum -= 1; | 1444 curwin->w_cursor.lnum -= 1; |
1442 check_cursor_col(); | 1445 check_cursor_col(); |
1443 } | 1446 } |
1444 else check_cursor(); | 1447 else |
1448 check_cursor(); | |
1445 changed_cline_bef_curs(); | 1449 changed_cline_bef_curs(); |
1446 } | 1450 } |
1447 invalidate_botline(); | 1451 invalidate_botline(); |
1448 } | 1452 } |
1449 } | 1453 } |
1840 { | 1844 { |
1841 vim_free(di); | 1845 vim_free(di); |
1842 lua_pushnil(L); | 1846 lua_pushnil(L); |
1843 return 1; | 1847 return 1; |
1844 } | 1848 } |
1845 copy_tv(&v, &di->di_tv); | 1849 di->di_tv = v; |
1846 clear_tv(&v); | |
1847 lua_pop(L, 2); // key copy and value | 1850 lua_pop(L, 2); // key copy and value |
1848 } | 1851 } |
1849 } | 1852 } |
1850 } | 1853 } |
1851 return 1; | 1854 return 1; |
2396 } | 2399 } |
2397 lua_call(L, 0, 1); | 2400 lua_call(L, 0, 1); |
2398 lua_replace(L, -2); // function -> body | 2401 lua_replace(L, -2); // function -> body |
2399 for (l = eap->line1; l <= eap->line2; l++) | 2402 for (l = eap->line1; l <= eap->line2; l++) |
2400 { | 2403 { |
2401 // Check the line number, the command my have deleted lines. | 2404 // Check the line number, the command may have deleted lines. |
2402 if (l > curbuf->b_ml.ml_line_count) | 2405 if (l > curbuf->b_ml.ml_line_count) |
2403 break; | 2406 break; |
2404 | 2407 |
2405 lua_pushvalue(L, -1); // function | 2408 lua_pushvalue(L, -1); // function |
2406 luaV_pushline(L, curbuf, l); // current line as arg | 2409 luaV_pushline(L, curbuf, l); // current line as arg |