lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 7d7ae8781e64e2b3b212d5c7b7c1b98b694df5ef
parent 724012d3d07f43f03451bb05d2bd9f55dff1d116
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue, 21 Jan 2025 13:33:32 -0300

Parameters for 'lua_createtable' back to int

Tables don't accept sizes larger than int.

Diffstat:
Mlapi.c | 4++--
Mltablib.c | 8++++----
Mltests.c | 6+++---
Mlua.c | 2+-
Mlua.h | 2+-
Mmanual/manual.of | 6+++---
Mtestes/sort.lua | 6++++--
7 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/lapi.c b/lapi.c @@ -782,14 +782,14 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { } -LUA_API void lua_createtable (lua_State *L, unsigned narray, unsigned nrec) { +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { Table *t; lua_lock(L); t = luaH_new(L); sethvalue2s(L, L->top.p, t); api_incr_top(L); if (narray > 0 || nrec > 0) - luaH_resize(L, t, narray, nrec); + luaH_resize(L, t, cast_uint(narray), cast_uint(nrec)); luaC_checkGC(L); lua_unlock(L); } diff --git a/ltablib.c b/ltablib.c @@ -62,9 +62,9 @@ static void checktab (lua_State *L, int arg, int what) { static int tcreate (lua_State *L) { lua_Unsigned sizeseq = (lua_Unsigned)luaL_checkinteger(L, 1); lua_Unsigned sizerest = (lua_Unsigned)luaL_optinteger(L, 2, 0); - luaL_argcheck(L, sizeseq <= UINT_MAX, 1, "out of range"); - luaL_argcheck(L, sizerest <= UINT_MAX, 2, "out of range"); - lua_createtable(L, (unsigned)sizeseq, (unsigned)sizerest); + luaL_argcheck(L, sizeseq <= cast_uint(INT_MAX), 1, "out of range"); + luaL_argcheck(L, sizerest <= cast_uint(INT_MAX), 2, "out of range"); + lua_createtable(L, cast_int(sizeseq), cast_int(sizerest)); return 1; } @@ -192,7 +192,7 @@ static int tconcat (lua_State *L) { static int tpack (lua_State *L) { int i; int n = lua_gettop(L); /* number of elements to pack */ - lua_createtable(L, cast_uint(n), 1); /* create result table */ + lua_createtable(L, n, 1); /* create result table */ lua_insert(L, 1); /* put it at index 1 */ for (i = n; i >= 1; i--) /* assign elements */ lua_seti(L, 1, i); diff --git a/ltests.c b/ltests.c @@ -809,7 +809,7 @@ static int listk (lua_State *L) { luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, "Lua function expected"); p = getproto(obj_at(L, 1)); - lua_createtable(L, cast_uint(p->sizek), 0); + lua_createtable(L, p->sizek, 0); for (i=0; i<p->sizek; i++) { pushobject(L, p->k+i); lua_rawseti(L, -2, i+1); @@ -825,7 +825,7 @@ static int listabslineinfo (lua_State *L) { 1, "Lua function expected"); p = getproto(obj_at(L, 1)); luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info"); - lua_createtable(L, 2u * cast_uint(p->sizeabslineinfo), 0); + lua_createtable(L, 2 * p->sizeabslineinfo, 0); for (i=0; i < p->sizeabslineinfo; i++) { lua_pushinteger(L, p->abslineinfo[i].pc); lua_rawseti(L, -2, 2 * i + 1); @@ -867,7 +867,7 @@ void lua_printstack (lua_State *L) { static int get_limits (lua_State *L) { - lua_createtable(L, 0, 6); + lua_createtable(L, 0, 5); setnameval(L, "IS32INT", LUAI_IS32INT); setnameval(L, "MAXARG_Ax", MAXARG_Ax); setnameval(L, "MAXARG_Bx", MAXARG_Bx); diff --git a/lua.c b/lua.c @@ -185,7 +185,7 @@ static void print_version (void) { static void createargtable (lua_State *L, char **argv, int argc, int script) { int i, narg; narg = argc - (script + 1); /* number of positive indices */ - lua_createtable(L, cast_uint(narg), cast_uint(script + 1)); + lua_createtable(L, narg, script + 1); for (i = 0; i < argc; i++) { lua_pushstring(L, argv[i]); lua_rawseti(L, -2, i - script); diff --git a/lua.h b/lua.h @@ -267,7 +267,7 @@ LUA_API int (lua_rawget) (lua_State *L, int idx); 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); -LUA_API void (lua_createtable) (lua_State *L, unsigned narr, unsigned nrec); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue); LUA_API int (lua_getmetatable) (lua_State *L, int objindex); LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n); diff --git a/manual/manual.of b/manual/manual.of @@ -3238,7 +3238,7 @@ Values at other positions are not affected. } -@APIEntry{void lua_createtable (lua_State *L, unsigned nseq, unsigned nrec);| +@APIEntry{void lua_createtable (lua_State *L, int nseq, int nrec);| @apii{0,1,m} Creates a new empty table and pushes it onto the stack. @@ -3249,7 +3249,7 @@ the table will have. Lua may use these hints to preallocate memory for the new table. This preallocation may help performance when you know in advance how many elements the table will have. -Otherwise you can use the function @Lid{lua_newtable}. +Otherwise you should use the function @Lid{lua_newtable}. } @@ -3351,7 +3351,7 @@ Returns the previous mode (@id{LUA_GCGEN} or @id{LUA_GCINC}). @item{@defid{LUA_GCPARAM} (int param, int val)| Changes and/or returns the value of a parameter of the collector. -If @id{val} is negative, the call only returns the current value. +If @id{val} is -1, the call only returns the current value. The argument @id{param} must have one of the following values: @description{ @item{@defid{LUA_GCPMINORMUL}| The minor multiplier. } diff --git a/testes/sort.lua b/testes/sort.lua @@ -35,8 +35,10 @@ do print "testing 'table.create'" assert(memdiff > 1024 * 12) assert(not T or select(2, T.querytab(t)) == 1024) - checkerror("table overflow", table.create, (1<<31) + 1) - checkerror("table overflow", table.create, 0, (1<<31) + 1) + local maxint1 = 1 << (string.packsize("i") * 8 - 1) + checkerror("out of range", table.create, maxint1) + checkerror("out of range", table.create, 0, maxint1) + checkerror("table overflow", table.create, 0, maxint1 - 1) end