فهرست منبع

no more 'luaO_nilobject' to avoid comparison of global variable addresses
(now uses static variables)

Roberto Ierusalimschy 7 سال پیش
والد
کامیت
505fc91222
5فایلهای تغییر یافته به همراه12 افزوده شده و 20 حذف شده
  1. 5 3
      lapi.c
  2. 1 5
      lobject.c
  3. 1 7
      lobject.h
  4. 2 3
      lstate.c
  5. 3 2
      ltm.c

+ 5 - 3
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.290 2018/02/27 20:01:55 roberto Exp roberto $
+** $Id: lapi.c,v 2.291 2018/04/04 14:23:41 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -38,10 +38,12 @@ const char lua_ident[] =
 
 
 /* value at a non-valid index */
-#define NONVALIDVALUE		cast(TValue *, luaO_nilobject)
+
+static const TValue nonvalidvaluep = {NILCONSTANT};
+#define NONVALIDVALUE		cast(TValue *, &nonvalidvaluep)
 
 /* corresponding test */
-#define isvalid(o)	((o) != luaO_nilobject)
+#define isvalid(o)	((o) != &nonvalidvaluep)
 
 /* test for pseudo index */
 #define ispseudo(i)		((i) <= LUA_REGISTRYINDEX)

+ 1 - 5
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 2.124 2018/02/27 18:47:32 roberto Exp roberto $
+** $Id: lobject.c,v 2.125 2018/04/25 16:26:20 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -29,10 +29,6 @@
 #include "lvm.h"
 
 
-
-LUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT};
-
-
 /*
 ** converts an integer to a "floating point byte", represented as
 ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if

+ 1 - 7
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 2.142 2018/04/04 14:23:41 roberto Exp roberto $
+** $Id: lobject.h,v 2.143 2018/06/01 16:51:34 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -150,10 +150,6 @@ typedef StackValue *StkId;  /* index to stack elements */
 #define setnilvalue(obj) settt_(obj, LUA_TNIL)
 
 
-/* (address of) a fixed nil value */
-#define luaO_nilobject		(&luaO_nilobject_)
-
-
 /*
 ** Variant tag, used only in tables to signal an empty slot
 ** (which might be different from a slot containing nil)
@@ -730,8 +726,6 @@ typedef struct Table {
 #define sizenode(t)	(twoto((t)->lsizenode))
 
 
-LUAI_DDEC const TValue luaO_nilobject_;
-
 /* size of buffer for 'luaO_utf8esc' function */
 #define UTF8BUFFSZ	8
 

+ 2 - 3
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 2.151 2018/02/05 17:11:37 roberto Exp roberto $
+** $Id: lstate.c,v 2.152 2018/05/29 18:02:51 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -69,12 +69,11 @@ typedef struct LG {
     memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }
 
 static unsigned int luai_makeseed (lua_State *L) {
-  char buff[4 * sizeof(size_t)];
+  char buff[3 * sizeof(size_t)];
   unsigned int h = cast_uint(time(NULL));
   int p = 0;
   addbuff(buff, p, L);  /* heap variable */
   addbuff(buff, p, &h);  /* local variable */
-  addbuff(buff, p, luaO_nilobject);  /* global variable */
   addbuff(buff, p, &lua_newstate);  /* public function */
   lua_assert(p == sizeof(buff));
   return luaS_hash(buff, p, h);

+ 3 - 2
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 2.66 2018/02/27 17:48:28 roberto Exp roberto $
+** $Id: ltm.c,v 2.67 2018/04/04 14:23:41 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -69,6 +69,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
 
 
 const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
+  static const TValue nilobject = {NILCONSTANT};
   Table *mt;
   switch (ttype(o)) {
     case LUA_TTABLE:
@@ -80,7 +81,7 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
     default:
       mt = G(L)->mt[ttype(o)];
   }
-  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);
+  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : &nilobject);
 }