98cd3d4
To: vim_dev@googlegroups.com
98cd3d4
Subject: Patch 7.3.317
98cd3d4
Fcc: outbox
98cd3d4
From: Bram Moolenaar <Bram@moolenaar.net>
98cd3d4
Mime-Version: 1.0
98cd3d4
Content-Type: text/plain; charset=UTF-8
98cd3d4
Content-Transfer-Encoding: 8bit
98cd3d4
------------
98cd3d4
98cd3d4
Patch 7.3.317
98cd3d4
Problem:    Calling debug.debug() in Lua may cause Vim to hang.
98cd3d4
Solution:   Add a better debug method. (Rob Hoelz, Luis Carvalho)
98cd3d4
Files:	    src/if_lua.c
98cd3d4
98cd3d4
98cd3d4
*** ../vim-7.3.316/src/if_lua.c	2011-01-17 19:53:20.000000000 +0100
98cd3d4
--- src/if_lua.c	2011-09-21 17:15:21.000000000 +0200
98cd3d4
***************
98cd3d4
*** 100,105 ****
98cd3d4
--- 100,106 ----
98cd3d4
  #define lua_setfield dll_lua_setfield
98cd3d4
  #define lua_rawset dll_lua_rawset
98cd3d4
  #define lua_rawseti dll_lua_rawseti
98cd3d4
+ #define lua_remove dll_lua_remove
98cd3d4
  #define lua_setmetatable dll_lua_setmetatable
98cd3d4
  #define lua_call dll_lua_call
98cd3d4
  #define lua_pcall dll_lua_pcall
98cd3d4
***************
98cd3d4
*** 161,166 ****
98cd3d4
--- 162,168 ----
98cd3d4
  void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
98cd3d4
  void (*dll_lua_rawset) (lua_State *L, int idx);
98cd3d4
  void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
98cd3d4
+ void (*dll_lua_remove) (lua_State *L, int idx);
98cd3d4
  int (*dll_lua_setmetatable) (lua_State *L, int objindex);
98cd3d4
  void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
98cd3d4
  int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
98cd3d4
***************
98cd3d4
*** 229,234 ****
98cd3d4
--- 231,237 ----
98cd3d4
      {"lua_setfield", (luaV_function) &dll_lua_setfield},
98cd3d4
      {"lua_rawset", (luaV_function) &dll_lua_rawset},
98cd3d4
      {"lua_rawseti", (luaV_function) &dll_lua_rawseti},
98cd3d4
+     {"lua_remove", (luaV_function) &dll_lua_remove},
98cd3d4
      {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
98cd3d4
      {"lua_call", (luaV_function) &dll_lua_call},
98cd3d4
      {"lua_pcall", (luaV_function) &dll_lua_pcall},
98cd3d4
***************
98cd3d4
*** 924,929 ****
98cd3d4
--- 927,957 ----
98cd3d4
  }
98cd3d4
  
98cd3d4
      static int
98cd3d4
+ luaV_debug(lua_State *L)
98cd3d4
+ {
98cd3d4
+     lua_settop(L, 0);
98cd3d4
+     lua_getglobal(L, "vim");
98cd3d4
+     lua_getfield(L, -1, "eval");
98cd3d4
+     lua_remove(L, -2); /* vim.eval at position 1 */
98cd3d4
+     for (;;)
98cd3d4
+     {
98cd3d4
+ 	const char *input;
98cd3d4
+ 	size_t l;
98cd3d4
+ 	lua_pushvalue(L, 1); /* vim.eval */
98cd3d4
+ 	lua_pushliteral(L, "input('lua_debug> ')");
98cd3d4
+ 	lua_call(L, 1, 1); /* return string */
98cd3d4
+ 	input = lua_tolstring(L, -1, &l);
98cd3d4
+ 	if (l == 0 || strcmp(input, "cont") == 0)
98cd3d4
+ 	    return 0;
98cd3d4
+ 	msg_putchar('\n'); /* avoid outputting on input line */
98cd3d4
+ 	if (luaL_loadbuffer(L, input, l, "=(debug command)")
98cd3d4
+ 		|| lua_pcall(L, 0, 0, 0))
98cd3d4
+ 	    luaV_emsg(L);
98cd3d4
+ 	lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */
98cd3d4
+     }
98cd3d4
+ }
98cd3d4
+ 
98cd3d4
+     static int
98cd3d4
  luaV_command(lua_State *L)
98cd3d4
  {
98cd3d4
      do_cmdline_cmd((char_u *) luaL_checkstring(L, 1));
98cd3d4
***************
98cd3d4
*** 1082,1087 ****
98cd3d4
--- 1110,1120 ----
98cd3d4
      /* print */
98cd3d4
      lua_pushcfunction(L, luaV_print);
98cd3d4
      lua_setglobal(L, "print");
98cd3d4
+     /* debug.debug */
98cd3d4
+     lua_getglobal(L, "debug");
98cd3d4
+     lua_pushcfunction(L, luaV_debug);
98cd3d4
+     lua_setfield(L, -2, "debug");
98cd3d4
+     lua_pop(L, 1);
98cd3d4
      /* free */
98cd3d4
      lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
98cd3d4
      lua_pushcfunction(L, luaV_free);
98cd3d4
*** ../vim-7.3.316/src/version.c	2011-09-21 13:40:13.000000000 +0200
98cd3d4
--- src/version.c	2011-09-21 17:14:01.000000000 +0200
98cd3d4
***************
98cd3d4
*** 711,712 ****
98cd3d4
--- 711,714 ----
98cd3d4
  {   /* Add new patch number below this line */
98cd3d4
+ /**/
98cd3d4
+     317,
98cd3d4
  /**/
98cd3d4
98cd3d4
-- 
98cd3d4
Q: What is the difference betwee open-source and commercial software?
98cd3d4
A: If you have a problem with commercial software you can call a phone
98cd3d4
   number and they will tell you it might be solved in a future version.
98cd3d4
   For open-source software there isn't a phone number to call, but you
98cd3d4
   get the solution within a day.
98cd3d4
98cd3d4
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
98cd3d4
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
98cd3d4
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
98cd3d4
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///