mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
update lua
This commit is contained in:
@@ -1687,12 +1687,15 @@ static void incstep (lua_State *L, global_State *g) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** performs a basic GC step if collector is running
|
** Performs a basic GC step if collector is running. (If collector is
|
||||||
|
** not running, set a reasonable debt to avoid it being called at
|
||||||
|
** every single check.)
|
||||||
*/
|
*/
|
||||||
void luaC_step (lua_State *L) {
|
void luaC_step (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
lua_assert(!g->gcemergency);
|
if (!gcrunning(g)) /* not running? */
|
||||||
if (gcrunning(g)) { /* running? */
|
luaE_setdebt(g, -2000);
|
||||||
|
else {
|
||||||
if(isdecGCmodegen(g))
|
if(isdecGCmodegen(g))
|
||||||
genstep(L, g);
|
genstep(L, g);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -177,18 +177,19 @@
|
|||||||
#define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0)
|
#define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0)
|
||||||
|
|
||||||
|
|
||||||
#define luaC_barrier(L,p,v) ( \
|
|
||||||
(iscollectable(v) && isblack(p) && ispurewhite(gcvalue(v))) ? \
|
|
||||||
luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))
|
|
||||||
|
|
||||||
#define luaC_barrierback(L,p,v) ( \
|
|
||||||
(iscollectable(v) && isblack(p) && ispurewhite(gcvalue(v))) ? \
|
|
||||||
luaC_barrierback_(L,p) : cast_void(0))
|
|
||||||
|
|
||||||
#define luaC_objbarrier(L,p,o) ( \
|
#define luaC_objbarrier(L,p,o) ( \
|
||||||
(isblack(p) && ispurewhite(o)) ? \
|
(isblack(p) && ispurewhite(o)) ? \
|
||||||
luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))
|
luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))
|
||||||
|
|
||||||
|
#define luaC_barrier(L,p,v) ( \
|
||||||
|
iscollectable(v) ? luaC_objbarrier(L,p,gcvalue(v)) : cast_void(0))
|
||||||
|
|
||||||
|
#define luaC_objbarrierback(L,p,o) ( \
|
||||||
|
(isblack(p) && ispurewhite(o)) ? luaC_barrierback_(L,p) : cast_void(0))
|
||||||
|
|
||||||
|
#define luaC_barrierback(L,p,v) ( \
|
||||||
|
iscollectable(v) ? luaC_objbarrierback(L, p, gcvalue(v)) : cast_void(0))
|
||||||
|
|
||||||
LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);
|
LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);
|
||||||
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
|
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
|
||||||
LUAI_FUNC void luaC_step (lua_State *L);
|
LUAI_FUNC void luaC_step (lua_State *L);
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ static int math_type (lua_State *L) {
|
|||||||
|
|
||||||
/* try to find an integer type with at least 64 bits */
|
/* try to find an integer type with at least 64 bits */
|
||||||
|
|
||||||
#if (ULONG_MAX >> 31 >> 31) >= 3
|
#if ((ULONG_MAX >> 31) >> 31) >= 3
|
||||||
|
|
||||||
/* 'long' has at least 64 bits */
|
/* 'long' has at least 64 bits */
|
||||||
#define Rand64 unsigned long
|
#define Rand64 unsigned long
|
||||||
@@ -277,9 +277,9 @@ static int math_type (lua_State *L) {
|
|||||||
/* there is a 'long long' type (which must have at least 64 bits) */
|
/* there is a 'long long' type (which must have at least 64 bits) */
|
||||||
#define Rand64 unsigned long long
|
#define Rand64 unsigned long long
|
||||||
|
|
||||||
#elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3
|
#elif ((LUA_MAXUNSIGNED >> 31) >> 31) >= 3
|
||||||
|
|
||||||
/* 'lua_Integer' has at least 64 bits */
|
/* 'lua_Unsigned' has at least 64 bits */
|
||||||
#define Rand64 lua_Unsigned
|
#define Rand64 lua_Unsigned
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -500,12 +500,12 @@ static lua_Number I2d (Rand64 x) {
|
|||||||
|
|
||||||
/* convert a 'Rand64' to a 'lua_Unsigned' */
|
/* convert a 'Rand64' to a 'lua_Unsigned' */
|
||||||
static lua_Unsigned I2UInt (Rand64 x) {
|
static lua_Unsigned I2UInt (Rand64 x) {
|
||||||
return ((lua_Unsigned)trim32(x.h) << 31 << 1) | (lua_Unsigned)trim32(x.l);
|
return (((lua_Unsigned)trim32(x.h) << 31) << 1) | (lua_Unsigned)trim32(x.l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert a 'lua_Unsigned' to a 'Rand64' */
|
/* convert a 'lua_Unsigned' to a 'Rand64' */
|
||||||
static Rand64 Int2I (lua_Unsigned n) {
|
static Rand64 Int2I (lua_Unsigned n) {
|
||||||
return packI((lu_int32)(n >> 31 >> 1), (lu_int32)n);
|
return packI((lu_int32)((n >> 31) >> 1), (lu_int32)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* } */
|
#endif /* } */
|
||||||
|
|||||||
@@ -22,25 +22,6 @@
|
|||||||
#include "lstate.h"
|
#include "lstate.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(EMERGENCYGCTESTS)
|
|
||||||
/*
|
|
||||||
** First allocation will fail whenever not building initial state.
|
|
||||||
** (This fail will trigger 'tryagain' and a full GC cycle at every
|
|
||||||
** allocation.)
|
|
||||||
*/
|
|
||||||
static void *firsttry (global_State *g, void *block, size_t os, size_t ns) {
|
|
||||||
if (completestate(g) && ns > 0) /* frees never fail */
|
|
||||||
return NULL; /* fail */
|
|
||||||
else /* normal allocation */
|
|
||||||
return (*g->frealloc)(g->ud, block, os, ns);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define firsttry(g,block,os,ns) ((*g->frealloc)(g->ud, block, os, ns))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** About the realloc function:
|
** About the realloc function:
|
||||||
@@ -60,6 +41,43 @@ static void *firsttry (global_State *g, void *block, size_t os, size_t ns) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Macro to call the allocation function.
|
||||||
|
*/
|
||||||
|
#define callfrealloc(g,block,os,ns) ((*g->frealloc)(g->ud, block, os, ns))
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** When an allocation fails, it will try again after an emergency
|
||||||
|
** collection, except when it cannot run a collection. The GC should
|
||||||
|
** not be called while the state is not fully built, as the collector
|
||||||
|
** is not yet fully initialized. Also, it should not be called when
|
||||||
|
** 'gcstopem' is true, because then the interpreter is in the middle of
|
||||||
|
** a collection step.
|
||||||
|
*/
|
||||||
|
#define cantryagain(g) (completestate(g) && !g->gcstopem)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(EMERGENCYGCTESTS)
|
||||||
|
/*
|
||||||
|
** First allocation will fail except when freeing a block (frees never
|
||||||
|
** fail) and when it cannot try again; this fail will trigger 'tryagain'
|
||||||
|
** and a full GC cycle at every allocation.
|
||||||
|
*/
|
||||||
|
static void *firsttry (global_State *g, void *block, size_t os, size_t ns) {
|
||||||
|
if (ns > 0 && cantryagain(g))
|
||||||
|
return NULL; /* fail */
|
||||||
|
else /* normal allocation */
|
||||||
|
return callfrealloc(g, block, os, ns);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define firsttry(g,block,os,ns) callfrealloc(g, block, os, ns)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -132,7 +150,7 @@ l_noret luaM_toobig (lua_State *L) {
|
|||||||
void luaM_free_ (lua_State *L, void *block, size_t osize) {
|
void luaM_free_ (lua_State *L, void *block, size_t osize) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
lua_assert((osize == 0) == (block == NULL));
|
lua_assert((osize == 0) == (block == NULL));
|
||||||
(*g->frealloc)(g->ud, block, osize, 0);
|
callfrealloc(g, block, osize, 0);
|
||||||
g->GCdebt -= osize;
|
g->GCdebt -= osize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,19 +158,15 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) {
|
|||||||
/*
|
/*
|
||||||
** In case of allocation fail, this function will do an emergency
|
** In case of allocation fail, this function will do an emergency
|
||||||
** collection to free some memory and then try the allocation again.
|
** collection to free some memory and then try the allocation again.
|
||||||
** The GC should not be called while state is not fully built, as the
|
|
||||||
** collector is not yet fully initialized. Also, it should not be called
|
|
||||||
** when 'gcstopem' is true, because then the interpreter is in the
|
|
||||||
** middle of a collection step.
|
|
||||||
*/
|
*/
|
||||||
static void *tryagain (lua_State *L, void *block,
|
static void *tryagain (lua_State *L, void *block,
|
||||||
size_t osize, size_t nsize) {
|
size_t osize, size_t nsize) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
if (completestate(g) && !g->gcstopem) {
|
if (cantryagain(g)) {
|
||||||
luaC_fullgc(L, 1); /* try to free some memory... */
|
luaC_fullgc(L, 1); /* try to free some memory... */
|
||||||
return (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
|
return callfrealloc(g, block, osize, nsize); /* try again */
|
||||||
}
|
}
|
||||||
else return NULL; /* cannot free any memory without a full state */
|
else return NULL; /* cannot run an emergency collection */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -138,12 +138,28 @@
|
|||||||
/* }================================================================== */
|
/* }================================================================== */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Despite claiming to be ISO, the C library in some Apple platforms
|
||||||
|
** does not implement 'system'.
|
||||||
|
*/
|
||||||
|
#if !defined(l_system) && defined(__APPLE__) /* { */
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
|
||||||
|
#define l_system(cmd) ((cmd) == NULL ? 0 : -1)
|
||||||
|
#endif
|
||||||
|
#endif /* } */
|
||||||
|
|
||||||
|
#if !defined(l_system)
|
||||||
|
#define l_system(cmd) system(cmd) /* default definition */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int os_execute (lua_State *L) {
|
static int os_execute (lua_State *L) {
|
||||||
const char *cmd = luaL_optstring(L, 1, NULL);
|
const char *cmd = luaL_optstring(L, 1, NULL);
|
||||||
int stat;
|
int stat;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
stat = system(cmd);
|
stat = l_system(cmd);
|
||||||
if (cmd != NULL)
|
if (cmd != NULL)
|
||||||
return luaL_execresult(L, stat);
|
return luaL_execresult(L, stat);
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Some header files included here need this definition */
|
||||||
|
typedef struct CallInfo CallInfo;
|
||||||
|
|
||||||
|
|
||||||
#include "lobject.h"
|
#include "lobject.h"
|
||||||
#include "ltm.h"
|
#include "ltm.h"
|
||||||
#include "lzio.h"
|
#include "lzio.h"
|
||||||
@@ -169,7 +174,7 @@ typedef struct stringtable {
|
|||||||
** - field 'transferinfo' is used only during call/returnhooks,
|
** - field 'transferinfo' is used only during call/returnhooks,
|
||||||
** before the function starts or after it ends.
|
** before the function starts or after it ends.
|
||||||
*/
|
*/
|
||||||
typedef struct CallInfo {
|
struct CallInfo {
|
||||||
StkIdRel func; /* function index in the stack */
|
StkIdRel func; /* function index in the stack */
|
||||||
StkIdRel top; /* top for this function */
|
StkIdRel top; /* top for this function */
|
||||||
struct CallInfo *previous, *next; /* dynamic call link */
|
struct CallInfo *previous, *next; /* dynamic call link */
|
||||||
@@ -196,7 +201,7 @@ typedef struct CallInfo {
|
|||||||
} u2;
|
} u2;
|
||||||
short nresults; /* expected number of results from this function */
|
short nresults; /* expected number of results from this function */
|
||||||
unsigned short callstatus;
|
unsigned short callstatus;
|
||||||
} CallInfo;
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -290,7 +295,7 @@ typedef struct global_State {
|
|||||||
struct lua_State *mainthread;
|
struct lua_State *mainthread;
|
||||||
TString *memerrmsg; /* message for memory-allocation errors */
|
TString *memerrmsg; /* message for memory-allocation errors */
|
||||||
TString *tmname[TM_N]; /* array with tag-method names */
|
TString *tmname[TM_N]; /* array with tag-method names */
|
||||||
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
struct Table *mt[LUA_NUMTYPES]; /* metatables for basic types */
|
||||||
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
||||||
lua_WarnFunction warnf; /* warning function */
|
lua_WarnFunction warnf; /* warning function */
|
||||||
void *ud_warn; /* auxiliary data to 'warnf' */
|
void *ud_warn; /* auxiliary data to 'warnf' */
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "lobject.h"
|
#include "lobject.h"
|
||||||
|
#include "lstate.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -95,8 +96,8 @@ LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
|
|||||||
int inv, int isfloat, TMS event);
|
int inv, int isfloat, TMS event);
|
||||||
|
|
||||||
LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,
|
LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,
|
||||||
struct CallInfo *ci, const Proto *p);
|
CallInfo *ci, const Proto *p);
|
||||||
LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci,
|
LUAI_FUNC void luaT_getvarargs (lua_State *L, CallInfo *ci,
|
||||||
StkId where, int wanted);
|
StkId where, int wanted);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -633,7 +633,8 @@ static int pmain (lua_State *L) {
|
|||||||
}
|
}
|
||||||
luaL_openlibs(L); /* open standard libraries */
|
luaL_openlibs(L); /* open standard libraries */
|
||||||
createargtable(L, argv, argc, script); /* create table 'arg' */
|
createargtable(L, argv, argc, script); /* create table 'arg' */
|
||||||
lua_gc(L, LUA_GCGEN, 0, 0); /* GC in generational mode */
|
lua_gc(L, LUA_GCRESTART); /* start GC... */
|
||||||
|
lua_gc(L, LUA_GCGEN, 0, 0); /* ...in generational mode */
|
||||||
if (!(args & has_E)) { /* no option '-E'? */
|
if (!(args & has_E)) { /* no option '-E'? */
|
||||||
if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
|
if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
|
||||||
return 0; /* error running LUA_INIT */
|
return 0; /* error running LUA_INIT */
|
||||||
@@ -665,6 +666,7 @@ int main (int argc, char **argv) {
|
|||||||
l_message(argv[0], "cannot create state: not enough memory");
|
l_message(argv[0], "cannot create state: not enough memory");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
lua_gc(L, LUA_GCSTOP); /* stop GC while buidling state */
|
||||||
lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */
|
lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */
|
||||||
lua_pushinteger(L, argc); /* 1st argument */
|
lua_pushinteger(L, argc); /* 1st argument */
|
||||||
lua_pushlightuserdata(L, argv); /* 2nd argument */
|
lua_pushlightuserdata(L, argv); /* 2nd argument */
|
||||||
|
|||||||
@@ -131,6 +131,16 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
|
|||||||
typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
|
typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Type used by the debug API to collect debug information
|
||||||
|
*/
|
||||||
|
typedef struct lua_Debug lua_Debug;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Functions to be called by the debugger in specific events
|
||||||
|
*/
|
||||||
|
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -446,12 +456,6 @@ LUA_API void (lua_closeslot) (lua_State *L, int idx);
|
|||||||
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
|
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
|
||||||
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
|
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
|
||||||
|
|
||||||
typedef struct lua_Debug lua_Debug; /* activation record */
|
|
||||||
|
|
||||||
|
|
||||||
/* Functions to be called by the debugger in specific events */
|
|
||||||
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
|
|
||||||
|
|
||||||
|
|
||||||
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
|
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
|
||||||
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
|
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
|
||||||
|
|||||||
Reference in New Issue
Block a user