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