mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
updated for version 7.3.317
Problem: Calling debug.debug() in Lua may cause Vim to hang. Solution: Add a better debug method. (Rob Hoelz, Luis Carvalho)
This commit is contained in:
33
src/if_lua.c
33
src/if_lua.c
@@ -100,6 +100,7 @@ static const char LUAVIM_FREE[] = "luaV_free";
|
|||||||
#define lua_setfield dll_lua_setfield
|
#define lua_setfield dll_lua_setfield
|
||||||
#define lua_rawset dll_lua_rawset
|
#define lua_rawset dll_lua_rawset
|
||||||
#define lua_rawseti dll_lua_rawseti
|
#define lua_rawseti dll_lua_rawseti
|
||||||
|
#define lua_remove dll_lua_remove
|
||||||
#define lua_setmetatable dll_lua_setmetatable
|
#define lua_setmetatable dll_lua_setmetatable
|
||||||
#define lua_call dll_lua_call
|
#define lua_call dll_lua_call
|
||||||
#define lua_pcall dll_lua_pcall
|
#define lua_pcall dll_lua_pcall
|
||||||
@@ -161,6 +162,7 @@ int (*dll_lua_getmetatable) (lua_State *L, int objindex);
|
|||||||
void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
|
void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
|
||||||
void (*dll_lua_rawset) (lua_State *L, int idx);
|
void (*dll_lua_rawset) (lua_State *L, int idx);
|
||||||
void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
|
void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
|
||||||
|
void (*dll_lua_remove) (lua_State *L, int idx);
|
||||||
int (*dll_lua_setmetatable) (lua_State *L, int objindex);
|
int (*dll_lua_setmetatable) (lua_State *L, int objindex);
|
||||||
void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
|
void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
|
||||||
int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
|
int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
|
||||||
@@ -229,6 +231,7 @@ static const luaV_Reg luaV_dll[] = {
|
|||||||
{"lua_setfield", (luaV_function) &dll_lua_setfield},
|
{"lua_setfield", (luaV_function) &dll_lua_setfield},
|
||||||
{"lua_rawset", (luaV_function) &dll_lua_rawset},
|
{"lua_rawset", (luaV_function) &dll_lua_rawset},
|
||||||
{"lua_rawseti", (luaV_function) &dll_lua_rawseti},
|
{"lua_rawseti", (luaV_function) &dll_lua_rawseti},
|
||||||
|
{"lua_remove", (luaV_function) &dll_lua_remove},
|
||||||
{"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
|
{"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
|
||||||
{"lua_call", (luaV_function) &dll_lua_call},
|
{"lua_call", (luaV_function) &dll_lua_call},
|
||||||
{"lua_pcall", (luaV_function) &dll_lua_pcall},
|
{"lua_pcall", (luaV_function) &dll_lua_pcall},
|
||||||
@@ -923,6 +926,31 @@ luaV_print(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
luaV_debug(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_settop(L, 0);
|
||||||
|
lua_getglobal(L, "vim");
|
||||||
|
lua_getfield(L, -1, "eval");
|
||||||
|
lua_remove(L, -2); /* vim.eval at position 1 */
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
const char *input;
|
||||||
|
size_t l;
|
||||||
|
lua_pushvalue(L, 1); /* vim.eval */
|
||||||
|
lua_pushliteral(L, "input('lua_debug> ')");
|
||||||
|
lua_call(L, 1, 1); /* return string */
|
||||||
|
input = lua_tolstring(L, -1, &l);
|
||||||
|
if (l == 0 || strcmp(input, "cont") == 0)
|
||||||
|
return 0;
|
||||||
|
msg_putchar('\n'); /* avoid outputting on input line */
|
||||||
|
if (luaL_loadbuffer(L, input, l, "=(debug command)")
|
||||||
|
|| lua_pcall(L, 0, 0, 0))
|
||||||
|
luaV_emsg(L);
|
||||||
|
lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
luaV_command(lua_State *L)
|
luaV_command(lua_State *L)
|
||||||
{
|
{
|
||||||
@@ -1082,6 +1110,11 @@ luaopen_vim(lua_State *L)
|
|||||||
/* print */
|
/* print */
|
||||||
lua_pushcfunction(L, luaV_print);
|
lua_pushcfunction(L, luaV_print);
|
||||||
lua_setglobal(L, "print");
|
lua_setglobal(L, "print");
|
||||||
|
/* debug.debug */
|
||||||
|
lua_getglobal(L, "debug");
|
||||||
|
lua_pushcfunction(L, luaV_debug);
|
||||||
|
lua_setfield(L, -2, "debug");
|
||||||
|
lua_pop(L, 1);
|
||||||
/* free */
|
/* free */
|
||||||
lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
|
lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
|
||||||
lua_pushcfunction(L, luaV_free);
|
lua_pushcfunction(L, luaV_free);
|
||||||
|
@@ -709,6 +709,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
317,
|
||||||
/**/
|
/**/
|
||||||
316,
|
316,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user