diff --git a/include/lapi.h b/include/lapi.h index 6d36dee..8e16ad5 100644 --- a/include/lapi.h +++ b/include/lapi.h @@ -1,5 +1,5 @@ /* -** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ +** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ diff --git a/include/lauxlib.h b/include/lauxlib.h index e8724f3..86c29c7 100644 --- a/include/lauxlib.h +++ b/include/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp $ +** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -285,30 +285,10 @@ LUALIB_API int (luaL_newmetatable)(lua_State *L, const char *tname); LUALIB_API void (luaL_setmetatable)(lua_State *L, const char *tname); LUALIB_API void *(luaL_testudata)(lua_State *L, int ud, const char *tname); LUALIB_API void *(luaL_checkudata)(lua_State *L, int ud, const char *tname); -#if 0 -LUALIB_API int raviL_newmetatable(lua_State *L, const void *meta_key, - const char *tname); - -/* meta_key is the key assigned to the meta table of the userdata */ -LUALIB_API void raviL_getmetatable(lua_State *L, const void *meta_key); - -/* - arg_index is the position of userdata argument on the stack - meta_key is the key assigned to the meta table of the userdata -*/ -LUALIB_API void *raviL_testudata(lua_State *L, int arg_index, const void *meta_key); - -/* - arg_index is the position of userdata argument on the stack - meta_key is the key assigned to the meta table of the userdata -*/ -LUALIB_API void *raviL_checkudata(lua_State *L, int arg_index, const void *meta_key); -#else #define raviL_newmetatable(L, meta_key, tname) luaL_newmetatable(L, meta_key) #define raviL_getmetatable(L, meta_key) luaL_getmetatable(L, meta_key) #define raviL_testudata(L, arg_index, meta_key) luaL_testudata(L, arg_index, meta_key) #define raviL_checkudata(L, arg_index, meta_key) luaL_checkudata(L, arg_index, meta_key) -#endif LUALIB_API int (raviL_build_ast_from_buffer) (lua_State *L, const char *buff, size_t size, const char *name, const char *mode); diff --git a/include/lcode.h b/include/lcode.h index 0513b3d..edb28d9 100644 --- a/include/lcode.h +++ b/include/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $ +** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ diff --git a/include/lctype.h b/include/lctype.h index 99c7d12..b09b21a 100644 --- a/include/lctype.h +++ b/include/lctype.h @@ -1,5 +1,5 @@ /* -** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ +** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $ ** 'ctype' functions for Lua ** See Copyright Notice in lua.h */ diff --git a/include/ldebug.h b/include/ldebug.h index 0e31546..8cea0ee 100644 --- a/include/ldebug.h +++ b/include/ldebug.h @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $ +** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 roberto Exp $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ diff --git a/include/ldo.h b/include/ldo.h index 1af1e74..b8a3d0f 100644 --- a/include/ldo.h +++ b/include/ldo.h @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $ +** $Id: ldo.h,v 2.29.1.1 2017/04/19 17:20:42 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ diff --git a/include/lfunc.h b/include/lfunc.h index 8c5365a..18d9bba 100644 --- a/include/lfunc.h +++ b/include/lfunc.h @@ -1,5 +1,5 @@ /* -** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ +** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ diff --git a/include/lgc.h b/include/lgc.h index aed3e18..425cd7c 100644 --- a/include/lgc.h +++ b/include/lgc.h @@ -1,5 +1,5 @@ /* -** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $ +** $Id: lgc.h,v 2.91.1.1 2017/04/19 17:39:34 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ diff --git a/include/llex.h b/include/llex.h index 05118f4..baac67b 100644 --- a/include/llex.h +++ b/include/llex.h @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $ +** $Id: llex.h,v 1.79.1.1 2017/04/19 17:20:42 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ diff --git a/include/llimits.h b/include/llimits.h index 550638a..6836ab1 100644 --- a/include/llimits.h +++ b/include/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $ +** $Id: llimits.h,v 1.141.1.1 2017/04/19 17:20:42 roberto Exp $ ** Limits, basic types, and some other 'installation-dependent' definitions ** See Copyright Notice in lua.h */ diff --git a/include/lmem.h b/include/lmem.h index 30f4848..357b1e4 100644 --- a/include/lmem.h +++ b/include/lmem.h @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ +** $Id: lmem.h,v 1.43.1.1 2017/04/19 17:20:42 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ diff --git a/include/lobject.h b/include/lobject.h index 095571b..2925d69 100644 --- a/include/lobject.h +++ b/include/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.117 2016/08/01 19:51:24 roberto Exp $ +** $Id: lobject.h,v 2.117.1.1 2017/04/19 17:39:34 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ diff --git a/include/lopcodes.h b/include/lopcodes.h index 2397523..2fbcdaf 100644 --- a/include/lopcodes.h +++ b/include/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.149 2016/07/19 17:12:21 roberto Exp $ +** $Id: lopcodes.h,v 1.149.1.1 2017/04/19 17:20:42 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ diff --git a/include/lparser.h b/include/lparser.h index afcebff..19696af 100644 --- a/include/lparser.h +++ b/include/lparser.h @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $ +** $Id: lparser.h,v 1.76.1.1 2017/04/19 17:20:42 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ diff --git a/include/lprefix.h b/include/lprefix.h index 02daa83..9a749a3 100644 --- a/include/lprefix.h +++ b/include/lprefix.h @@ -1,5 +1,5 @@ /* -** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ +** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $ ** Definitions for Lua code that must come before any other header file ** See Copyright Notice in lua.h */ diff --git a/include/lstate.h b/include/lstate.h index d55ca2f..7219d34 100644 --- a/include/lstate.h +++ b/include/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.133 2016/12/22 13:08:50 roberto Exp $ +** $Id: lstate.h,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ diff --git a/include/lstring.h b/include/lstring.h index 27efd20..d612abd 100644 --- a/include/lstring.h +++ b/include/lstring.h @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $ +** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 roberto Exp $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ diff --git a/include/ltable.h b/include/ltable.h index ca3b17e..31dc5cf 100644 --- a/include/ltable.h +++ b/include/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $ +** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ diff --git a/include/ltm.h b/include/ltm.h index 25c6e4c..4887a54 100644 --- a/include/ltm.h +++ b/include/ltm.h @@ -1,5 +1,5 @@ /* -** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $ +** $Id: ltm.h,v 2.22.1.1 2017/04/19 17:20:42 roberto Exp $ ** Tag methods ** See Copyright Notice in lua.h */ diff --git a/include/lua.h b/include/lua.h index 9429948..bd3eaa7 100644 --- a/include/lua.h +++ b/include/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.332 2016/12/22 15:51:20 roberto Exp $ +** $Id: lua.h,v 1.332.1.2 2018/06/13 16:58:17 roberto Exp $ ** Lua - A Scripting Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -19,11 +19,11 @@ #define LUA_VERSION_MAJOR "5" #define LUA_VERSION_MINOR "3" #define LUA_VERSION_NUM 503 -#define LUA_VERSION_RELEASE "4" +#define LUA_VERSION_RELEASE "5" #define LUA_VERSION "Ravi " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE -#define LUA_COPYRIGHT LUA_RELEASE "\nCopyright (C) 1994-2017 Lua.org, PUC-Rio\nPortions Copyright (C) 2015-2017 Dibyendu Majumdar" +#define LUA_COPYRIGHT LUA_RELEASE "\nCopyright (C) 1994-2018 Lua.org, PUC-Rio\nPortions Copyright (C) 2015-2018 Dibyendu Majumdar" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes, Dibyendu Majumdar" diff --git a/include/luaconf.h b/include/luaconf.h index bde5642..631713b 100644 --- a/include/luaconf.h +++ b/include/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $ +** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -621,6 +621,13 @@ #endif +/* +@@ lua_pointer2str converts a pointer to a readable string in a +** non-specified way. +*/ +#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p) + + /* @@ lua_number2strx converts a float to an hexadecimal numeric string. ** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. diff --git a/include/lualib.h b/include/lualib.h index 9cac595..11ec110 100644 --- a/include/lualib.h +++ b/include/lualib.h @@ -1,5 +1,5 @@ /* -** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $ +** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ ** Lua standard libraries ** See Copyright Notice in lua.h */ diff --git a/include/lundump.h b/include/lundump.h index aa5cc82..ce492d6 100644 --- a/include/lundump.h +++ b/include/lundump.h @@ -1,5 +1,5 @@ /* -** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ +** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/include/lvm.h b/include/lvm.h index 0254298..8357de3 100644 --- a/include/lvm.h +++ b/include/lvm.h @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 roberto Exp $ +** $Id: lvm.h,v 2.41.1.1 2017/04/19 17:20:42 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ diff --git a/include/lzio.h b/include/lzio.h index e7b6f34..d897870 100644 --- a/include/lzio.h +++ b/include/lzio.h @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ +** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $ ** Buffered streams ** See Copyright Notice in lua.h */ diff --git a/src/lapi.c b/src/lapi.c index d9233cc..dec54a3 100644 --- a/src/lapi.c +++ b/src/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $ +** $Id: lapi.c,v 2.259.1.2 2017/12/06 18:35:12 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -580,6 +580,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { lua_lock(L); if (n == 0) { setfvalue(L->top, fn); + api_incr_top(L); } else { CClosure *cl; @@ -595,9 +596,9 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { /* does not need barrier because closure is white */ } setclCvalue(L, L->top, cl); + api_incr_top(L); + luaC_checkGC(L); } - api_incr_top(L); - luaC_checkGC(L); lua_unlock(L); } @@ -681,11 +682,12 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { if (ttisLtable(t) || !ttistable(t)) { if (luaV_fastgeti(L, t, n, slot)) { setobj2s(L, L->top, slot); + api_incr_top(L); } else { - TValue aux; - setivalue(&aux, n); - luaV_finishget(L, t, &aux, L->top, slot); + setivalue(L->top, n); + api_incr_top(L); + luaV_finishget(L, t, L->top - 1, L->top - 1, slot); } } else { @@ -702,8 +704,8 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { setnilvalue(L->top); } } + api_incr_top(L); } - api_incr_top(L); lua_unlock(L); return ttnov(L->top - 1); } @@ -716,7 +718,7 @@ LUA_API int lua_rawget(lua_State *L, int idx) { api_check(L, ttistable(t), "table expected"); h = hvalue(t); if (ttisLtable(t)) { - setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + setobj2s(L, L->top - 1, luaH_get(h, L->top - 1)); } else if (ttisfarray(t)) { TValue *key = L->top - 1; @@ -759,7 +761,7 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { api_check(L, ttistable(t), "table expected"); h = hvalue(t); if (ttisLtable(t)) { - setobj2s(L, L->top, luaH_getint(hvalue(t), n)); + setobj2s(L, L->top, luaH_getint(h, n)); } else if (ttisfarray(t)) { if (n <= raviH_getn(h)) { raviH_get_float_inline(L, h, n, L->top); } @@ -782,13 +784,11 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { StkId t; TValue k; - Table *h; lua_lock(L); t = index2addr(L, idx); api_check(L, ttisLtable(t), "Lua table expected"); - h = hvalue(t); setpvalue(&k, cast(void *, p)); - setobj2s(L, L->top, luaH_get(h, &k)); + setobj2s(L, L->top, luaH_get(hvalue(t), &k)); api_incr_top(L); lua_unlock(L); return ttnov(L->top - 1); @@ -1019,11 +1019,13 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { if (ttisLtable(t) || !ttistable(t)) { if (luaV_fastgeti(L, t, n, slot)) { luaV_finishfastset(L, t, slot, L->top - 1); + L->top--; /* pop value */ } else { - TValue aux; - setivalue(&aux, n); - luaV_finishset(L, t, &aux, L->top - 1, slot); + setivalue(L->top, n); + api_incr_top(L); + luaV_finishset(L, t, L->top - 1, L->top - 2, slot); + L->top -= 2; /* pop value and key */ } } else { @@ -1051,8 +1053,8 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { luaG_runerror(L, "value cannot be converted to integer"); } } + L->top--; /* pop value */ } - L->top--; /* pop value */ lua_unlock(L); } @@ -1060,19 +1062,18 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { LUA_API void lua_rawset (lua_State *L, int idx) { StkId o; TValue *slot; - Table *t; lua_lock(L); api_checknelems(L, 2); o = index2addr(L, idx); api_check(L, ttistable(o), "table expected"); - t = hvalue(o); if (ttisLtable(o)) { - slot = luaH_set(L, t, L->top - 2); + slot = luaH_set(L, hvalue(o), L->top - 2); setobj2t(L, slot, L->top - 1); - invalidateTMcache(t); - luaC_barrierback(L, t, L->top - 1); + invalidateTMcache(hvalue(o)); + luaC_barrierback(L, hvalue(o), L->top - 1); } else if (ttisfarray(o)) { + Table *t = hvalue(o); TValue *key = L->top - 2; TValue *val = L->top - 1; if (!ttisinteger(key)) luaG_typeerror(L, key, "index"); @@ -1092,6 +1093,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { } } else { + Table *t = hvalue(o); TValue *key = L->top - 2; TValue *val = L->top - 1; if (!ttisinteger(key)) luaG_typeerror(L, key, "index"); @@ -1114,17 +1116,16 @@ LUA_API void lua_rawset (lua_State *L, int idx) { LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { StkId o; - Table *t; lua_lock(L); api_checknelems(L, 1); o = index2addr(L, idx); api_check(L, ttistable(o), "table expected"); - t = hvalue(o); if (ttisLtable(o)) { - luaH_setint(L, t, n, L->top - 1); - luaC_barrierback(L, t, L->top - 1); + luaH_setint(L, hvalue(o), n, L->top - 1); + luaC_barrierback(L, hvalue(o), L->top - 1); } else if (ttisfarray(o)) { + Table *t = hvalue(o); TValue *val = L->top - 1; if (ttisfloat(val)) { raviH_set_float_inline(L, t, n, fltvalue(val)); } else if (ttisinteger(val)) { @@ -1138,6 +1139,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { } } else { + Table *t = hvalue(o); TValue *val = L->top - 1; if (ttisinteger(val)) { raviH_set_int_inline(L, t, n, ivalue(val)); } else { @@ -1154,17 +1156,15 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { StkId o; - Table *t; TValue k, *slot; lua_lock(L); api_checknelems(L, 1); o = index2addr(L, idx); api_check(L, ttisLtable(o), "table expected"); - t = hvalue(o); setpvalue(&k, cast(void *, p)); - slot = luaH_set(L, t, &k); + slot = luaH_set(L, hvalue(o), &k); setobj2t(L, slot, L->top - 1); - luaC_barrierback(L, t, L->top - 1); + luaC_barrierback(L, hvalue(o), L->top - 1); L->top--; lua_unlock(L); } @@ -1341,6 +1341,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, return status; } + LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { int status; TValue *o; diff --git a/src/lauxlib.c b/src/lauxlib.c index 6dd1f11..d71bee6 100644 --- a/src/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp $ +** $Id: lauxlib.c,v 1.289.1.1 2017/04/19 17:20:42 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -760,6 +760,7 @@ LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, return lua_load(L, getS, &ls, name, mode); } + LUALIB_API int luaL_loadstring (lua_State *L, const char *s) { return luaL_loadbuffer(L, s, strlen(s), s); } @@ -1080,66 +1081,3 @@ LUALIB_API int (raviL_dumpast) (lua_State *L) { return 0; } -#if 0 -/* The normal Lua metatable functions in C use string - keys - these are expensive as the key needs to be - converted to Lua string, hash code computed etc. - Following implementations are taken from a post in - Lua mailing list (http://lua-users.org/lists/lua-l/2010-11/msg00151.html) - They use lightuserdata instead of strings to speed - things up - meta_key is the key assigned to the meta - table of the userdata */ -LUALIB_API int raviL_newmetatable(lua_State *L, const void *meta_key, const char *tname) { - lua_pushlightuserdata(L, (void *)meta_key); - lua_rawget(L, LUA_REGISTRYINDEX); - if (!lua_isnil(L, -1)) { /* name already in use? */ - return 0; /* leave previous value on top, but return 0 */ - } - lua_pop(L, 1); /* pop the nil value */ - lua_createtable(L, 0, 2); /* create metatable */ - lua_pushstring(L, tname); - lua_setfield(L, -2, "__name"); /* metatable.__name = tname */ - lua_pushlightuserdata(L, (void *)meta_key); /* meta_key */ - lua_pushvalue(L, -2); /* table */ - lua_rawset(L, LUA_REGISTRYINDEX); /* assign table to meta_key in the registry */ - return 1; -} - -/* meta_key is the key assigned to the meta table of the userdata */ -LUALIB_API void raviL_getmetatable(lua_State *L, const void *meta_key) { - lua_pushlightuserdata(L, (void *)meta_key); /* meta_key */ - lua_rawget(L, LUA_REGISTRYINDEX); /* obtain the value associated with - meta_key from registry */ -} - -/* arg_index is the position of userdata argument on the stack - meta_key is the key assigned to the meta table of the userdata */ -LUALIB_API void *raviL_testudata(lua_State *L, int arg_index, - const void *meta_key) { - void *p = lua_touserdata(L, arg_index); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, arg_index)) { /* does it have a metatable? */ - lua_pushlightuserdata(L, (void *)meta_key); /* meta_key */ - lua_rawget( - L, - LUA_REGISTRYINDEX); /* get correct metatable associated with meta_key */ - if (!lua_rawequal(L, -1, -2)) /* compare: does it have the correct mt? */ - p = NULL; - lua_pop(L, 2); /* remove both metatables */ - } - } - return p; /* to avoid warnings */ -} - -/* arg_index is the position of userdata argument on the stack - meta_key is the key assigned to the meta table of the userdata */ -LUALIB_API void *raviL_checkudata(lua_State *L, int arg_index, - const void *meta_key) { - void *p = raviL_testudata(L, arg_index, meta_key); - if (p == NULL) - luaL_argerror(L, arg_index, meta_key); - return p; -} - -#endif diff --git a/src/lbaselib.c b/src/lbaselib.c index 9d6a36a..a5e9f4a 100644 --- a/src/lbaselib.c +++ b/src/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.314 2016/09/05 19:06:34 roberto Exp $ +** $Id: lbaselib.c,v 1.314.1.1 2017/04/19 17:39:34 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -355,7 +355,6 @@ static int luaB_load (lua_State *L) { return load_aux(L, status, env); } - /* }====================================================== */ diff --git a/src/lbitlib.c b/src/lbitlib.c index 1cb1d5b..4786c0d 100644 --- a/src/lbitlib.c +++ b/src/lbitlib.c @@ -1,5 +1,5 @@ /* -** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $ +** $Id: lbitlib.c,v 1.30.1.1 2017/04/19 17:20:42 roberto Exp $ ** Standard library for bitwise operations ** See Copyright Notice in lua.h */ diff --git a/src/lcode.c b/src/lcode.c index a20edbe..35b9faf 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp $ +** $Id: lcode.c,v 2.112.1.1 2017/04/19 17:20:42 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ diff --git a/src/lcorolib.c b/src/lcorolib.c index 2303429..0b17af9 100644 --- a/src/lcorolib.c +++ b/src/lcorolib.c @@ -1,5 +1,5 @@ /* -** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $ +** $Id: lcorolib.c,v 1.10.1.1 2017/04/19 17:20:42 roberto Exp $ ** Coroutine Library ** See Copyright Notice in lua.h */ diff --git a/src/lctype.c b/src/lctype.c index ae9367e..f8ad7a2 100644 --- a/src/lctype.c +++ b/src/lctype.c @@ -1,5 +1,5 @@ /* -** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ +** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 roberto Exp $ ** 'ctype' functions for Lua ** See Copyright Notice in lua.h */ diff --git a/src/ldblib.c b/src/ldblib.c index 5fa4ecd..640ebf2 100644 --- a/src/ldblib.c +++ b/src/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $ +** $Id: ldblib.c,v 1.151.1.1 2017/04/19 17:20:42 roberto Exp $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ diff --git a/src/ldebug.c b/src/ldebug.c index 6aa7469..281da9a 100644 --- a/src/ldebug.c +++ b/src/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.121 2016/10/19 12:32:10 roberto Exp $ +** $Id: ldebug.c,v 2.121.1.2 2017/07/10 17:21:50 roberto Exp $ ** Debug Interface ** See Copyright Notice in lua.h */ diff --git a/src/ldo.c b/src/ldo.c index c13c133..1c5147c 100644 --- a/src/ldo.c +++ b/src/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.157 2016/12/13 15:52:21 roberto Exp $ +** $Id: ldo.c,v 2.157.1.1 2017/04/19 17:20:42 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ diff --git a/src/ldump.c b/src/ldump.c index 87d3f8b..e0a825c 100644 --- a/src/ldump.c +++ b/src/ldump.c @@ -1,5 +1,5 @@ /* -** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $ +** $Id: ldump.c,v 2.37.1.1 2017/04/19 17:20:42 roberto Exp $ ** save precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/src/lgc.c b/src/lgc.c index b4c56bf..9e74570 100644 --- a/src/lgc.c +++ b/src/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.215 2016/12/22 13:08:50 roberto Exp $ +** $Id: lgc.c,v 2.215.1.2 2017/08/31 16:15:27 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -9,6 +9,7 @@ #include "lprefix.h" + #include #include "lua.h" @@ -24,73 +25,74 @@ #include "ltable.h" #include "ltm.h" + /* ** internal state for collector while inside the atomic phase. The ** collector should never be in this state while running regular code. */ -#define GCSinsideatomic (GCSpause + 1) +#define GCSinsideatomic (GCSpause + 1) /* ** cost of sweeping one element (the size of a small object divided ** by some adjust for the sweep speed) */ -#define GCSWEEPCOST ((sizeof(TString) + 4) / 4) +#define GCSWEEPCOST ((sizeof(TString) + 4) / 4) /* maximum number of elements to sweep in each single step */ -#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4)) +#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4)) /* cost of calling one finalizer */ -#define GCFINALIZECOST GCSWEEPCOST +#define GCFINALIZECOST GCSWEEPCOST + /* ** macro to adjust 'stepmul': 'stepmul' is actually used like ** 'stepmul / STEPMULADJ' (value chosen by tests) */ -#define STEPMULADJ 200 +#define STEPMULADJ 200 + /* ** macro to adjust 'pause': 'pause' is actually used like ** 'pause / PAUSEADJ' (value chosen by tests) */ -#define PAUSEADJ 100 +#define PAUSEADJ 100 + /* ** 'makewhite' erases all color bits then sets only the current white ** bit */ -#define maskcolors (~(bitmask(BLACKBIT) | WHITEBITS)) -#define makewhite(g, x) (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g))) +#define maskcolors (~(bitmask(BLACKBIT) | WHITEBITS)) +#define makewhite(g,x) \ + (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g))) -#define white2gray(x) resetbits(x->marked, WHITEBITS) -#define black2gray(x) resetbit(x->marked, BLACKBIT) +#define white2gray(x) resetbits(x->marked, WHITEBITS) +#define black2gray(x) resetbit(x->marked, BLACKBIT) -#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) -#define checkdeadkey(n) lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n))) +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) -#define checkconsistency(obj) lua_longassert(!iscollectable(obj) || righttt(obj)) +#define checkdeadkey(n) lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n))) -#define markvalue(g, o) \ - { \ - checkconsistency(o); \ - if (valiswhite(o)) reallymarkobject(g, gcvalue(o)); \ - } -#define markobject(g, t) \ - { \ - if (iswhite(t)) reallymarkobject(g, obj2gco(t)); \ - } +#define checkconsistency(obj) \ + lua_longassert(!iscollectable(obj) || righttt(obj)) + + +#define markvalue(g,o) { checkconsistency(o); \ + if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(t)) reallymarkobject(g, obj2gco(t)); } /* ** mark an object that can be NULL (either because it is really optional, ** or it was stripped as debug info, or inside an uncompleted structure) */ -#define markobjectN(g, t) \ - { \ - if (t) markobject(g, t); \ - } +#define markobjectN(g,t) { if (t) markobject(g,t); } + +static void reallymarkobject (global_State *g, GCObject *o); -static void reallymarkobject(global_State *g, GCObject *o); /* ** {====================================================== @@ -98,15 +100,18 @@ static void reallymarkobject(global_State *g, GCObject *o); ** ======================================================= */ + /* ** one after last element in a hash array */ -#define gnodelast(h) gnode(h, cast(size_t, sizenode(h))) +#define gnodelast(h) gnode(h, cast(size_t, sizenode(h))) + /* ** link collectable object 'o' into list pointed by 'p' */ -#define linkgclist(o, p) ((o)->gclist = (p), (p) = obj2gco(o)) +#define linkgclist(o,p) ((o)->gclist = (p), (p) = obj2gco(o)) + /* ** If key is not marked, mark its entry as dead. This allows key to be @@ -117,11 +122,13 @@ static void reallymarkobject(global_State *g, GCObject *o); ** associated nil value is enough to signal that the entry is logically ** empty. */ -static void removeentry(Node *n) { +static void removeentry (Node *n) { lua_assert(ttisnil(gval(n))); - if (valiswhite(gkey(n))) setdeadvalue(wgkey(n)); /* unused and unmarked key; remove it */ + if (valiswhite(gkey(n))) + setdeadvalue(wgkey(n)); /* unused and unmarked key; remove it */ } + /* ** tells whether a key or value can be cleared from a weak ** table. Non-collectable objects are never removed from weak @@ -129,15 +136,13 @@ static void removeentry(Node *n) { ** other objects: if really collected, cannot keep them; for objects ** being finalized, keep them in keys, but not in values */ -static int iscleared(global_State *g, const TValue *o) { - if (!iscollectable(o)) - return 0; +static int iscleared (global_State *g, const TValue *o) { + if (!iscollectable(o)) return 0; else if (ttisstring(o)) { - markobject(g, tsvalue(o)); /* strings are 'values', so are never weak */ + markobject(g, tsvalue(o)); /* strings are 'values', so are never weak */ return 0; } - else - return iswhite(gcvalue(o)); + else return iswhite(gcvalue(o)); } /* @@ -234,10 +239,10 @@ void luaC_barrier_(lua_State *L, GCObject *o, GCObject *v) { ** table if black must be turned to gray as black objects cannot point ** to white objects. */ -void luaC_barrierback_(lua_State *L, Table *t) { +void luaC_barrierback_ (lua_State *L, Table *t) { global_State *g = G(L); lua_assert(isblack(t) && !isdead(g, t)); - black2gray(t); /* make table gray (again) */ + black2gray(t); /* make table gray (again) */ linkgclist(t, g->grayagain); } @@ -247,31 +252,34 @@ void luaC_barrierback_(lua_State *L, Table *t) { ** closures pointing to it. So, we assume that the object being assigned ** must be marked. */ -void luaC_upvalbarrier_(lua_State *L, UpVal *uv) { +void luaC_upvalbarrier_ (lua_State *L, UpVal *uv) { global_State *g = G(L); GCObject *o = gcvalue(uv->v); - lua_assert(!upisopen(uv)); /* ensured by macro luaC_upvalbarrier */ - if (keepinvariant(g)) markobject(g, o); + lua_assert(!upisopen(uv)); /* ensured by macro luaC_upvalbarrier */ + if (keepinvariant(g)) + markobject(g, o); } -void luaC_fix(lua_State *L, GCObject *o) { + +void luaC_fix (lua_State *L, GCObject *o) { global_State *g = G(L); - lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */ - white2gray(o); /* they will be gray forever */ - g->allgc = o->next; /* remove object from 'allgc' list */ - o->next = g->fixedgc; /* link it to 'fixedgc' list */ + lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */ + white2gray(o); /* they will be gray forever */ + g->allgc = o->next; /* remove object from 'allgc' list */ + o->next = g->fixedgc; /* link it to 'fixedgc' list */ g->fixedgc = o; } + /* ** create a new collectable object (with given type and size) and link ** it to 'allgc' list. */ -GCObject *luaC_newobj(lua_State *L, int tt, size_t sz) { +GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { global_State *g = G(L); GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz)); o->marked = luaC_white(g); - lua_assert(tt <= 127); /* Must fit in a byte */ + lua_assert(tt <= 127); /* RAVI: Must fit in a byte */ o->tt = tt; o->next = g->allgc; g->allgc = o; @@ -280,12 +288,15 @@ GCObject *luaC_newobj(lua_State *L, int tt, size_t sz) { /* }====================================================== */ + + /* ** {====================================================== ** Mark functions ** ======================================================= */ + /* ** mark an object. Userdata, strings, and closed upvalues are visited ** and turned black here. Other objects (functions, tables, threads, protos) @@ -293,8 +304,8 @@ GCObject *luaC_newobj(lua_State *L, int tt, size_t sz) { ** to appropriate list to be visited (and turned black) later. (Open ** upvalues are already linked in 'headuv' list.) */ -static void reallymarkobject(global_State *g, GCObject *o) { -reentry: +static void reallymarkobject (global_State *g, GCObject *o) { + reentry: white2gray(o); switch (o->tt) { case LUA_TSHRSTR: { @@ -309,11 +320,11 @@ reentry: } case LUA_TUSERDATA: { TValue uvalue; - markobjectN(g, gco2u(o)->metatable); /* mark its metatable */ + markobjectN(g, gco2u(o)->metatable); /* mark its metatable */ gray2black(o); g->GCmemtrav += sizeudata(gco2u(o)); getuservalue(g->mainthread, gco2u(o), &uvalue); - if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ + if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ o = gcvalue(&uvalue); goto reentry; } @@ -327,6 +338,7 @@ reentry: linkgclist(gco2ccl(o), g->gray); break; } + /* RAVI changes */ case RAVI_TIARRAY: case RAVI_TFARRAY: case LUA_TTABLE: { @@ -345,42 +357,47 @@ reentry: } } + /* ** mark metamethods for basic types */ -static void markmt(global_State *g) { +static void markmt (global_State *g) { int i; - for (i = 0; i < LUA_NUMTAGS; i++) markobjectN(g, g->mt[i]); + for (i=0; i < LUA_NUMTAGS; i++) + markobjectN(g, g->mt[i]); } + /* ** mark all objects in list of being-finalized */ -static void markbeingfnz(global_State *g) { +static void markbeingfnz (global_State *g) { GCObject *o; - for (o = g->tobefnz; o != NULL; o = o->next) markobject(g, o); + for (o = g->tobefnz; o != NULL; o = o->next) + markobject(g, o); } + /* ** Mark all values stored in marked open upvalues from non-marked threads. ** (Values from marked threads were already marked when traversing the ** thread.) Remove from the list threads that no longer have upvalues and ** not-marked threads. */ -static void remarkupvals(global_State *g) { +static void remarkupvals (global_State *g) { lua_State *thread; lua_State **p = &g->twups; while ((thread = *p) != NULL) { - lua_assert(!isblack(thread)); /* threads are never black */ + lua_assert(!isblack(thread)); /* threads are never black */ if (isgray(thread) && thread->openupval != NULL) - p = &thread->twups; /* keep marked thread with upvalues in the list */ - else { /* thread is not marked or without upvalues */ + p = &thread->twups; /* keep marked thread with upvalues in the list */ + else { /* thread is not marked or without upvalues */ UpVal *uv; - *p = thread->twups; /* remove thread from the list */ - thread->twups = thread; /* mark that it is out of list */ + *p = thread->twups; /* remove thread from the list */ + thread->twups = thread; /* mark that it is out of list */ for (uv = thread->openupval; uv != NULL; uv = uv->u.open.next) { if (uv->u.open.touched) { - markvalue(g, uv->v); /* remark upvalue's value */ + markvalue(g, uv->v); /* remark upvalue's value */ uv->u.open.touched = 0; } } @@ -388,20 +405,22 @@ static void remarkupvals(global_State *g) { } } + /* ** mark root set and reset all gray lists, to start a new collection */ -static void restartcollection(global_State *g) { +static void restartcollection (global_State *g) { g->gray = g->grayagain = NULL; g->weak = g->allweak = g->ephemeron = NULL; markobject(g, g->mainthread); markvalue(g, &g->l_registry); markmt(g); - markbeingfnz(g); /* mark any finalizing object left from previous cycle */ + markbeingfnz(g); /* mark any finalizing object left from previous cycle */ } /* }====================================================== */ + /* ** {====================================================== ** Traverse functions @@ -414,28 +433,29 @@ static void restartcollection(global_State *g) { ** atomic phase. In the atomic phase, if table has any white value, ** put it in 'weak' list, to be cleared. */ -static void traverseweakvalue(global_State *g, Table *h) { +static void traverseweakvalue (global_State *g, Table *h) { Node *n, *limit = gnodelast(h); /* if there is array part, assume it may have white values (it is not worth traversing it now just to check) */ int hasclears = (h->sizearray > 0); - for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ + for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ checkdeadkey(n); - if (ttisnil(gval(n))) /* entry is empty? */ - removeentry(n); /* remove it */ + if (ttisnil(gval(n))) /* entry is empty? */ + removeentry(n); /* remove it */ else { lua_assert(!ttisnil(gkey(n))); - markvalue(g, gkey(n)); /* mark key */ - if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */ - hasclears = 1; /* table will have to be cleared */ + markvalue(g, gkey(n)); /* mark key */ + if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */ + hasclears = 1; /* table will have to be cleared */ } } if (g->gcstate == GCSpropagate) - linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ + linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ else if (hasclears) - linkgclist(h, g->weak); /* has to be cleared later */ + linkgclist(h, g->weak); /* has to be cleared later */ } + /* ** Traverse an ephemeron table and link it to proper list. Returns true ** iff any object was marked during this traversal (which implies that @@ -446,10 +466,10 @@ static void traverseweakvalue(global_State *g, Table *h) { ** black). Otherwise, if it has any white key, table has to be cleared ** (in the atomic phase). */ -static int traverseephemeron(global_State *g, Table *h) { - int marked = 0; /* true if an object is marked in this traversal */ - int hasclears = 0; /* true if table has white keys */ - int hasww = 0; /* true if table has entry "white-key -> white-value" */ +static int traverseephemeron (global_State *g, Table *h) { + int marked = 0; /* true if an object is marked in this traversal */ + int hasclears = 0; /* true if table has white keys */ + int hasww = 0; /* true if table has entry "white-key -> white-value" */ Node *n, *limit = gnodelast(h); unsigned int i; /* traverse array part */ @@ -462,75 +482,81 @@ static int traverseephemeron(global_State *g, Table *h) { /* traverse hash part */ for (n = gnode(h, 0); n < limit; n++) { checkdeadkey(n); - if (ttisnil(gval(n))) /* entry is empty? */ - removeentry(n); /* remove it */ - else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */ - hasclears = 1; /* table must be cleared */ - if (valiswhite(gval(n))) /* value not marked yet? */ - hasww = 1; /* white-white entry */ + if (ttisnil(gval(n))) /* entry is empty? */ + removeentry(n); /* remove it */ + else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */ + hasclears = 1; /* table must be cleared */ + if (valiswhite(gval(n))) /* value not marked yet? */ + hasww = 1; /* white-white entry */ } - else if (valiswhite(gval(n))) { /* value not marked yet? */ + else if (valiswhite(gval(n))) { /* value not marked yet? */ marked = 1; - reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ + reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ } } /* link table into proper list */ if (g->gcstate == GCSpropagate) - linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ - else if (hasww) /* table has white->white entries? */ - linkgclist(h, g->ephemeron); /* have to propagate again */ - else if (hasclears) /* table has white keys? */ - linkgclist(h, g->allweak); /* may have to clean white keys */ + linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ + else if (hasww) /* table has white->white entries? */ + linkgclist(h, g->ephemeron); /* have to propagate again */ + else if (hasclears) /* table has white keys? */ + linkgclist(h, g->allweak); /* may have to clean white keys */ return marked; } -static void traversestrongtable(global_State *g, Table *h) { + +static void traversestrongtable (global_State *g, Table *h) { Node *n, *limit = gnodelast(h); unsigned int i; - for (i = 0; i < h->sizearray; i++) /* traverse array part */ + for (i = 0; i < h->sizearray; i++) /* traverse array part */ markvalue(g, &h->array[i]); - for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ + for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ checkdeadkey(n); - if (ttisnil(gval(n))) /* entry is empty? */ - removeentry(n); /* remove it */ + if (ttisnil(gval(n))) /* entry is empty? */ + removeentry(n); /* remove it */ else { lua_assert(!ttisnil(gkey(n))); - markvalue(g, gkey(n)); /* mark key */ - markvalue(g, gval(n)); /* mark value */ + markvalue(g, gkey(n)); /* mark key */ + markvalue(g, gval(n)); /* mark value */ } } } -static lu_mem traversetable(global_State *g, Table *h) { + +static lu_mem traversetable (global_State *g, Table *h) { const char *weakkey, *weakvalue; const TValue *mode = gfasttm(g, h->metatable, TM_MODE); markobjectN(g, h->metatable); - if (mode && ttisstring(mode) && /* is there a weak mode? */ - ((weakkey = strchr(svalue(mode), 'k')), (weakvalue = strchr(svalue(mode), 'v')), - (weakkey || weakvalue))) { /* is really weak? */ - black2gray(h); /* keep table gray */ - if (!weakkey) /* strong keys? */ + if (mode && ttisstring(mode) && /* is there a weak mode? */ + ((weakkey = strchr(svalue(mode), 'k')), + (weakvalue = strchr(svalue(mode), 'v')), + (weakkey || weakvalue))) { /* is really weak? */ + black2gray(h); /* keep table gray */ + if (!weakkey) /* strong keys? */ traverseweakvalue(g, h); - else if (!weakvalue) /* strong values? */ + else if (!weakvalue) /* strong values? */ traverseephemeron(g, h); - else /* all weak */ - linkgclist(h, g->allweak); /* nothing to traverse now */ + else /* all weak */ + linkgclist(h, g->allweak); /* nothing to traverse now */ } - else /* not weak */ + else /* not weak */ traversestrongtable(g, h); - return sizeof(Table) + sizeof(TValue) * h->sizearray + sizeof(Node) * cast(size_t, allocsizenode(h)); + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * cast(size_t, allocsizenode(h)); } + /* ** Traverse a prototype. (While a prototype is being build, its ** arrays can be larger than needed; the extra slots are filled with ** NULL, so the use of 'markobjectN') */ -static int traverseproto(global_State *g, Proto *f) { +static int traverseproto (global_State *g, Proto *f) { int i; - if (f->cache && iswhite(f->cache)) f->cache = NULL; /* allow cache to be collected */ + if (f->cache && iswhite(f->cache)) + f->cache = NULL; /* allow cache to be collected */ markobjectN(g, f->source); - for (i = 0; i < f->sizek; i++) /* mark literals */ + for (i = 0; i < f->sizek; i++) /* mark literals */ markvalue(g, &f->k[i]); for (i = 0; i < f->sizeupvalues; i++) { /* mark upvalue names */ markobjectN(g, f->upvalues[i].name); @@ -542,13 +568,18 @@ static int traverseproto(global_State *g, Proto *f) { markobjectN(g, f->locvars[i].varname); markobjectN(g, f->locvars[i].usertype); /* RAVI change */ } - return sizeof(Proto) + sizeof(Instruction) * f->sizecode + sizeof(Proto *) * f->sizep + sizeof(TValue) * f->sizek + - sizeof(int) * f->sizelineinfo + sizeof(LocVar) * f->sizelocvars + sizeof(Upvaldesc) * f->sizeupvalues; + return sizeof(Proto) + sizeof(Instruction) * f->sizecode + + sizeof(Proto *) * f->sizep + + sizeof(TValue) * f->sizek + + sizeof(int) * f->sizelineinfo + + sizeof(LocVar) * f->sizelocvars + + sizeof(Upvaldesc) * f->sizeupvalues; } -static lu_mem traverseCclosure(global_State *g, CClosure *cl) { + +static lu_mem traverseCclosure (global_State *g, CClosure *cl) { int i; - for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */ + for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */ markvalue(g, &cl->upvalue[i]); return sizeCclosure(cl->nupvalues); } @@ -559,14 +590,14 @@ static lu_mem traverseCclosure(global_State *g, CClosure *cl) { ** (because then the value cannot be changed by the thread and the ** thread may not be traversed again) */ -static lu_mem traverseLclosure(global_State *g, LClosure *cl) { +static lu_mem traverseLclosure (global_State *g, LClosure *cl) { int i; - markobjectN(g, cl->p); /* mark its prototype */ - for (i = 0; i < cl->nupvalues; i++) { /* mark its upvalues */ + markobjectN(g, cl->p); /* mark its prototype */ + for (i = 0; i < cl->nupvalues; i++) { /* mark its upvalues */ UpVal *uv = cl->upvals[i]; if (uv != NULL) { if (upisopen(uv) && g->gcstate != GCSinsideatomic) - uv->u.open.touched = 1; /* can be marked in 'remarkupvals' */ + uv->u.open.touched = 1; /* can be marked in 'remarkupvals' */ else markvalue(g, uv->v); } @@ -574,68 +605,74 @@ static lu_mem traverseLclosure(global_State *g, LClosure *cl) { return sizeLclosure(cl->nupvalues); } -static lu_mem traversethread(global_State *g, lua_State *th) { + +static lu_mem traversethread (global_State *g, lua_State *th) { StkId o = th->stack; - if (o == NULL) return 1; /* stack not completely built yet */ - lua_assert(g->gcstate == GCSinsideatomic || th->openupval == NULL || isintwups(th)); - for (; o < th->top; o++) /* mark live elements in the stack */ + if (o == NULL) + return 1; /* stack not completely built yet */ + lua_assert(g->gcstate == GCSinsideatomic || + th->openupval == NULL || isintwups(th)); + for (; o < th->top; o++) /* mark live elements in the stack */ markvalue(g, o); - if (g->gcstate == GCSinsideatomic) { /* final traversal? */ - StkId lim = th->stack + th->stacksize; /* real end of stack */ - for (; o < lim; o++) /* clear not-marked stack slice */ + if (g->gcstate == GCSinsideatomic) { /* final traversal? */ + StkId lim = th->stack + th->stacksize; /* real end of stack */ + for (; o < lim; o++) /* clear not-marked stack slice */ setnilvalue(o); /* 'remarkupvals' may have removed thread from 'twups' list */ if (!isintwups(th) && th->openupval != NULL) { - th->twups = g->twups; /* link it back to the list */ + th->twups = g->twups; /* link it back to the list */ g->twups = th; } } else if (g->gckind != KGC_EMERGENCY) luaD_shrinkstack(th); /* do not change stack in emergency cycle */ - return (sizeof(lua_State) + sizeof(TValue) * th->stacksize + sizeof(CallInfo) * th->nci); + return (sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->nci); } + /* ** traverse one gray object, turning it to black (except for threads, ** which are always gray). */ -static void propagatemark(global_State *g) { +static void propagatemark (global_State *g) { lu_mem size; GCObject *o = g->gray; lua_assert(isgray(o)); gray2black(o); switch (o->tt) { + /* RAVI changes */ case RAVI_TIARRAY: case RAVI_TFARRAY: case LUA_TTABLE: { Table *h = gco2t(o); - g->gray = h->gclist; /* remove from 'gray' list */ + g->gray = h->gclist; /* remove from 'gray' list */ size = traversetable(g, h); break; } case LUA_TLCL: { LClosure *cl = gco2lcl(o); - g->gray = cl->gclist; /* remove from 'gray' list */ + g->gray = cl->gclist; /* remove from 'gray' list */ size = traverseLclosure(g, cl); break; } case LUA_TCCL: { CClosure *cl = gco2ccl(o); - g->gray = cl->gclist; /* remove from 'gray' list */ + g->gray = cl->gclist; /* remove from 'gray' list */ size = traverseCclosure(g, cl); break; } case LUA_TTHREAD: { lua_State *th = gco2th(o); - g->gray = th->gclist; /* remove from 'gray' list */ - linkgclist(th, g->grayagain); /* insert into 'grayagain' list */ + g->gray = th->gclist; /* remove from 'gray' list */ + linkgclist(th, g->grayagain); /* insert into 'grayagain' list */ black2gray(o); size = traversethread(g, th); break; } case LUA_TPROTO: { Proto *p = gco2p(o); - g->gray = p->gclist; /* remove from 'gray' list */ + g->gray = p->gclist; /* remove from 'gray' list */ size = traverseproto(g, p); break; } @@ -644,22 +681,24 @@ static void propagatemark(global_State *g) { g->GCmemtrav += size; } -static void propagateall(global_State *g) { + +static void propagateall (global_State *g) { while (g->gray) propagatemark(g); } -static void convergeephemerons(global_State *g) { + +static void convergeephemerons (global_State *g) { int changed; do { GCObject *w; - GCObject *next = g->ephemeron; /* get ephemeron list */ - g->ephemeron = NULL; /* tables may return to this list when traversed */ + GCObject *next = g->ephemeron; /* get ephemeron list */ + g->ephemeron = NULL; /* tables may return to this list when traversed */ changed = 0; while ((w = next) != NULL) { next = gco2t(w)->gclist; - if (traverseephemeron(g, gco2t(w))) { /* traverse marked some value? */ - propagateall(g); /* propagate changes */ - changed = 1; /* will have to revisit all ephemeron tables */ + if (traverseephemeron(g, gco2t(w))) { /* traverse marked some value? */ + propagateall(g); /* propagate changes */ + changed = 1; /* will have to revisit all ephemeron tables */ } } } while (changed); @@ -667,68 +706,77 @@ static void convergeephemerons(global_State *g) { /* }====================================================== */ + /* ** {====================================================== ** Sweep Functions ** ======================================================= */ + /* ** clear entries with unmarked keys from all weaktables in list 'l' up ** to element 'f' */ -static void clearkeys(global_State *g, GCObject *l, GCObject *f) { +static void clearkeys (global_State *g, GCObject *l, GCObject *f) { for (; l != f; l = gco2t(l)->gclist) { Table *h = gco2t(l); Node *n, *limit = gnodelast(h); for (n = gnode(h, 0); n < limit; n++) { if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) { - setnilvalue(gval(n)); /* remove value ... */ - removeentry(n); /* and remove entry from table */ + setnilvalue(gval(n)); /* remove value ... */ } + if (ttisnil(gval(n))) /* is entry empty? */ + removeentry(n); /* remove entry from table */ } } } + /* ** clear entries with unmarked values from all weaktables in list 'l' up ** to element 'f' */ -static void clearvalues(global_State *g, GCObject *l, GCObject *f) { +static void clearvalues (global_State *g, GCObject *l, GCObject *f) { for (; l != f; l = gco2t(l)->gclist) { Table *h = gco2t(l); Node *n, *limit = gnodelast(h); unsigned int i; for (i = 0; i < h->sizearray; i++) { TValue *o = &h->array[i]; - if (iscleared(g, o)) /* value was collected? */ - setnilvalue(o); /* remove value */ + if (iscleared(g, o)) /* value was collected? */ + setnilvalue(o); /* remove value */ } for (n = gnode(h, 0); n < limit; n++) { if (!ttisnil(gval(n)) && iscleared(g, gval(n))) { - setnilvalue(gval(n)); /* remove value ... */ - removeentry(n); /* and remove entry from table */ + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* and remove entry from table */ } } } } -void luaC_upvdeccount(lua_State *L, UpVal *uv) { + +void luaC_upvdeccount (lua_State *L, UpVal *uv) { lua_assert(uv->refcount > 0); uv->refcount--; - if (uv->refcount == 0 && !upisopen(uv)) luaM_free(L, uv); + if (uv->refcount == 0 && !upisopen(uv)) + luaM_free(L, uv); } -static void freeLclosure(lua_State *L, LClosure *cl) { + +static void freeLclosure (lua_State *L, LClosure *cl) { int i; for (i = 0; i < cl->nupvalues; i++) { UpVal *uv = cl->upvals[i]; - if (uv) luaC_upvdeccount(L, uv); + if (uv) + luaC_upvdeccount(L, uv); } luaM_freemem(L, cl, sizeLclosure(cl->nupvalues)); } -static void freeobj(lua_State *L, GCObject *o) { + +static void freeobj (lua_State *L, GCObject *o) { switch (o->tt) { case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; case LUA_TLCL: { @@ -739,13 +787,14 @@ static void freeobj(lua_State *L, GCObject *o) { luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues)); break; } + /* RAVI changes */ case RAVI_TFARRAY: case RAVI_TIARRAY: case LUA_TTABLE: luaH_free(L, gco2t(o)); break; case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break; case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break; case LUA_TSHRSTR: - luaS_remove(L, gco2ts(o)); /* remove it from hash table */ + luaS_remove(L, gco2ts(o)); /* remove it from hash table */ luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen)); break; case LUA_TLNGSTR: { @@ -756,8 +805,10 @@ static void freeobj(lua_State *L, GCObject *o) { } } -#define sweepwholelist(L, p) sweeplist(L, p, MAX_LUMEM) -static GCObject **sweeplist(lua_State *L, GCObject **p, lu_mem count); + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count); + /* ** sweep at most 'count' elements from a list of GCObjects erasing dead @@ -766,36 +817,40 @@ static GCObject **sweeplist(lua_State *L, GCObject **p, lu_mem count); ** collection cycle. Return where to continue the traversal or NULL if ** list is finished. */ -static GCObject **sweeplist(lua_State *L, GCObject **p, lu_mem count) { +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { global_State *g = G(L); int ow = otherwhite(g); - int white = luaC_white(g); /* current white */ + int white = luaC_white(g); /* current white */ while (*p != NULL && count-- > 0) { GCObject *curr = *p; int marked = curr->marked; - if (isdeadm(ow, marked)) { /* is 'curr' dead? */ - *p = curr->next; /* remove 'curr' from list */ - freeobj(L, curr); /* erase 'curr' */ + if (isdeadm(ow, marked)) { /* is 'curr' dead? */ + *p = curr->next; /* remove 'curr' from list */ + freeobj(L, curr); /* erase 'curr' */ } - else { /* change mark to 'white' */ + else { /* change mark to 'white' */ curr->marked = cast_byte((marked & maskcolors) | white); - p = &curr->next; /* go to next element */ + p = &curr->next; /* go to next element */ } } return (*p == NULL) ? NULL : p; } + /* ** sweep a list until a live object (or end of list) */ -static GCObject **sweeptolive(lua_State *L, GCObject **p) { +static GCObject **sweeptolive (lua_State *L, GCObject **p) { GCObject **old = p; - do { p = sweeplist(L, p, 1); } while (p == old); + do { + p = sweeplist(L, p, 1); + } while (p == old); return p; } /* }====================================================== */ + /* ** {====================================================== ** Finalization @@ -805,163 +860,180 @@ static GCObject **sweeptolive(lua_State *L, GCObject **p) { /* ** If possible, shrink string table */ -static void checkSizes(lua_State *L, global_State *g) { +static void checkSizes (lua_State *L, global_State *g) { if (g->gckind != KGC_EMERGENCY) { l_mem olddebt = g->GCdebt; if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ - luaS_resize(L, g->strt.size / 2); /* shrink it a little */ - g->GCestimate += g->GCdebt - olddebt; /* update estimate */ + luaS_resize(L, g->strt.size / 2); /* shrink it a little */ + g->GCestimate += g->GCdebt - olddebt; /* update estimate */ } } -static GCObject *udata2finalize(global_State *g) { - GCObject *o = g->tobefnz; /* get first element */ + +static GCObject *udata2finalize (global_State *g) { + GCObject *o = g->tobefnz; /* get first element */ lua_assert(tofinalize(o)); - g->tobefnz = o->next; /* remove it from 'tobefnz' list */ - o->next = g->allgc; /* return it to 'allgc' list */ + g->tobefnz = o->next; /* remove it from 'tobefnz' list */ + o->next = g->allgc; /* return it to 'allgc' list */ g->allgc = o; - resetbit(o->marked, FINALIZEDBIT); /* object is "normal" again */ - if (issweepphase(g)) makewhite(g, o); /* "sweep" object */ + resetbit(o->marked, FINALIZEDBIT); /* object is "normal" again */ + if (issweepphase(g)) + makewhite(g, o); /* "sweep" object */ return o; } -static void dothecall(lua_State *L, void *ud) { + +static void dothecall (lua_State *L, void *ud) { UNUSED(ud); luaD_callnoyield(L, L->top - 2, 0); } -static void GCTM(lua_State *L, int propagateerrors) { + +static void GCTM (lua_State *L, int propagateerrors) { global_State *g = G(L); const TValue *tm; TValue v; setgcovalue(L, &v, udata2finalize(g)); tm = luaT_gettmbyobj(L, &v, TM_GC); - if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */ + if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */ int status; lu_byte oldah = L->allowhook; - int running = g->gcrunning; - L->allowhook = 0; /* stop debug hooks during GC metamethod */ - g->gcrunning = 0; /* avoid GC steps */ - setobj2s(L, L->top, tm); /* push finalizer... */ - setobj2s(L, L->top + 1, &v); /* ... and its argument */ - L->top += 2; /* and (next line) call the finalizer */ - L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ + int running = g->gcrunning; + L->allowhook = 0; /* stop debug hooks during GC metamethod */ + g->gcrunning = 0; /* avoid GC steps */ + setobj2s(L, L->top, tm); /* push finalizer... */ + setobj2s(L, L->top + 1, &v); /* ... and its argument */ + L->top += 2; /* and (next line) call the finalizer */ + L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); - L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ - L->allowhook = oldah; /* restore hooks */ - g->gcrunning = running; /* restore state */ - if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ - if (status == LUA_ERRRUN) { /* is there an error object? */ - const char *msg = (ttisstring(L->top - 1)) ? svalue(L->top - 1) : "no message"; + L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ + L->allowhook = oldah; /* restore hooks */ + g->gcrunning = running; /* restore state */ + if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ + if (status == LUA_ERRRUN) { /* is there an error object? */ + const char *msg = (ttisstring(L->top - 1)) + ? svalue(L->top - 1) + : "no message"; luaO_pushfstring(L, "error in __gc metamethod (%s)", msg); - status = LUA_ERRGCMM; /* error in __gc metamethod */ + status = LUA_ERRGCMM; /* error in __gc metamethod */ } - luaD_throw(L, status); /* re-throw error */ + luaD_throw(L, status); /* re-throw error */ } } } + /* ** call a few (up to 'g->gcfinnum') finalizers */ -static int runafewfinalizers(lua_State *L) { +static int runafewfinalizers (lua_State *L) { global_State *g = G(L); unsigned int i; lua_assert(!g->tobefnz || g->gcfinnum > 0); - for (i = 0; g->tobefnz && i < g->gcfinnum; i++) GCTM(L, 1); /* call one finalizer */ - g->gcfinnum = (!g->tobefnz) ? 0 /* nothing more to finalize? */ - : g->gcfinnum * 2; /* else call a few more next time */ + for (i = 0; g->tobefnz && i < g->gcfinnum; i++) + GCTM(L, 1); /* call one finalizer */ + g->gcfinnum = (!g->tobefnz) ? 0 /* nothing more to finalize? */ + : g->gcfinnum * 2; /* else call a few more next time */ return i; } + /* ** call all pending finalizers */ -static void callallpendingfinalizers(lua_State *L) { +static void callallpendingfinalizers (lua_State *L) { global_State *g = G(L); - while (g->tobefnz) GCTM(L, 0); + while (g->tobefnz) + GCTM(L, 0); } + /* ** find last 'next' field in list 'p' list (to add elements in its end) */ -static GCObject **findlast(GCObject **p) { - while (*p != NULL) p = &(*p)->next; +static GCObject **findlast (GCObject **p) { + while (*p != NULL) + p = &(*p)->next; return p; } + /* ** move all unreachable objects (or 'all' objects) that need ** finalization from list 'finobj' to list 'tobefnz' (to be finalized) */ -static void separatetobefnz(global_State *g, int all) { +static void separatetobefnz (global_State *g, int all) { GCObject *curr; GCObject **p = &g->finobj; GCObject **lastnext = findlast(&g->tobefnz); - while ((curr = *p) != NULL) { /* traverse all finalizable objects */ + while ((curr = *p) != NULL) { /* traverse all finalizable objects */ lua_assert(tofinalize(curr)); - if (!(iswhite(curr) || all)) /* not being collected? */ - p = &curr->next; /* don't bother with it */ + if (!(iswhite(curr) || all)) /* not being collected? */ + p = &curr->next; /* don't bother with it */ else { - *p = curr->next; /* remove 'curr' from 'finobj' list */ - curr->next = *lastnext; /* link at the end of 'tobefnz' list */ + *p = curr->next; /* remove 'curr' from 'finobj' list */ + curr->next = *lastnext; /* link at the end of 'tobefnz' list */ *lastnext = curr; lastnext = &curr->next; } } } + /* ** if object 'o' has a finalizer, remove it from 'allgc' list (must ** search the list to find it) and link it in 'finobj' list. */ -void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt) { +void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { global_State *g = G(L); - if (tofinalize(o) || /* obj. is already marked... */ - gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ - return; /* nothing to be done */ - else { /* move 'o' to 'finobj' list */ + if (tofinalize(o) || /* obj. is already marked... */ + gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ + return; /* nothing to be done */ + else { /* move 'o' to 'finobj' list */ GCObject **p; if (issweepphase(g)) { - makewhite(g, o); /* "sweep" object 'o' */ - if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ - g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */ + makewhite(g, o); /* "sweep" object 'o' */ + if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ + g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */ } /* search for pointer pointing to 'o' */ - for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ - } - *p = o->next; /* remove 'o' from 'allgc' list */ - o->next = g->finobj; /* link it in 'finobj' list */ + for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ } + *p = o->next; /* remove 'o' from 'allgc' list */ + o->next = g->finobj; /* link it in 'finobj' list */ g->finobj = o; - l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */ + l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */ } } /* }====================================================== */ + + /* ** {====================================================== ** GC control ** ======================================================= */ + /* ** Set a reasonable "time" to wait before starting a new GC cycle; cycle ** will start when memory use hits threshold. (Division by 'estimate' ** should be OK: it cannot be zero (because Lua cannot even start with ** less than PAUSEADJ bytes). */ -static void setpause(global_State *g) { +static void setpause (global_State *g) { l_mem threshold, debt; - l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */ + l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */ lua_assert(estimate > 0); - threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */ - ? estimate * g->gcpause /* no overflow */ - : MAX_LMEM; /* overflow; truncate to maximum */ + threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */ + ? estimate * g->gcpause /* no overflow */ + : MAX_LMEM; /* overflow; truncate to maximum */ debt = gettotalbytes(g) - threshold; luaE_setdebt(g, debt); } + /* ** Enter first sweep phase. ** The call to 'sweeplist' tries to make pointer point to an object @@ -969,16 +1041,17 @@ static void setpause(global_State *g) { ** not need to skip objects created between "now" and the start of the ** real sweep. */ -static void entersweep(lua_State *L) { +static void entersweep (lua_State *L) { global_State *g = G(L); g->gcstate = GCSswpallgc; lua_assert(g->sweepgc == NULL); g->sweepgc = sweeplist(L, &g->allgc, 1); } -void luaC_freeallobjects(lua_State *L) { + +void luaC_freeallobjects (lua_State *L) { global_State *g = G(L); - separatetobefnz(g, 1); /* separate all objects with finalizers */ + separatetobefnz(g, 1); /* separate all objects with finalizers */ lua_assert(g->finobj == NULL); callallpendingfinalizers(L); lua_assert(g->tobefnz == NULL); @@ -986,63 +1059,65 @@ void luaC_freeallobjects(lua_State *L) { g->gckind = KGC_NORMAL; sweepwholelist(L, &g->finobj); sweepwholelist(L, &g->allgc); - sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ + sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ lua_assert(g->strt.nuse == 0); } -static l_mem atomic(lua_State *L) { + +static l_mem atomic (lua_State *L) { global_State *g = G(L); l_mem work; GCObject *origweak, *origall; - GCObject *grayagain = g->grayagain; /* save original list */ + GCObject *grayagain = g->grayagain; /* save original list */ lua_assert(g->ephemeron == NULL && g->weak == NULL); lua_assert(!iswhite(g->mainthread)); g->gcstate = GCSinsideatomic; - g->GCmemtrav = 0; /* start counting work */ - markobject(g, L); /* mark running thread */ + g->GCmemtrav = 0; /* start counting work */ + markobject(g, L); /* mark running thread */ /* registry and global metatables may be changed by API */ markvalue(g, &g->l_registry); - markmt(g); /* mark global metatables */ + markmt(g); /* mark global metatables */ /* remark occasional upvalues of (maybe) dead threads */ remarkupvals(g); - propagateall(g); /* propagate changes */ - work = g->GCmemtrav; /* stop counting (do not recount 'grayagain') */ + propagateall(g); /* propagate changes */ + work = g->GCmemtrav; /* stop counting (do not recount 'grayagain') */ g->gray = grayagain; propagateall(g); /* traverse 'grayagain' list */ - g->GCmemtrav = 0; /* restart counting */ + g->GCmemtrav = 0; /* restart counting */ convergeephemerons(g); /* at this point, all strongly accessible objects are marked. */ /* Clear values from weak tables, before checking finalizers */ clearvalues(g, g->weak, NULL); clearvalues(g, g->allweak, NULL); - origweak = g->weak; - origall = g->allweak; + origweak = g->weak; origall = g->allweak; work += g->GCmemtrav; /* stop counting (objects being finalized) */ - separatetobefnz(g, 0); /* separate objects to be finalized */ - g->gcfinnum = 1; /* there may be objects to be finalized */ - markbeingfnz(g); /* mark objects that will be finalized */ - propagateall(g); /* remark, to propagate 'resurrection' */ - g->GCmemtrav = 0; /* restart counting */ + separatetobefnz(g, 0); /* separate objects to be finalized */ + g->gcfinnum = 1; /* there may be objects to be finalized */ + markbeingfnz(g); /* mark objects that will be finalized */ + propagateall(g); /* remark, to propagate 'resurrection' */ + g->GCmemtrav = 0; /* restart counting */ convergeephemerons(g); /* at this point, all resurrected objects are marked. */ /* remove dead objects from weak tables */ - clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */ - clearkeys(g, g->allweak, NULL); /* clear keys from all 'allweak' tables */ + clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */ + clearkeys(g, g->allweak, NULL); /* clear keys from all 'allweak' tables */ /* clear values from resurrected weak tables */ clearvalues(g, g->weak, origweak); clearvalues(g, g->allweak, origall); luaS_clearcache(g); - g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ - work += g->GCmemtrav; /* complete counting */ - return work; /* estimate of memory marked by 'atomic' */ + g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ + work += g->GCmemtrav; /* complete counting */ + return work; /* estimate of memory marked by 'atomic' */ } -static lu_mem sweepstep(lua_State *L, global_State *g, int nextstate, GCObject **nextlist) { + +static lu_mem sweepstep (lua_State *L, global_State *g, + int nextstate, GCObject **nextlist) { if (g->sweepgc) { l_mem olddebt = g->GCdebt; g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); - g->GCestimate += g->GCdebt - olddebt; /* update estimate */ - if (g->sweepgc) /* is there still something to sweep? */ + g->GCestimate += g->GCdebt - olddebt; /* update estimate */ + if (g->sweepgc) /* is there still something to sweep? */ return (GCSWEEPMAX * GCSWEEPCOST); } /* else enter next state */ @@ -1051,11 +1126,12 @@ static lu_mem sweepstep(lua_State *L, global_State *g, int nextstate, GCObject * return 0; } -static lu_mem singlestep(lua_State *L) { + +static lu_mem singlestep (lua_State *L) { global_State *g = G(L); switch (g->gcstate) { case GCSpause: { - g->GCmemtrav = g->strt.size * sizeof(GCObject *); + g->GCmemtrav = g->strt.size * sizeof(GCObject*); restartcollection(g); g->gcstate = GCSpropagate; return g->GCmemtrav; @@ -1064,38 +1140,40 @@ static lu_mem singlestep(lua_State *L) { g->GCmemtrav = 0; lua_assert(g->gray); propagatemark(g); - if (g->gray == NULL) /* no more gray objects? */ - g->gcstate = GCSatomic; /* finish propagate phase */ - return g->GCmemtrav; /* memory traversed in this step */ + if (g->gray == NULL) /* no more gray objects? */ + g->gcstate = GCSatomic; /* finish propagate phase */ + return g->GCmemtrav; /* memory traversed in this step */ } case GCSatomic: { lu_mem work; propagateall(g); /* make sure gray list is empty */ - work = atomic(L); /* work is what was traversed by 'atomic' */ + work = atomic(L); /* work is what was traversed by 'atomic' */ entersweep(L); - g->GCestimate = gettotalbytes(g); /* first estimate */ - ; + g->GCestimate = gettotalbytes(g); /* first estimate */; return work; } - case GCSswpallgc: { /* sweep "regular" objects */ return sweepstep(L, g, GCSswpfinobj, &g->finobj); + case GCSswpallgc: { /* sweep "regular" objects */ + return sweepstep(L, g, GCSswpfinobj, &g->finobj); } - case GCSswpfinobj: { /* sweep objects with finalizers */ return sweepstep(L, g, GCSswptobefnz, &g->tobefnz); + case GCSswpfinobj: { /* sweep objects with finalizers */ + return sweepstep(L, g, GCSswptobefnz, &g->tobefnz); } - case GCSswptobefnz: { /* sweep objects to be finalized */ return sweepstep(L, g, GCSswpend, NULL); + case GCSswptobefnz: { /* sweep objects to be finalized */ + return sweepstep(L, g, GCSswpend, NULL); } - case GCSswpend: { /* finish sweeps */ - makewhite(g, g->mainthread); /* sweep main thread */ + case GCSswpend: { /* finish sweeps */ + makewhite(g, g->mainthread); /* sweep main thread */ checkSizes(L, g); g->gcstate = GCScallfin; return 0; } - case GCScallfin: { /* call remaining finalizers */ + case GCScallfin: { /* call remaining finalizers */ if (g->tobefnz && g->gckind != KGC_EMERGENCY) { int n = runafewfinalizers(L); return (n * GCFINALIZECOST); } - else { /* emergency mode or no more finalizers */ - g->gcstate = GCSpause; /* finish collection */ + else { /* emergency mode or no more finalizers */ + g->gcstate = GCSpause; /* finish collection */ return 0; } } @@ -1103,24 +1181,26 @@ static lu_mem singlestep(lua_State *L) { } } + /* ** advances the garbage collector until it reaches a state allowed ** by 'statemask' */ -void luaC_runtilstate(lua_State *L, int statesmask) { +void luaC_runtilstate (lua_State *L, int statesmask) { global_State *g = G(L); - while (!testbit(statesmask, g->gcstate)) singlestep(L); + while (!testbit(statesmask, g->gcstate)) + singlestep(L); } + /* ** get GC debt and convert it from Kb to 'work units' (avoid zero debt ** and overflows) */ -static l_mem getdebt(global_State *g) { +static l_mem getdebt (global_State *g) { l_mem debt = g->GCdebt; int stepmul = g->gcstepmul; - if (debt <= 0) - return 0; /* minimal debt */ + if (debt <= 0) return 0; /* minimal debt */ else { debt = (debt / STEPMULADJ) + 1; debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM; @@ -1131,26 +1211,27 @@ static l_mem getdebt(global_State *g) { /* ** performs a basic GC step when collector is running */ -void luaC_step(lua_State *L) { +void luaC_step (lua_State *L) { global_State *g = G(L); - l_mem debt = getdebt(g); /* GC deficit (be paid now) */ - if (!g->gcrunning) { /* not running? */ - luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */ + l_mem debt = getdebt(g); /* GC deficit (be paid now) */ + if (!g->gcrunning) { /* not running? */ + luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */ return; } - do { /* repeat until pause or enough "credit" (negative debt) */ - lu_mem work = singlestep(L); /* perform one single step */ + do { /* repeat until pause or enough "credit" (negative debt) */ + lu_mem work = singlestep(L); /* perform one single step */ debt -= work; } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause); if (g->gcstate == GCSpause) - setpause(g); /* pause until next cycle */ + setpause(g); /* pause until next cycle */ else { - debt = (debt / g->gcstepmul) * STEPMULADJ; /* convert 'work units' to Kb */ + debt = (debt / g->gcstepmul) * STEPMULADJ; /* convert 'work units' to Kb */ luaE_setdebt(g, debt); runafewfinalizers(L); } } + /* ** Performs a full GC cycle; if 'isemergency', set a flag to avoid ** some operations which could change the interpreter state in some @@ -1160,22 +1241,24 @@ void luaC_step(lua_State *L) { ** to sweep all objects to turn them back to white (as white has not ** changed, nothing will be collected). */ -void luaC_fullgc(lua_State *L, int isemergency) { +void luaC_fullgc (lua_State *L, int isemergency) { global_State *g = G(L); lua_assert(g->gckind == KGC_NORMAL); - if (isemergency) g->gckind = KGC_EMERGENCY; /* set flag */ - if (keepinvariant(g)) { /* black objects? */ - entersweep(L); /* sweep everything to turn them back to white */ + if (isemergency) g->gckind = KGC_EMERGENCY; /* set flag */ + if (keepinvariant(g)) { /* black objects? */ + entersweep(L); /* sweep everything to turn them back to white */ } /* finish any pending sweep phase to start a new cycle */ luaC_runtilstate(L, bitmask(GCSpause)); luaC_runtilstate(L, ~bitmask(GCSpause)); /* start new collection */ - luaC_runtilstate(L, bitmask(GCScallfin)); /* run up to finalizers */ + luaC_runtilstate(L, bitmask(GCScallfin)); /* run up to finalizers */ /* estimate must be correct after a full GC cycle */ lua_assert(g->GCestimate == gettotalbytes(g)); - luaC_runtilstate(L, bitmask(GCSpause)); /* finish collection */ + luaC_runtilstate(L, bitmask(GCSpause)); /* finish collection */ g->gckind = KGC_NORMAL; setpause(g); } /* }====================================================== */ + + diff --git a/src/linit.c b/src/linit.c index b0b1d17..a24896c 100644 --- a/src/linit.c +++ b/src/linit.c @@ -1,5 +1,5 @@ /* -** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp $ +** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $ ** Initialization of libraries for lua.c and other clients ** See Copyright Notice in lua.h */ diff --git a/src/liolib.c b/src/liolib.c index 4c4e7c4..32d40ba 100644 --- a/src/liolib.c +++ b/src/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 roberto Exp $ +** $Id: liolib.c,v 2.151.1.1 2017/04/19 17:29:57 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -206,11 +206,16 @@ static int aux_close (lua_State *L) { } +static int f_close (lua_State *L) { + tofile(L); /* make sure argument is an open stream */ + return aux_close(L); +} + + static int io_close (lua_State *L) { if (lua_isnone(L, 1)) /* no argument? */ lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */ - tofile(L); /* make sure argument is an open stream */ - return aux_close(L); + return f_close(L); } @@ -713,7 +718,7 @@ static const luaL_Reg iolib[] = { ** methods for file handles */ static const luaL_Reg flib[] = { - {"close", io_close}, + {"close", f_close}, {"flush", f_flush}, {"lines", f_lines}, {"read", f_read}, diff --git a/src/llex.c b/src/llex.c index 16b80e1..cc4591e 100644 --- a/src/llex.c +++ b/src/llex.c @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp $ +** $Id: llex.c,v 2.96.1.1 2017/04/19 17:20:42 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ diff --git a/src/lmathlib.c b/src/lmathlib.c index b7f8bae..7ef7e59 100644 --- a/src/lmathlib.c +++ b/src/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.119 2016/12/22 13:08:50 roberto Exp $ +** $Id: lmathlib.c,v 1.119.1.1 2017/04/19 17:20:42 roberto Exp $ ** Standard mathematical library ** See Copyright Notice in lua.h */ diff --git a/src/lmem.c b/src/lmem.c index 0a0476c..0241cc3 100644 --- a/src/lmem.c +++ b/src/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $ +** $Id: lmem.c,v 1.91.1.1 2017/04/19 17:20:42 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ diff --git a/src/loadlib.c b/src/loadlib.c index 4791e74..45f44d3 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp $ +** $Id: loadlib.c,v 1.130.1.1 2017/04/19 17:20:42 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** diff --git a/src/lobject.c b/src/lobject.c index 2da7689..2218c8c 100644 --- a/src/lobject.c +++ b/src/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.113 2016/12/22 13:08:50 roberto Exp $ +** $Id: lobject.c,v 2.113.1.1 2017/04/19 17:29:57 roberto Exp $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -435,7 +435,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { } case 'p': { /* a pointer */ char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */ - int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *)); + void *p = va_arg(argp, void *); + int l = lua_pointer2str(buff, sizeof(buff), p); pushstr(L, buff, l); break; } diff --git a/src/lopcodes.c b/src/lopcodes.c index 5e469f3..7047c4c 100644 --- a/src/lopcodes.c +++ b/src/lopcodes.c @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $ +** $Id: lopcodes.c,v 1.55.1.1 2017/04/19 17:20:42 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ diff --git a/src/loslib.c b/src/loslib.c index 5a94eb9..de590c6 100644 --- a/src/loslib.c +++ b/src/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.65 2016/07/18 17:58:58 roberto Exp $ +** $Id: loslib.c,v 1.65.1.1 2017/04/19 17:29:57 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -293,7 +293,8 @@ static int os_date (lua_State *L) { else stm = l_localtime(&t, &tmr); if (stm == NULL) /* invalid date? */ - luaL_error(L, "time result cannot be represented in this installation"); + return luaL_error(L, + "time result cannot be represented in this installation"); if (strcmp(s, "*t") == 0) { lua_createtable(L, 0, 9); /* 9 = number of fields */ setallfields(L, stm); @@ -340,7 +341,8 @@ static int os_time (lua_State *L) { setallfields(L, &ts); /* update fields with normalized values */ } if (t != (time_t)(l_timet)t || t == (time_t)(-1)) - luaL_error(L, "time result cannot be represented in this installation"); + return luaL_error(L, + "time result cannot be represented in this installation"); l_pushtime(L, t); return 1; } diff --git a/src/lparser.c b/src/lparser.c index ed5e0d6..65d6338 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.155 2016/08/01 19:51:24 roberto Exp $ +** $Id: lparser.c,v 2.155.1.2 2017/04/29 18:11:40 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -2141,7 +2141,7 @@ static void test_then_block (LexState *ls, int *escapelist) { luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ enterblock(fs, &bl, 0); /* must enter block before 'goto' */ gotostat(ls, v.t); /* handle goto/break */ - skipnoopstat(ls); /* skip other no-op statements */ + while (testnext(ls, ';')) {} /* skip colons */ if (block_follow(ls, 0)) { /* 'goto' is the entire block? */ leaveblock(fs); return; /* and that is it */ diff --git a/src/lstate.c b/src/lstate.c index 99f0f9a..672182f 100644 --- a/src/lstate.c +++ b/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $ +** $Id: lstate.c,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ diff --git a/src/lstring.c b/src/lstring.c index 9351766..6257f21 100644 --- a/src/lstring.c +++ b/src/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $ +** $Id: lstring.c,v 2.56.1.1 2017/04/19 17:20:42 roberto Exp $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ diff --git a/src/lstrlib.c b/src/lstrlib.c index c7aa755..b4bed7e 100644 --- a/src/lstrlib.c +++ b/src/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.254 2016/12/22 13:08:50 roberto Exp $ +** $Id: lstrlib.c,v 1.254.1.1 2017/04/19 17:29:57 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -879,7 +879,7 @@ static int lua_number2strx (lua_State *L, char *buff, int sz, buff[i] = toupper(uchar(buff[i])); } else if (fmt[SIZELENMOD] != 'a') - luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); + return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); return n; } @@ -1199,8 +1199,8 @@ static int getnum (const char **fmt, int df) { static int getnumlimit (Header *h, const char **fmt, int df) { int sz = getnum(fmt, df); if (sz > MAXINTSIZE || sz <= 0) - luaL_error(h->L, "integral size (%d) out of limits [1,%d]", - sz, MAXINTSIZE); + return luaL_error(h->L, "integral size (%d) out of limits [1,%d]", + sz, MAXINTSIZE); return sz; } diff --git a/src/ltable.c b/src/ltable.c index 5b2aa4b..6ce8ca8 100644 --- a/src/ltable.c +++ b/src/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.118 2016/11/07 12:38:35 roberto Exp $ +** $Id: ltable.c,v 2.118.1.4 2018/06/08 16:22:51 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -243,7 +243,9 @@ static unsigned int computesizes (unsigned int nums[], unsigned int *pna) { unsigned int na = 0; /* number of elements to go to array part */ unsigned int optimal = 0; /* optimal size for array part */ /* loop while keys can fill more than half of total size */ - for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) { + for (i = 0, twotoi = 1; + twotoi > 0 && *pna > twotoi / 2; + i++, twotoi *= 2) { if (nums[i] > 0) { a += nums[i]; if (a > twotoi/2) { /* more than half elements present? */ @@ -356,17 +358,34 @@ static void setnodevector (lua_State *L, Table *t, unsigned int size) { } +typedef struct { + Table *t; + unsigned int nhsize; +} AuxsetnodeT; + + +static void auxsetnode (lua_State *L, void *ud) { + AuxsetnodeT *asn = cast(AuxsetnodeT *, ud); + setnodevector(L, asn->t, asn->nhsize); +} + + void luaH_resize (lua_State *L, Table *t, unsigned int nasize, unsigned int nhsize) { unsigned int i; int j; + AuxsetnodeT asn; unsigned int oldasize = t->sizearray; int oldhsize = allocsizenode(t); Node *nold = t->node; /* save old hash ... */ if (nasize > oldasize) /* array part must grow? */ setarrayvector(L, t, nasize); /* create new hash part with appropriate size */ - setnodevector(L, t, nhsize); + asn.t = t; asn.nhsize = nhsize; + if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) { /* mem. error? */ + setarrayvector(L, t, oldasize); /* array back to its original size */ + luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */ + } if (nasize < oldasize) { /* array part must shrink? */ t->sizearray = nasize; /* re-insert elements from vanishing slice */ @@ -695,13 +714,13 @@ void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { } -static int unbound_search (Table *t, unsigned int j) { - unsigned int i = j; /* i is zero or a present index */ +static lua_Unsigned unbound_search (Table *t, lua_Unsigned j) { + lua_Unsigned i = j; /* i is zero or a present index */ j++; /* find 'i' and 'j' such that i is present and j is not */ while (!ttisnil(luaH_getint(t, j))) { i = j; - if (j > cast(unsigned int, MAX_INT)/2) { /* overflow? */ + if (j > l_castS2U(LUA_MAXINTEGER) / 2) { /* overflow? */ /* table was built with bad purposes: resort to linear search */ i = 1; while (!ttisnil(luaH_getint(t, i))) i++; @@ -711,7 +730,7 @@ static int unbound_search (Table *t, unsigned int j) { } /* now do a binary search between them */ while (j - i > 1) { - unsigned int m = (i+j)/2; + lua_Unsigned m = (i+j)/2; if (ttisnil(luaH_getint(t, m))) j = m; else i = m; } diff --git a/src/ltablib.c b/src/ltablib.c index cb8bc16..826828c 100644 --- a/src/ltablib.c +++ b/src/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $ +** $Id: ltablib.c,v 1.93.1.1 2017/04/19 17:20:42 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ diff --git a/src/ltm.c b/src/ltm.c index 95b9b24..6c695bf 100644 --- a/src/ltm.c +++ b/src/ltm.c @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 2.38 2016/12/22 13:08:50 roberto Exp $ +** $Id: ltm.c,v 2.38.1.1 2017/04/19 17:39:34 roberto Exp $ ** Tag methods ** See Copyright Notice in lua.h */ diff --git a/src/lua.c b/src/lua.c index 85c25df..0b9d7df 100644 --- a/src/lua.c +++ b/src/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.230 2017/01/12 17:14:26 roberto Exp $ +** $Id: lua.c,v 1.230.1.1 2017/04/19 17:29:57 roberto Exp $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -153,7 +153,7 @@ static void print_usage (lua_State *L, const char *badoption) { "Available options are:\n" " -e stat execute string 'stat'\n" " -i enter interactive mode after executing 'script'\n" - " -l name require library 'name'\n" + " -l name require library 'name' into global 'name'\n" " -v show version information\n" " -E ignore environment variables\n" " -- stop handling options\n" diff --git a/src/luac.c b/src/luac.c index ea5fdad..55765a1 100644 --- a/src/luac.c +++ b/src/luac.c @@ -1,5 +1,5 @@ /* -** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $ +** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $ ** Lua compiler (saves bytecodes to files; also lists bytecodes) ** See Copyright Notice in lua.h */ @@ -206,7 +206,7 @@ int main(int argc, char* argv[]) } /* -** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $ +** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $ ** print bytecodes ** See Copyright Notice in lua.h */ @@ -373,6 +373,7 @@ static void PrintCode(const Proto* f) case OP_ADD: case OP_SUB: case OP_MUL: + case OP_MOD: case OP_POW: case OP_DIV: case OP_IDIV: diff --git a/src/lundump.c b/src/lundump.c index b989fd5..2ad1670 100644 --- a/src/lundump.c +++ b/src/lundump.c @@ -1,5 +1,5 @@ /* -** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $ +** $Id: lundump.c,v 2.44.1.1 2017/04/19 17:20:42 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/src/lutf8lib.c b/src/lutf8lib.c index de9e3dc..10bd238 100644 --- a/src/lutf8lib.c +++ b/src/lutf8lib.c @@ -1,5 +1,5 @@ /* -** $Id: lutf8lib.c,v 1.16 2016/12/22 13:08:50 roberto Exp $ +** $Id: lutf8lib.c,v 1.16.1.1 2017/04/19 17:29:57 roberto Exp $ ** Standard library for UTF-8 manipulation ** See Copyright Notice in lua.h */ @@ -171,7 +171,7 @@ static int byteoffset (lua_State *L) { } else { if (iscont(s + posi)) - luaL_error(L, "initial position is a continuation byte"); + return luaL_error(L, "initial position is a continuation byte"); if (n < 0) { while (n < 0 && posi > 0) { /* move back */ do { /* find beginning of previous character */ diff --git a/src/lvm.c b/src/lvm.c index bcdd9bc..e3653aa 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.268 2016/02/05 19:59:14 roberto Exp $ +** $Id: lvm.c,v 2.268.1.1 2017/04/19 17:39:34 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -196,7 +196,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, return; } t = tm; /* else try to access 'tm[key]' */ - if (luaV_fastget(L, t, key, slot, luaH_get)) { /* fast track? */ + if (luaV_fastget(L,t,key,slot,luaH_get)) { /* fast track? */ setobj2s(L, val, slot); /* done */ return; } diff --git a/src/lzio.c b/src/lzio.c index c9e1f49..6f79094 100644 --- a/src/lzio.c +++ b/src/lzio.c @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $ +** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 roberto Exp $ ** Buffered streams ** See Copyright Notice in lua.h */