@@ -353,7 +353,7 @@ LUA_API void lua_arith (lua_State *L, int op) {
353353 }
354354 /* first operand at top - 2, second at top - 1; result go to top - 2 */
355355 luaO_arith (L , op , s2v (L -> top .p - 2 ), s2v (L -> top .p - 1 ), L -> top .p - 2 );
356- L -> top .p -- ; /* remove second operand */
356+ L -> top .p -- ; /* pop second operand */
357357 lua_unlock (L );
358358}
359359
@@ -666,47 +666,49 @@ LUA_API int lua_pushthread (lua_State *L) {
666666
667667
668668static int auxgetstr (lua_State * L , const TValue * t , const char * k ) {
669- TValue aux ;
669+ int tag ;
670670 TString * str = luaS_new (L , k );
671- luaV_fastget (t , str , s2v (L -> top .p ), luaH_getstr , aux );
672- if (!isemptyV ( aux )) {
671+ luaV_fastget (t , str , s2v (L -> top .p ), luaH_getstr , tag );
672+ if (!tagisempty ( tag )) {
673673 api_incr_top (L );
674674 }
675675 else {
676676 setsvalue2s (L , L -> top .p , str );
677677 api_incr_top (L );
678- luaV_finishget (L , t , s2v (L -> top .p - 1 ), L -> top .p - 1 , aux );
678+ tag = luaV_finishget (L , t , s2v (L -> top .p - 1 ), L -> top .p - 1 , tag );
679679 }
680680 lua_unlock (L );
681- return ttype ( s2v ( L -> top . p - 1 ) );
681+ return novariant ( tag );
682682}
683683
684684
685- static TValue getGlobalTable (lua_State * L ) {
685+ static void getGlobalTable (lua_State * L , TValue * gt ) {
686686 Table * registry = hvalue (& G (L )-> l_registry );
687- return luaH_getint (registry , LUA_RIDX_GLOBALS );
687+ int tag = luaH_getint (registry , LUA_RIDX_GLOBALS , gt );
688+ (void )tag ; /* avoid not-used warnings when checks are off */
689+ api_check (L , novariant (tag ) == LUA_TTABLE , "global table must exist" );
688690}
689691
690692
691693LUA_API int lua_getglobal (lua_State * L , const char * name ) {
692694 TValue gt ;
693695 lua_lock (L );
694- gt = getGlobalTable (L );
696+ getGlobalTable (L , & gt );
695697 return auxgetstr (L , & gt , name );
696698}
697699
698700
699701LUA_API int lua_gettable (lua_State * L , int idx ) {
700- TValue aux ;
702+ int tag ;
701703 TValue * t ;
702704 lua_lock (L );
703705 api_checkpop (L , 1 );
704706 t = index2value (L , idx );
705- luaV_fastget (t , s2v (L -> top .p - 1 ), s2v (L -> top .p - 1 ), luaH_get , aux );
706- if (isemptyV ( aux ))
707- luaV_finishget (L , t , s2v (L -> top .p - 1 ), L -> top .p - 1 , aux );
707+ luaV_fastget (t , s2v (L -> top .p - 1 ), s2v (L -> top .p - 1 ), luaH_get , tag );
708+ if (tagisempty ( tag ))
709+ tag = luaV_finishget (L , t , s2v (L -> top .p - 1 ), L -> top .p - 1 , tag );
708710 lua_unlock (L );
709- return ttype ( s2v ( L -> top . p - 1 ) );
711+ return novariant ( tag );
710712}
711713
712714
@@ -718,29 +720,27 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {
718720
719721LUA_API int lua_geti (lua_State * L , int idx , lua_Integer n ) {
720722 TValue * t ;
721- TValue aux ;
723+ int tag ;
722724 lua_lock (L );
723725 t = index2value (L , idx );
724- luaV_fastgeti (t , n , s2v (L -> top .p ), aux );
725- if (isemptyV ( aux )) {
726+ luaV_fastgeti (t , n , s2v (L -> top .p ), tag );
727+ if (tagisempty ( tag )) {
726728 TValue key ;
727729 setivalue (& key , n );
728- luaV_finishget (L , t , & key , L -> top .p , aux );
730+ tag = luaV_finishget (L , t , & key , L -> top .p , tag );
729731 }
730732 api_incr_top (L );
731733 lua_unlock (L );
732- return ttype ( s2v ( L -> top . p - 1 ) );
734+ return novariant ( tag );
733735}
734736
735737
736- l_sinline int finishrawget (lua_State * L , TValue res ) {
737- if (isemptyV ( res )) /* avoid copying empty items to the stack */
738+ static int finishrawget (lua_State * L , int tag ) {
739+ if (tagisempty ( tag )) /* avoid copying empty items to the stack */
738740 setnilvalue (s2v (L -> top .p ));
739- else
740- setobjV (L , s2v (L -> top .p ), res );
741741 api_incr_top (L );
742742 lua_unlock (L );
743- return ttypeV ( res );
743+ return novariant ( tag );
744744}
745745
746746
@@ -753,23 +753,23 @@ l_sinline Table *gettable (lua_State *L, int idx) {
753753
754754LUA_API int lua_rawget (lua_State * L , int idx ) {
755755 Table * t ;
756- TValue res ;
756+ int tag ;
757757 lua_lock (L );
758758 api_checkpop (L , 1 );
759759 t = gettable (L , idx );
760- res = luaH_get (t , s2v (L -> top .p - 1 ));
760+ tag = luaH_get (t , s2v ( L -> top . p - 1 ) , s2v (L -> top .p - 1 ));
761761 L -> top .p -- ; /* pop key */
762- return finishrawget (L , res );
762+ return finishrawget (L , tag );
763763}
764764
765765
766766LUA_API int lua_rawgeti (lua_State * L , int idx , lua_Integer n ) {
767767 Table * t ;
768- TValue aux ;
768+ int tag ;
769769 lua_lock (L );
770770 t = gettable (L , idx );
771- luaH_fastgeti (t , n , s2v (L -> top .p ), aux );
772- return finishrawget (L , aux );
771+ luaH_fastgeti (t , n , s2v (L -> top .p ), tag );
772+ return finishrawget (L , tag );
773773}
774774
775775
@@ -779,7 +779,7 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {
779779 lua_lock (L );
780780 t = gettable (L , idx );
781781 setpvalue (& k , cast_voidp (p ));
782- return finishrawget (L , luaH_get (t , & k ));
782+ return finishrawget (L , luaH_get (t , & k , s2v ( L -> top . p ) ));
783783}
784784
785785
@@ -872,7 +872,7 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
872872LUA_API void lua_setglobal (lua_State * L , const char * name ) {
873873 TValue gt ;
874874 lua_lock (L ); /* unlock done in 'auxsetstr' */
875- gt = getGlobalTable (L );
875+ getGlobalTable (L , & gt );
876876 auxsetstr (L , & gt , name );
877877}
878878
@@ -1122,7 +1122,8 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
11221122 LClosure * f = clLvalue (s2v (L -> top .p - 1 )); /* get new function */
11231123 if (f -> nupvalues >= 1 ) { /* does it have an upvalue? */
11241124 /* get global table from registry */
1125- TValue gt = getGlobalTable (L );
1125+ TValue gt ;
1126+ getGlobalTable (L , & gt );
11261127 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
11271128 setobj (L , f -> upvals [0 ]-> v .p , & gt );
11281129 luaC_barrier (L , f -> upvals [0 ], & gt );
@@ -1266,7 +1267,7 @@ LUA_API int lua_next (lua_State *L, int idx) {
12661267 if (more )
12671268 api_incr_top (L );
12681269 else /* no more elements */
1269- L -> top .p -= 1 ; /* remove key */
1270+ L -> top .p -- ; /* pop key */
12701271 lua_unlock (L );
12711272 return more ;
12721273}
0 commit comments