Преглед на файлове

no need to check whether libraries and host use the same kernel;
Lua should work correctly with several copies of the kernel

Roberto Ierusalimschy преди 7 години
родител
ревизия
af70905246
променени са 6 файла, в които са добавени 18 реда и са изтрити 23 реда
  1. 4 5
      lapi.c
  2. 4 6
      lauxlib.c
  3. 2 2
      lmem.c
  4. 5 6
      lstate.c
  5. 1 2
      lstate.h
  6. 2 2
      lua.h

+ 4 - 5
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.293 2018/06/15 17:30:52 roberto Exp roberto $
+** $Id: lapi.c,v 2.294 2018/06/15 19:31:22 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -138,10 +138,9 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
 }
 
 
-LUA_API const lua_Number *lua_version (lua_State *L) {
-  static const lua_Number version = LUA_VERSION_NUM;
-  if (L == NULL) return &version;
-  else return G(L)->version;
+LUA_API lua_Number lua_version (lua_State *L) {
+  UNUSED(L);
+  return LUA_VERSION_NUM;
 }
 
 

+ 4 - 6
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.293 2018/02/21 13:48:44 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.294 2018/02/27 18:47:32 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -950,13 +950,11 @@ LUALIB_API lua_State *luaL_newstate (void) {
 
 
 LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {
-  const lua_Number *v = lua_version(L);
+  lua_Number v = lua_version(L);
   if (sz != LUAL_NUMSIZES)  /* check numeric types */
     luaL_error(L, "core and library have incompatible numeric types");
-  if (v != lua_version(NULL))
-    luaL_error(L, "multiple Lua VMs detected");
-  else if (*v != ver)
+  else if (v != ver)
     luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
-                  (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);
+                  (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)v);
 }
 

+ 2 - 2
lmem.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.c,v 1.96 2018/01/28 15:13:26 roberto Exp roberto $
+** $Id: lmem.c,v 1.97 2018/05/30 14:25:52 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -123,7 +123,7 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) {
 static void *tryagain (lua_State *L, void *block,
                        size_t osize, size_t nsize) {
   global_State *g = G(L);
-  if (g->version) {  /* is state fully build? */
+  if (ttisnil(&g->nilvalue)) {  /* is state fully build? */
     luaC_fullgc(L, 1);  /* try to free some memory... */
     return (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */
   }

+ 5 - 6
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 2.153 2018/06/01 17:40:38 roberto Exp roberto $
+** $Id: lstate.c,v 2.154 2018/06/15 19:31:22 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -215,7 +215,7 @@ static void init_registry (lua_State *L, global_State *g) {
 
 /*
 ** open parts of the state that may cause memory-allocation errors.
-** ('g->version' != NULL flags that the state was completely build)
+** ('ttisnil(&g->nilvalue)'' flags that the state was completely build)
 */
 static void f_luaopen (lua_State *L, void *ud) {
   global_State *g = G(L);
@@ -226,7 +226,7 @@ static void f_luaopen (lua_State *L, void *ud) {
   luaT_init(L);
   luaX_init(L);
   g->gcrunning = 1;  /* allow gc */
-  g->version = lua_version(NULL);
+  setnilvalue(&g->nilvalue);
   luai_userstateopen(L);
 }
 
@@ -260,7 +260,7 @@ static void close_state (lua_State *L) {
   global_State *g = G(L);
   luaF_close(L, L->stack);  /* close all upvalues for this thread */
   luaC_freeallobjects(L);  /* collect all objects */
-  if (g->version)  /* closing a fully built state? */
+  if (ttisnil(&g->nilvalue))  /* closing a fully built state? */
     luai_userstateclose(L);
   luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
   freestack(L);
@@ -332,7 +332,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
   g->strt.hash = NULL;
   setnilvalue(&g->l_registry);
   g->panic = NULL;
-  g->version = NULL;
   g->gcstate = GCSpause;
   g->gckind = KGC_INC;
   g->gcemergency = 0;
@@ -345,7 +344,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
   g->twups = NULL;
   g->totalbytes = sizeof(LG);
   g->GCdebt = 0;
-  setnilvalue(&g->nilvalue);
+  setivalue(&g->nilvalue, 0);  /* to signal that state is not yet built */
   setgcparam(g->gcpause, LUAI_GCPAUSE);
   setgcparam(g->gcstepmul, LUAI_GCMUL);
   g->gcstepsize = LUAI_GCSTEPSIZE;

+ 1 - 2
lstate.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.h,v 2.158 2018/03/16 15:33:34 roberto Exp roberto $
+** $Id: lstate.h,v 2.159 2018/06/15 19:31:22 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -181,7 +181,6 @@ typedef struct global_State {
   struct lua_State *twups;  /* list of threads with open upvalues */
   lua_CFunction panic;  /* to be called in unprotected errors */
   struct lua_State *mainthread;
-  const lua_Number *version;  /* pointer to version number */
   TString *memerrmsg;  /* message for memory-allocation errors */
   TString *tmname[TM_N];  /* array with tag-method names */
   struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */

+ 2 - 2
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.345 2018/03/16 15:33:34 roberto Exp roberto $
+** $Id: lua.h,v 1.346 2018/04/04 14:23:41 roberto Exp roberto $
 ** Lua - A Scripting Language
 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
 ** See Copyright Notice at the end of this file
@@ -149,7 +149,7 @@ LUA_API lua_State *(lua_newthread) (lua_State *L);
 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
 
 
-LUA_API const lua_Number *(lua_version) (lua_State *L);
+LUA_API lua_Number (lua_version) (lua_State *L);
 
 
 /*