Karsten Hopp 9785c1
To: vim_dev@googlegroups.com
Karsten Hopp 9785c1
Subject: Patch 7.3.896
Karsten Hopp 9785c1
Fcc: outbox
Karsten Hopp 9785c1
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 9785c1
Mime-Version: 1.0
Karsten Hopp 9785c1
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 9785c1
Content-Transfer-Encoding: 8bit
Karsten Hopp 9785c1
------------
Karsten Hopp 9785c1
Karsten Hopp 9785c1
Patch 7.3.896
Karsten Hopp 9785c1
Problem:    Memory leaks in Lua interface.
Karsten Hopp 9785c1
Solution:   Fix the leaks, add tests. (Yukihiro Nakadaira)
Karsten Hopp 9785c1
Files:	    src/testdir/test85.in, src/testdir/test85.ok, src/if_lua.c
Karsten Hopp 9785c1
Karsten Hopp 9785c1
Karsten Hopp 9785c1
*** ../vim-7.3.895/src/testdir/test85.in	2012-04-05 16:56:38.000000000 +0200
Karsten Hopp 9785c1
--- src/testdir/test85.in	2013-04-15 13:12:43.000000000 +0200
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 33,38 ****
Karsten Hopp 9785c1
--- 33,81 ----
Karsten Hopp 9785c1
  :let res = "FAILED"
Karsten Hopp 9785c1
  :endif
Karsten Hopp 9785c1
  :call setline(search("^3"), "circular test " . res)
Karsten Hopp 9785c1
+ 
Karsten Hopp 9785c1
+ :let l = []
Karsten Hopp 9785c1
+ :lua l = vim.eval("l")
Karsten Hopp 9785c1
+ :lua l:add(123)
Karsten Hopp 9785c1
+ :lua l:add("abc")
Karsten Hopp 9785c1
+ :lua l:add(vim.eval("[1, 2, 3]"))
Karsten Hopp 9785c1
+ :lua l:add(vim.eval("{'a':1, 'b':2, 'c':3}"))
Karsten Hopp 9785c1
+ :lua l:insert(123)
Karsten Hopp 9785c1
+ :lua l:insert("abc")
Karsten Hopp 9785c1
+ :lua l:insert(vim.eval("[1, 2, 3]"))
Karsten Hopp 9785c1
+ :lua l:insert(vim.eval("{'a':1, 'b':2, 'c':3}"))
Karsten Hopp 9785c1
+ :lua l[0] = l[0]
Karsten Hopp 9785c1
+ :lua l[1] = l[1]
Karsten Hopp 9785c1
+ :lua l[2] = l[2]
Karsten Hopp 9785c1
+ :lua l[3] = l[3]
Karsten Hopp 9785c1
+ :lua l[0] = 123
Karsten Hopp 9785c1
+ :lua l[1] = "abc"
Karsten Hopp 9785c1
+ :lua l[2] = vim.eval("[1, 2, 3]")
Karsten Hopp 9785c1
+ :lua l[3] = vim.eval("{'a':1, 'b':2, 'c':3}")
Karsten Hopp 9785c1
+ :lua l[3] = nil
Karsten Hopp 9785c1
+ :lua l[2] = nil
Karsten Hopp 9785c1
+ :lua l[1] = nil
Karsten Hopp 9785c1
+ :lua l[0] = nil
Karsten Hopp 9785c1
+ :lua l = nil
Karsten Hopp 9785c1
+ :$put =string(l)
Karsten Hopp 9785c1
+ 
Karsten Hopp 9785c1
+ :let d = {}
Karsten Hopp 9785c1
+ :lua d = vim.eval("d")
Karsten Hopp 9785c1
+ :lua d[0] = 123
Karsten Hopp 9785c1
+ :lua d[1] = "abc"
Karsten Hopp 9785c1
+ :lua d[2] = vim.eval("[1, 2, 3]")
Karsten Hopp 9785c1
+ :lua d[3] = vim.eval("{'a':1, 'b':2, 'c':3}")
Karsten Hopp 9785c1
+ :lua d[4] = d[0]
Karsten Hopp 9785c1
+ :lua d[5] = d[1]
Karsten Hopp 9785c1
+ :lua d[6] = d[2]
Karsten Hopp 9785c1
+ :lua d[7] = d[3]
Karsten Hopp 9785c1
+ :lua d[3] = nil
Karsten Hopp 9785c1
+ :lua d[2] = nil
Karsten Hopp 9785c1
+ :lua d[1] = nil
Karsten Hopp 9785c1
+ :lua d[0] = nil
Karsten Hopp 9785c1
+ :lua d = nil
Karsten Hopp 9785c1
+ :$put =string(d)
Karsten Hopp 9785c1
+ 
Karsten Hopp 9785c1
  :?^1?,$w! test.out
