diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-01-21 13:33:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-01-21 13:33:59 -0300 |
commit | 7d7ae8781e64e2b3b212d5c7b7c1b98b694df5ef (patch) | |
tree | a29433a8a29cd79ec3c8abc308c133e81d4259c6 | |
parent | 724012d3d07f43f03451bb05d2bd9f55dff1d116 (diff) | |
download | lua-7d7ae8781e64e2b3b212d5c7b7c1b98b694df5ef.tar.gz lua-7d7ae8781e64e2b3b212d5c7b7c1b98b694df5ef.tar.bz2 lua-7d7ae8781e64e2b3b212d5c7b7c1b98b694df5ef.zip |
Parameters for 'lua_createtable' back to int
Tables don't accept sizes larger than int.
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | ltablib.c | 8 | ||||
-rw-r--r-- | ltests.c | 6 | ||||
-rw-r--r-- | lua.c | 2 | ||||
-rw-r--r-- | lua.h | 2 | ||||
-rw-r--r-- | manual/manual.of | 6 | ||||
-rw-r--r-- | testes/sort.lua | 6 |
7 files changed, 18 insertions, 16 deletions
@@ -782,14 +782,14 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { | |||
782 | } | 782 | } |
783 | 783 | ||
784 | 784 | ||
785 | LUA_API void lua_createtable (lua_State *L, unsigned narray, unsigned nrec) { | 785 | LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { |
786 | Table *t; | 786 | Table *t; |
787 | lua_lock(L); | 787 | lua_lock(L); |
788 | t = luaH_new(L); | 788 | t = luaH_new(L); |
789 | sethvalue2s(L, L->top.p, t); | 789 | sethvalue2s(L, L->top.p, t); |
790 | api_incr_top(L); | 790 | api_incr_top(L); |
791 | if (narray > 0 || nrec > 0) | 791 | if (narray > 0 || nrec > 0) |
792 | luaH_resize(L, t, narray, nrec); | 792 | luaH_resize(L, t, cast_uint(narray), cast_uint(nrec)); |
793 | luaC_checkGC(L); | 793 | luaC_checkGC(L); |
794 | lua_unlock(L); | 794 | lua_unlock(L); |
795 | } | 795 | } |
@@ -62,9 +62,9 @@ static void checktab (lua_State *L, int arg, int what) { | |||
62 | static int tcreate (lua_State *L) { | 62 | static int tcreate (lua_State *L) { |
63 | lua_Unsigned sizeseq = (lua_Unsigned)luaL_checkinteger(L, 1); | 63 | lua_Unsigned sizeseq = (lua_Unsigned)luaL_checkinteger(L, 1); |
64 | lua_Unsigned sizerest = (lua_Unsigned)luaL_optinteger(L, 2, 0); | 64 | lua_Unsigned sizerest = (lua_Unsigned)luaL_optinteger(L, 2, 0); |
65 | luaL_argcheck(L, sizeseq <= UINT_MAX, 1, "out of range"); | 65 | luaL_argcheck(L, sizeseq <= cast_uint(INT_MAX), 1, "out of range"); |
66 | luaL_argcheck(L, sizerest <= UINT_MAX, 2, "out of range"); | 66 | luaL_argcheck(L, sizerest <= cast_uint(INT_MAX), 2, "out of range"); |
67 | lua_createtable(L, (unsigned)sizeseq, (unsigned)sizerest); | 67 | lua_createtable(L, cast_int(sizeseq), cast_int(sizerest)); |
68 | return 1; | 68 | return 1; |
69 | } | 69 | } |
70 | 70 | ||
@@ -192,7 +192,7 @@ static int tconcat (lua_State *L) { | |||
192 | static int tpack (lua_State *L) { | 192 | static int tpack (lua_State *L) { |
193 | int i; | 193 | int i; |
194 | int n = lua_gettop(L); /* number of elements to pack */ | 194 | int n = lua_gettop(L); /* number of elements to pack */ |
195 | lua_createtable(L, cast_uint(n), 1); /* create result table */ | 195 | lua_createtable(L, n, 1); /* create result table */ |
196 | lua_insert(L, 1); /* put it at index 1 */ | 196 | lua_insert(L, 1); /* put it at index 1 */ |
197 | for (i = n; i >= 1; i--) /* assign elements */ | 197 | for (i = n; i >= 1; i--) /* assign elements */ |
198 | lua_seti(L, 1, i); | 198 | lua_seti(L, 1, i); |
@@ -809,7 +809,7 @@ static int listk (lua_State *L) { | |||
809 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 809 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
810 | 1, "Lua function expected"); | 810 | 1, "Lua function expected"); |
811 | p = getproto(obj_at(L, 1)); | 811 | p = getproto(obj_at(L, 1)); |
812 | lua_createtable(L, cast_uint(p->sizek), 0); | 812 | lua_createtable(L, p->sizek, 0); |
813 | for (i=0; i<p->sizek; i++) { | 813 | for (i=0; i<p->sizek; i++) { |
814 | pushobject(L, p->k+i); | 814 | pushobject(L, p->k+i); |
815 | lua_rawseti(L, -2, i+1); | 815 | lua_rawseti(L, -2, i+1); |
@@ -825,7 +825,7 @@ static int listabslineinfo (lua_State *L) { | |||
825 | 1, "Lua function expected"); | 825 | 1, "Lua function expected"); |
826 | p = getproto(obj_at(L, 1)); | 826 | p = getproto(obj_at(L, 1)); |
827 | luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info"); | 827 | luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info"); |
828 | lua_createtable(L, 2u * cast_uint(p->sizeabslineinfo), 0); | 828 | lua_createtable(L, 2 * p->sizeabslineinfo, 0); |
829 | for (i=0; i < p->sizeabslineinfo; i++) { | 829 | for (i=0; i < p->sizeabslineinfo; i++) { |
830 | lua_pushinteger(L, p->abslineinfo[i].pc); | 830 | lua_pushinteger(L, p->abslineinfo[i].pc); |
831 | lua_rawseti(L, -2, 2 * i + 1); | 831 | lua_rawseti(L, -2, 2 * i + 1); |
@@ -867,7 +867,7 @@ void lua_printstack (lua_State *L) { | |||
867 | 867 | ||
868 | 868 | ||
869 | static int get_limits (lua_State *L) { | 869 | static int get_limits (lua_State *L) { |
870 | lua_createtable(L, 0, 6); | 870 | lua_createtable(L, 0, 5); |
871 | setnameval(L, "IS32INT", LUAI_IS32INT); | 871 | setnameval(L, "IS32INT", LUAI_IS32INT); |
872 | setnameval(L, "MAXARG_Ax", MAXARG_Ax); | 872 | setnameval(L, "MAXARG_Ax", MAXARG_Ax); |
873 | setnameval(L, "MAXARG_Bx", MAXARG_Bx); | 873 | setnameval(L, "MAXARG_Bx", MAXARG_Bx); |
@@ -185,7 +185,7 @@ static void print_version (void) { | |||
185 | static void createargtable (lua_State *L, char **argv, int argc, int script) { | 185 | static void createargtable (lua_State *L, char **argv, int argc, int script) { |
186 | int i, narg; | 186 | int i, narg; |
187 | narg = argc - (script + 1); /* number of positive indices */ | 187 | narg = argc - (script + 1); /* number of positive indices */ |
188 | lua_createtable(L, cast_uint(narg), cast_uint(script + 1)); | 188 | lua_createtable(L, narg, script + 1); |
189 | for (i = 0; i < argc; i++) { | 189 | for (i = 0; i < argc; i++) { |
190 | lua_pushstring(L, argv[i]); | 190 | lua_pushstring(L, argv[i]); |
191 | lua_rawseti(L, -2, i - script); | 191 | lua_rawseti(L, -2, i - script); |
@@ -267,7 +267,7 @@ LUA_API int (lua_rawget) (lua_State *L, int idx); | |||
267 | LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n); | 267 | LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n); |
268 | LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p); | 268 | LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p); |
269 | 269 | ||
270 | LUA_API void (lua_createtable) (lua_State *L, unsigned narr, unsigned nrec); | 270 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); |
271 | LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue); | 271 | LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue); |
272 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); | 272 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); |
273 | LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n); | 273 | LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n); |
diff --git a/manual/manual.of b/manual/manual.of index 77e37de3..150315d4 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -3238,7 +3238,7 @@ Values at other positions are not affected. | |||
3238 | 3238 | ||
3239 | } | 3239 | } |
3240 | 3240 | ||
3241 | @APIEntry{void lua_createtable (lua_State *L, unsigned nseq, unsigned nrec);| | 3241 | @APIEntry{void lua_createtable (lua_State *L, int nseq, int nrec);| |
3242 | @apii{0,1,m} | 3242 | @apii{0,1,m} |
3243 | 3243 | ||
3244 | Creates a new empty table and pushes it onto the stack. | 3244 | Creates a new empty table and pushes it onto the stack. |
@@ -3249,7 +3249,7 @@ the table will have. | |||
3249 | Lua may use these hints to preallocate memory for the new table. | 3249 | Lua may use these hints to preallocate memory for the new table. |
3250 | This preallocation may help performance when you know in advance | 3250 | This preallocation may help performance when you know in advance |
3251 | how many elements the table will have. | 3251 | how many elements the table will have. |
3252 | Otherwise you can use the function @Lid{lua_newtable}. | 3252 | Otherwise you should use the function @Lid{lua_newtable}. |
3253 | 3253 | ||
3254 | } | 3254 | } |
3255 | 3255 | ||
@@ -3351,7 +3351,7 @@ Returns the previous mode (@id{LUA_GCGEN} or @id{LUA_GCINC}). | |||
3351 | 3351 | ||
3352 | @item{@defid{LUA_GCPARAM} (int param, int val)| | 3352 | @item{@defid{LUA_GCPARAM} (int param, int val)| |
3353 | Changes and/or returns the value of a parameter of the collector. | 3353 | Changes and/or returns the value of a parameter of the collector. |
3354 | If @id{val} is negative, the call only returns the current value. | 3354 | If @id{val} is -1, the call only returns the current value. |
3355 | The argument @id{param} must have one of the following values: | 3355 | The argument @id{param} must have one of the following values: |
3356 | @description{ | 3356 | @description{ |
3357 | @item{@defid{LUA_GCPMINORMUL}| The minor multiplier. } | 3357 | @item{@defid{LUA_GCPMINORMUL}| The minor multiplier. } |
diff --git a/testes/sort.lua b/testes/sort.lua index 442b3129..965e1534 100644 --- a/testes/sort.lua +++ b/testes/sort.lua | |||
@@ -35,8 +35,10 @@ do print "testing 'table.create'" | |||
35 | assert(memdiff > 1024 * 12) | 35 | assert(memdiff > 1024 * 12) |
36 | assert(not T or select(2, T.querytab(t)) == 1024) | 36 | assert(not T or select(2, T.querytab(t)) == 1024) |
37 | 37 | ||
38 | checkerror("table overflow", table.create, (1<<31) + 1) | 38 | local maxint1 = 1 << (string.packsize("i") * 8 - 1) |
39 | checkerror("table overflow", table.create, 0, (1<<31) + 1) | 39 | checkerror("out of range", table.create, maxint1) |
40 | checkerror("out of range", table.create, 0, maxint1) | ||
41 | checkerror("table overflow", table.create, 0, maxint1 - 1) | ||
40 | end | 42 | end |
41 | 43 | ||
42 | 44 | ||