diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-04 11:08:42 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-04 11:08:42 -0300 |
commit | 23051e830a8b212f831443eb888e93e30fa8bb19 (patch) | |
tree | 782f56415ad3a8799c4dea8d6d329f1550d3d7c3 /lcode.c | |
parent | f15589f3b0da477e5dda8863cbf4c0b36469e36d (diff) | |
download | lua-23051e830a8b212f831443eb888e93e30fa8bb19.tar.gz lua-23051e830a8b212f831443eb888e93e30fa8bb19.tar.bz2 lua-23051e830a8b212f831443eb888e93e30fa8bb19.zip |
Changes in the API of 'luaH_set' and related functions
Functions to set values in a table (luaH_set, luaH_newkey, etc.) receive
the new value, instead of returning a slot where to put the value.
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -545,11 +545,14 @@ static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) { | |||
545 | ** and try to reuse constants. Because some values should not be used | 545 | ** and try to reuse constants. Because some values should not be used |
546 | ** as keys (nil cannot be a key, integer keys can collapse with float | 546 | ** as keys (nil cannot be a key, integer keys can collapse with float |
547 | ** keys), the caller must provide a useful 'key' for indexing the cache. | 547 | ** keys), the caller must provide a useful 'key' for indexing the cache. |
548 | ** Note that all functions share the same table, so entering or exiting | ||
549 | ** a function can make some indices wrong. | ||
548 | */ | 550 | */ |
549 | static int addk (FuncState *fs, TValue *key, TValue *v) { | 551 | static int addk (FuncState *fs, TValue *key, TValue *v) { |
552 | TValue val; | ||
550 | lua_State *L = fs->ls->L; | 553 | lua_State *L = fs->ls->L; |
551 | Proto *f = fs->f; | 554 | Proto *f = fs->f; |
552 | TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */ | 555 | const TValue *idx = luaH_get(fs->ls->h, key); /* query scanner table */ |
553 | int k, oldsize; | 556 | int k, oldsize; |
554 | if (ttisinteger(idx)) { /* is there an index there? */ | 557 | if (ttisinteger(idx)) { /* is there an index there? */ |
555 | k = cast_int(ivalue(idx)); | 558 | k = cast_int(ivalue(idx)); |
@@ -563,7 +566,8 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { | |||
563 | k = fs->nk; | 566 | k = fs->nk; |
564 | /* numerical value does not need GC barrier; | 567 | /* numerical value does not need GC barrier; |
565 | table has no metatable, so it does not need to invalidate cache */ | 568 | table has no metatable, so it does not need to invalidate cache */ |
566 | setivalue(idx, k); | 569 | setivalue(&val, k); |
570 | luaH_finishset(L, fs->ls->h, key, idx, &val); | ||
567 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); | 571 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); |
568 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); | 572 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
569 | setobj(L, &f->k[k], v); | 573 | setobj(L, &f->k[k], v); |