Karsten Hopp 9785c1
  :qa!
Karsten Hopp 9785c1
  ENDTEST
Karsten Hopp 9785c1
*** ../vim-7.3.895/src/testdir/test85.ok	2012-04-05 16:56:38.000000000 +0200
Karsten Hopp 9785c1
--- src/testdir/test85.ok	2013-04-15 13:12:47.000000000 +0200
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 3,5 ****
Karsten Hopp 9785c1
--- 3,7 ----
Karsten Hopp 9785c1
  2 line 2
Karsten Hopp 9785c1
  dictionary with list OK
Karsten Hopp 9785c1
  circular test OK
Karsten Hopp 9785c1
+ [123.0, 'abc', [1, 2, 3], {'a': 1, 'b': 2, 'c': 3}]
Karsten Hopp 9785c1
+ {'4': 123.0, '5': 'abc', '6': [1, 2, 3], '7': {'a': 1, 'b': 2, 'c': 3}}
Karsten Hopp 9785c1
*** ../vim-7.3.895/src/if_lua.c	2013-04-12 12:18:43.000000000 +0200
Karsten Hopp 9785c1
--- src/if_lua.c	2013-04-15 13:35:40.000000000 +0200
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 709,716 ****
Karsten Hopp 9785c1
      {
Karsten Hopp 9785c1
  	const char *s = lua_tostring(L, 2);
Karsten Hopp 9785c1
  	if (strncmp(s, "add", 3) == 0
Karsten Hopp 9785c1
! 		|| strncmp(s, "insert", 6) == 0
Karsten Hopp 9785c1
! 		|| strncmp(s, "extend", 6) == 0)
Karsten Hopp 9785c1
  	{
Karsten Hopp 9785c1
  	    lua_getmetatable(L, 1);
Karsten Hopp 9785c1
  	    lua_getfield(L, -1, s);
Karsten Hopp 9785c1
--- 709,715 ----
Karsten Hopp 9785c1
      {
Karsten Hopp 9785c1
  	const char *s = lua_tostring(L, 2);
Karsten Hopp 9785c1
  	if (strncmp(s, "add", 3) == 0
Karsten Hopp 9785c1
! 		|| strncmp(s, "insert", 6) == 0)
Karsten Hopp 9785c1
  	{
Karsten Hopp 9785c1
  	    lua_getmetatable(L, 1);
Karsten Hopp 9785c1
  	    lua_getfield(L, -1, s);
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 745,750 ****
Karsten Hopp 9785c1
--- 744,750 ----
Karsten Hopp 9785c1
  	luaV_totypval(L, 3, &v);
Karsten Hopp 9785c1
  	clear_tv(&li->li_tv);
Karsten Hopp 9785c1
  	copy_tv(&v, &li->li_tv);
Karsten Hopp 9785c1
+ 	clear_tv(&v);
Karsten Hopp 9785c1
      }
Karsten Hopp 9785c1
      return 0;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 754,770 ****
Karsten Hopp 9785c1
  {
Karsten Hopp 9785c1
      luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST);
Karsten Hopp 9785c1
      list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis);
Karsten Hopp 9785c1
!     listitem_T *li;
Karsten Hopp 9785c1
      if (l->lv_lock)
Karsten Hopp 9785c1
  	luaL_error(L, "list is locked");
Karsten Hopp 9785c1
!     li = listitem_alloc();
Karsten Hopp 9785c1
!     if (li != NULL)
Karsten Hopp 9785c1
      {
Karsten Hopp 9785c1
! 	typval_T v;
Karsten Hopp 9785c1
! 	lua_settop(L, 2);
Karsten Hopp 9785c1
! 	luaV_totypval(L, 2, &v);
Karsten Hopp 9785c1
! 	list_append_tv(l, &v);
Karsten Hopp 9785c1
      }
Karsten Hopp 9785c1
      lua_settop(L, 1);
Karsten Hopp 9785c1
      return 1;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
--- 754,770 ----
Karsten Hopp 9785c1
  {
Karsten Hopp 9785c1
      luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST);
Karsten Hopp 9785c1
      list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis);
Karsten Hopp 9785c1
!     typval_T v;
Karsten Hopp 9785c1
      if (l->lv_lock)
Karsten Hopp 9785c1
  	luaL_error(L, "list is locked");
Karsten Hopp 9785c1
!     lua_settop(L, 2);
Karsten Hopp 9785c1
!     luaV_totypval(L, 2, &v);
Karsten Hopp 9785c1
!     if (list_append_tv(l, &v) == FAIL)
Karsten Hopp 9785c1
      {
Karsten Hopp 9785c1
! 	clear_tv(&v);
Karsten Hopp 9785c1
! 	luaL_error(L, "Failed to add item to list");
Karsten Hopp 9785c1
      }
Karsten Hopp 9785c1
+     clear_tv(&v);
Karsten Hopp 9785c1
      lua_settop(L, 1);
Karsten Hopp 9785c1
      return 1;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 787,793 ****
Karsten Hopp 9785c1
      }
