diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-10 12:09:35 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-10 12:09:35 -0300 |
commit | 94b503d95ef00f1e38b58b024ef45bf8973a8746 (patch) | |
tree | c713558a386934bc1d251f064c8d9fae1fb725c0 /ltable.c | |
parent | bdc85357aa41a9610498232c2cffe7aa191e5cf6 (diff) | |
download | lua-94b503d95ef00f1e38b58b024ef45bf8973a8746.tar.gz lua-94b503d95ef00f1e38b58b024ef45bf8973a8746.tar.bz2 lua-94b503d95ef00f1e38b58b024ef45bf8973a8746.zip |
Encoding of table indices (hres) must use C indices
As the encoding of array indices is (~index), 0 is encoded as -1 and
INT_MAX is encoded as INT_MIN.
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -384,7 +384,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { | |||
384 | int tag = *getArrTag(t, i); | 384 | int tag = *getArrTag(t, i); |
385 | if (!tagisempty(tag)) { /* a non-empty entry? */ | 385 | if (!tagisempty(tag)) { /* a non-empty entry? */ |
386 | setivalue(s2v(key), i + 1); | 386 | setivalue(s2v(key), i + 1); |
387 | farr2val(t, i + 1, tag, s2v(key + 1)); | 387 | farr2val(t, i, tag, s2v(key + 1)); |
388 | return 1; | 388 | return 1; |
389 | } | 389 | } |
390 | } | 390 | } |
@@ -692,7 +692,7 @@ static void reinsertOldSlice (lua_State *L, Table *t, unsigned oldasize, | |||
692 | int tag = *getArrTag(t, i); | 692 | int tag = *getArrTag(t, i); |
693 | if (!tagisempty(tag)) { /* a non-empty entry? */ | 693 | if (!tagisempty(tag)) { /* a non-empty entry? */ |
694 | TValue aux; | 694 | TValue aux; |
695 | farr2val(t, i + 1, tag, &aux); /* copy entry into 'aux' */ | 695 | farr2val(t, i, tag, &aux); /* copy entry into 'aux' */ |
696 | luaH_setint(L, t, i + 1, &aux); /* re-insert it into the table */ | 696 | luaH_setint(L, t, i + 1, &aux); /* re-insert it into the table */ |
697 | } | 697 | } |
698 | } | 698 | } |
@@ -937,7 +937,7 @@ int luaH_getint (Table *t, lua_Integer key, TValue *res) { | |||
937 | if (keyinarray(t, key)) { | 937 | if (keyinarray(t, key)) { |
938 | int tag = *getArrTag(t, key - 1); | 938 | int tag = *getArrTag(t, key - 1); |
939 | if (!tagisempty(tag)) | 939 | if (!tagisempty(tag)) |
940 | farr2val(t, key, tag, res); | 940 | farr2val(t, key - 1, tag, res); |
941 | return tag; | 941 | return tag; |
942 | } | 942 | } |
943 | else | 943 | else |
@@ -1048,11 +1048,11 @@ int luaH_psetint (Table *t, lua_Integer key, TValue *val) { | |||
1048 | if (keyinarray(t, key)) { | 1048 | if (keyinarray(t, key)) { |
1049 | lu_byte *tag = getArrTag(t, key - 1); | 1049 | lu_byte *tag = getArrTag(t, key - 1); |
1050 | if (!tagisempty(*tag) || checknoTM(t->metatable, TM_NEWINDEX)) { | 1050 | if (!tagisempty(*tag) || checknoTM(t->metatable, TM_NEWINDEX)) { |
1051 | fval2arr(t, key, tag, val); | 1051 | fval2arr(t, key - 1, tag, val); |
1052 | return HOK; /* success */ | 1052 | return HOK; /* success */ |
1053 | } | 1053 | } |
1054 | else | 1054 | else |
1055 | return ~cast_int(key); /* empty slot in the array part */ | 1055 | return ~cast_int(key - 1); /* empty slot in the array part */ |
1056 | } | 1056 | } |
1057 | else | 1057 | else |
1058 | return finishnodeset(t, getintfromhash(t, key), val); | 1058 | return finishnodeset(t, getintfromhash(t, key), val); |
@@ -1126,7 +1126,7 @@ void luaH_set (lua_State *L, Table *t, const TValue *key, TValue *value) { | |||
1126 | */ | 1126 | */ |
1127 | void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { | 1127 | void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { |
1128 | if (keyinarray(t, key)) | 1128 | if (keyinarray(t, key)) |
1129 | obj2arr(t, key, value); | 1129 | obj2arr(t, key - 1, value); |
1130 | else { | 1130 | else { |
1131 | int ok = rawfinishnodeset(getintfromhash(t, key), value); | 1131 | int ok = rawfinishnodeset(getintfromhash(t, key), value); |
1132 | if (!ok) { | 1132 | if (!ok) { |