Karsten Hopp 9785c1
      lua_settop(L, 2);
Karsten Hopp 9785c1
      luaV_totypval(L, 2, &v);
Karsten Hopp 9785c1
!     list_insert_tv(l, &v, li);
Karsten Hopp 9785c1
      lua_settop(L, 1);
Karsten Hopp 9785c1
      return 1;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
--- 787,798 ----
Karsten Hopp 9785c1
      }
Karsten Hopp 9785c1
      lua_settop(L, 2);
Karsten Hopp 9785c1
      luaV_totypval(L, 2, &v);
Karsten Hopp 9785c1
!     if (list_insert_tv(l, &v, li) == FAIL)
Karsten Hopp 9785c1
!     {
Karsten Hopp 9785c1
! 	clear_tv(&v);
Karsten Hopp 9785c1
! 	luaL_error(L, "Failed to add item to list");
Karsten Hopp 9785c1
!     }
Karsten Hopp 9785c1
!     clear_tv(&v);
Karsten Hopp 9785c1
      lua_settop(L, 1);
Karsten Hopp 9785c1
      return 1;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 908,913 ****
Karsten Hopp 9785c1
--- 913,919 ----
Karsten Hopp 9785c1
  	typval_T v;
Karsten Hopp 9785c1
  	luaV_totypval(L, 3, &v);
Karsten Hopp 9785c1
  	copy_tv(&v, &di->di_tv);
Karsten Hopp 9785c1
+ 	clear_tv(&v);
Karsten Hopp 9785c1
      }
Karsten Hopp 9785c1
      return 0;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 1323,1328 ****
Karsten Hopp 9785c1
--- 1329,1335 ----
Karsten Hopp 9785c1
      typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL);
Karsten Hopp 9785c1
      if (tv == NULL) luaL_error(L, "invalid expression");
Karsten Hopp 9785c1
      luaV_pushtypval(L, tv);
Karsten Hopp 9785c1
+     free_tv(tv);
Karsten Hopp 9785c1
      return 1;
Karsten Hopp 9785c1
  }
Karsten Hopp 9785c1
  
Karsten Hopp 9785c1
*** ../vim-7.3.895/src/version.c	2013-04-15 13:06:15.000000000 +0200
Karsten Hopp 9785c1
--- src/version.c	2013-04-15 13:48:21.000000000 +0200
Karsten Hopp 9785c1
***************
Karsten Hopp 9785c1
*** 730,731 ****
Karsten Hopp 9785c1
--- 730,733 ----
Karsten Hopp 9785c1
  {   /* Add new patch number below this line */
Karsten Hopp 9785c1
+ /**/
Karsten Hopp 9785c1
+     896,
Karsten Hopp 9785c1
  /**/
Karsten Hopp 9785c1
Karsten Hopp 9785c1
-- 
Karsten Hopp 9785c1
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 9785c1
172. You join listservers just for the extra e-mail.
Karsten Hopp 9785c1
Karsten Hopp 9785c1
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 9785c1
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 9785c1
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 9785c1
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///