xref: /aosp_15_r20/external/lua/src/lstate.h (revision 088332b5b69e7ab13924864b272aabfc2509d2d5)
1*088332b5SXin Li /*
2*088332b5SXin Li ** $Id: lstate.h $
3*088332b5SXin Li ** Global State
4*088332b5SXin Li ** See Copyright Notice in lua.h
5*088332b5SXin Li */
6*088332b5SXin Li 
7*088332b5SXin Li #ifndef lstate_h
8*088332b5SXin Li #define lstate_h
9*088332b5SXin Li 
10*088332b5SXin Li #include "lua.h"
11*088332b5SXin Li 
12*088332b5SXin Li #include "lobject.h"
13*088332b5SXin Li #include "ltm.h"
14*088332b5SXin Li #include "lzio.h"
15*088332b5SXin Li 
16*088332b5SXin Li 
17*088332b5SXin Li /*
18*088332b5SXin Li ** Some notes about garbage-collected objects: All objects in Lua must
19*088332b5SXin Li ** be kept somehow accessible until being freed, so all objects always
20*088332b5SXin Li ** belong to one (and only one) of these lists, using field 'next' of
21*088332b5SXin Li ** the 'CommonHeader' for the link:
22*088332b5SXin Li **
23*088332b5SXin Li ** 'allgc': all objects not marked for finalization;
24*088332b5SXin Li ** 'finobj': all objects marked for finalization;
25*088332b5SXin Li ** 'tobefnz': all objects ready to be finalized;
26*088332b5SXin Li ** 'fixedgc': all objects that are not to be collected (currently
27*088332b5SXin Li ** only small strings, such as reserved words).
28*088332b5SXin Li **
29*088332b5SXin Li ** For the generational collector, some of these lists have marks for
30*088332b5SXin Li ** generations. Each mark points to the first element in the list for
31*088332b5SXin Li ** that particular generation; that generation goes until the next mark.
32*088332b5SXin Li **
33*088332b5SXin Li ** 'allgc' -> 'survival': new objects;
34*088332b5SXin Li ** 'survival' -> 'old': objects that survived one collection;
35*088332b5SXin Li ** 'old1' -> 'reallyold': objects that became old in last collection;
36*088332b5SXin Li ** 'reallyold' -> NULL: objects old for more than one cycle.
37*088332b5SXin Li **
38*088332b5SXin Li ** 'finobj' -> 'finobjsur': new objects marked for finalization;
39*088332b5SXin Li ** 'finobjsur' -> 'finobjold1': survived   """";
40*088332b5SXin Li ** 'finobjold1' -> 'finobjrold': just old  """";
41*088332b5SXin Li ** 'finobjrold' -> NULL: really old       """".
42*088332b5SXin Li **
43*088332b5SXin Li ** All lists can contain elements older than their main ages, due
44*088332b5SXin Li ** to 'luaC_checkfinalizer' and 'udata2finalize', which move
45*088332b5SXin Li ** objects between the normal lists and the "marked for finalization"
46*088332b5SXin Li ** lists. Moreover, barriers can age young objects in young lists as
47*088332b5SXin Li ** OLD0, which then become OLD1. However, a list never contains
48*088332b5SXin Li ** elements younger than their main ages.
49*088332b5SXin Li **
50*088332b5SXin Li ** The generational collector also uses a pointer 'firstold1', which
51*088332b5SXin Li ** points to the first OLD1 object in the list. It is used to optimize
52*088332b5SXin Li ** 'markold'. (Potentially OLD1 objects can be anywhere between 'allgc'
53*088332b5SXin Li ** and 'reallyold', but often the list has no OLD1 objects or they are
54*088332b5SXin Li ** after 'old1'.) Note the difference between it and 'old1':
55*088332b5SXin Li ** 'firstold1': no OLD1 objects before this point; there can be all
56*088332b5SXin Li **   ages after it.
57*088332b5SXin Li ** 'old1': no objects younger than OLD1 after this point.
58*088332b5SXin Li */
59*088332b5SXin Li 
60*088332b5SXin Li /*
61*088332b5SXin Li ** Moreover, there is another set of lists that control gray objects.
62*088332b5SXin Li ** These lists are linked by fields 'gclist'. (All objects that
63*088332b5SXin Li ** can become gray have such a field. The field is not the same
64*088332b5SXin Li ** in all objects, but it always has this name.)  Any gray object
65*088332b5SXin Li ** must belong to one of these lists, and all objects in these lists
66*088332b5SXin Li ** must be gray (with two exceptions explained below):
67*088332b5SXin Li **
68*088332b5SXin Li ** 'gray': regular gray objects, still waiting to be visited.
69*088332b5SXin Li ** 'grayagain': objects that must be revisited at the atomic phase.
70*088332b5SXin Li **   That includes
71*088332b5SXin Li **   - black objects got in a write barrier;
72*088332b5SXin Li **   - all kinds of weak tables during propagation phase;
73*088332b5SXin Li **   - all threads.
74*088332b5SXin Li ** 'weak': tables with weak values to be cleared;
75*088332b5SXin Li ** 'ephemeron': ephemeron tables with white->white entries;
76*088332b5SXin Li ** 'allweak': tables with weak keys and/or weak values to be cleared.
77*088332b5SXin Li **
78*088332b5SXin Li ** The exceptions to that "gray rule" are:
79*088332b5SXin Li ** - TOUCHED2 objects in generational mode stay in a gray list (because
80*088332b5SXin Li ** they must be visited again at the end of the cycle), but they are
81*088332b5SXin Li ** marked black because assignments to them must activate barriers (to
82*088332b5SXin Li ** move them back to TOUCHED1).
83*088332b5SXin Li ** - Open upvales are kept gray to avoid barriers, but they stay out
84*088332b5SXin Li ** of gray lists. (They don't even have a 'gclist' field.)
85*088332b5SXin Li */
86*088332b5SXin Li 
87*088332b5SXin Li 
88*088332b5SXin Li 
89*088332b5SXin Li /*
90*088332b5SXin Li ** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of
91*088332b5SXin Li ** how many "C calls" it still can do in the C stack, to avoid C-stack
92*088332b5SXin Li ** overflow.  This count is very rough approximation; it considers only
93*088332b5SXin Li ** recursive functions inside the interpreter, as non-recursive calls
94*088332b5SXin Li ** can be considered using a fixed (although unknown) amount of stack
95*088332b5SXin Li ** space.
96*088332b5SXin Li **
97*088332b5SXin Li ** The count has two parts: the lower part is the count itself; the
98*088332b5SXin Li ** higher part counts the number of non-yieldable calls in the stack.
99*088332b5SXin Li ** (They are together so that we can change both with one instruction.)
100*088332b5SXin Li **
101*088332b5SXin Li ** Because calls to external C functions can use an unknown amount
102*088332b5SXin Li ** of space (e.g., functions using an auxiliary buffer), calls
103*088332b5SXin Li ** to these functions add more than one to the count (see CSTACKCF).
104*088332b5SXin Li **
105*088332b5SXin Li ** The proper count excludes the number of CallInfo structures allocated
106*088332b5SXin Li ** by Lua, as a kind of "potential" calls. So, when Lua calls a function
107*088332b5SXin Li ** (and "consumes" one CallInfo), it needs neither to decrement nor to
108*088332b5SXin Li ** check 'nCcalls', as its use of C stack is already accounted for.
109*088332b5SXin Li */
110*088332b5SXin Li 
111*088332b5SXin Li /* number of "C stack slots" used by an external C function */
112*088332b5SXin Li #define CSTACKCF	10
113*088332b5SXin Li 
114*088332b5SXin Li 
115*088332b5SXin Li /*
116*088332b5SXin Li ** The C-stack size is sliced in the following zones:
117*088332b5SXin Li ** - larger than CSTACKERR: normal stack;
118*088332b5SXin Li ** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;
119*088332b5SXin Li ** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;
120*088332b5SXin Li ** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;
121*088332b5SXin Li ** (Because the counter can be decremented CSTACKCF at once, we need
122*088332b5SXin Li ** the so called "buffer zones", with at least that size, to properly
123*088332b5SXin Li ** detect a change from one zone to the next.)
124*088332b5SXin Li */
125*088332b5SXin Li #define CSTACKERR	(8 * CSTACKCF)
126*088332b5SXin Li #define CSTACKMARK	(CSTACKERR - (CSTACKCF + 2))
127*088332b5SXin Li #define CSTACKERRMARK	(CSTACKCF + 2)
128*088332b5SXin Li 
129*088332b5SXin Li 
130*088332b5SXin Li /* initial limit for the C-stack of threads */
131*088332b5SXin Li #define CSTACKTHREAD	(2 * CSTACKERR)
132*088332b5SXin Li 
133*088332b5SXin Li 
134*088332b5SXin Li /* true if this thread does not have non-yieldable calls in the stack */
135*088332b5SXin Li #define yieldable(L)		(((L)->nCcalls & 0xffff0000) == 0)
136*088332b5SXin Li 
137*088332b5SXin Li /* real number of C calls */
138*088332b5SXin Li #define getCcalls(L)	((L)->nCcalls & 0xffff)
139*088332b5SXin Li 
140*088332b5SXin Li 
141*088332b5SXin Li /* Increment the number of non-yieldable calls */
142*088332b5SXin Li #define incnny(L)	((L)->nCcalls += 0x10000)
143*088332b5SXin Li 
144*088332b5SXin Li /* Decrement the number of non-yieldable calls */
145*088332b5SXin Li #define decnny(L)	((L)->nCcalls -= 0x10000)
146*088332b5SXin Li 
147*088332b5SXin Li /* Increment the number of non-yieldable calls and decrement nCcalls */
148*088332b5SXin Li #define incXCcalls(L)	((L)->nCcalls += 0x10000 - CSTACKCF)
149*088332b5SXin Li 
150*088332b5SXin Li /* Decrement the number of non-yieldable calls and increment nCcalls */
151*088332b5SXin Li #define decXCcalls(L)	((L)->nCcalls -= 0x10000 - CSTACKCF)
152*088332b5SXin Li 
153*088332b5SXin Li 
154*088332b5SXin Li 
155*088332b5SXin Li 
156*088332b5SXin Li 
157*088332b5SXin Li 
158*088332b5SXin Li struct lua_longjmp;  /* defined in ldo.c */
159*088332b5SXin Li 
160*088332b5SXin Li 
161*088332b5SXin Li /*
162*088332b5SXin Li ** Atomic type (relative to signals) to better ensure that 'lua_sethook'
163*088332b5SXin Li ** is thread safe
164*088332b5SXin Li */
165*088332b5SXin Li #if !defined(l_signalT)
166*088332b5SXin Li #include <signal.h>
167*088332b5SXin Li #define l_signalT	sig_atomic_t
168*088332b5SXin Li #endif
169*088332b5SXin Li 
170*088332b5SXin Li 
171*088332b5SXin Li /* extra stack space to handle TM calls and some other extras */
172*088332b5SXin Li #define EXTRA_STACK   5
173*088332b5SXin Li 
174*088332b5SXin Li 
175*088332b5SXin Li #define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
176*088332b5SXin Li 
177*088332b5SXin Li 
178*088332b5SXin Li /* kinds of Garbage Collection */
179*088332b5SXin Li #define KGC_INC		0	/* incremental gc */
180*088332b5SXin Li #define KGC_GEN		1	/* generational gc */
181*088332b5SXin Li 
182*088332b5SXin Li 
183*088332b5SXin Li typedef struct stringtable {
184*088332b5SXin Li   TString **hash;
185*088332b5SXin Li   int nuse;  /* number of elements */
186*088332b5SXin Li   int size;
187*088332b5SXin Li } stringtable;
188*088332b5SXin Li 
189*088332b5SXin Li 
190*088332b5SXin Li /*
191*088332b5SXin Li ** Information about a call.
192*088332b5SXin Li */
193*088332b5SXin Li typedef struct CallInfo {
194*088332b5SXin Li   StkId func;  /* function index in the stack */
195*088332b5SXin Li   StkId	top;  /* top for this function */
196*088332b5SXin Li   struct CallInfo *previous, *next;  /* dynamic call link */
197*088332b5SXin Li   union {
198*088332b5SXin Li     struct {  /* only for Lua functions */
199*088332b5SXin Li       const Instruction *savedpc;
200*088332b5SXin Li       volatile l_signalT trap;
201*088332b5SXin Li       int nextraargs;  /* # of extra arguments in vararg functions */
202*088332b5SXin Li     } l;
203*088332b5SXin Li     struct {  /* only for C functions */
204*088332b5SXin Li       lua_KFunction k;  /* continuation in case of yields */
205*088332b5SXin Li       ptrdiff_t old_errfunc;
206*088332b5SXin Li       lua_KContext ctx;  /* context info. in case of yields */
207*088332b5SXin Li     } c;
208*088332b5SXin Li   } u;
209*088332b5SXin Li   union {
210*088332b5SXin Li     int funcidx;  /* called-function index */
211*088332b5SXin Li     int nyield;  /* number of values yielded */
212*088332b5SXin Li     struct {  /* info about transferred values (for call/return hooks) */
213*088332b5SXin Li       unsigned short ftransfer;  /* offset of first value transferred */
214*088332b5SXin Li       unsigned short ntransfer;  /* number of values transferred */
215*088332b5SXin Li     } transferinfo;
216*088332b5SXin Li   } u2;
217*088332b5SXin Li   short nresults;  /* expected number of results from this function */
218*088332b5SXin Li   unsigned short callstatus;
219*088332b5SXin Li } CallInfo;
220*088332b5SXin Li 
221*088332b5SXin Li 
222*088332b5SXin Li /*
223*088332b5SXin Li ** Bits in CallInfo status
224*088332b5SXin Li */
225*088332b5SXin Li #define CIST_OAH	(1<<0)	/* original value of 'allowhook' */
226*088332b5SXin Li #define CIST_C		(1<<1)	/* call is running a C function */
227*088332b5SXin Li #define CIST_HOOKED	(1<<2)	/* call is running a debug hook */
228*088332b5SXin Li #define CIST_YPCALL	(1<<3)	/* call is a yieldable protected call */
229*088332b5SXin Li #define CIST_TAIL	(1<<4)	/* call was tail called */
230*088332b5SXin Li #define CIST_HOOKYIELD	(1<<5)	/* last hook called yielded */
231*088332b5SXin Li #define CIST_FIN	(1<<6)  /* call is running a finalizer */
232*088332b5SXin Li #define CIST_TRAN	(1<<7)	/* 'ci' has transfer information */
233*088332b5SXin Li #if defined(LUA_COMPAT_LT_LE)
234*088332b5SXin Li #define CIST_LEQ	(1<<8)  /* using __lt for __le */
235*088332b5SXin Li #endif
236*088332b5SXin Li 
237*088332b5SXin Li /* active function is a Lua function */
238*088332b5SXin Li #define isLua(ci)	(!((ci)->callstatus & CIST_C))
239*088332b5SXin Li 
240*088332b5SXin Li /* call is running Lua code (not a hook) */
241*088332b5SXin Li #define isLuacode(ci)	(!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
242*088332b5SXin Li 
243*088332b5SXin Li /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
244*088332b5SXin Li #define setoah(st,v)	((st) = ((st) & ~CIST_OAH) | (v))
245*088332b5SXin Li #define getoah(st)	((st) & CIST_OAH)
246*088332b5SXin Li 
247*088332b5SXin Li 
248*088332b5SXin Li /*
249*088332b5SXin Li ** 'global state', shared by all threads of this state
250*088332b5SXin Li */
251*088332b5SXin Li typedef struct global_State {
252*088332b5SXin Li   lua_Alloc frealloc;  /* function to reallocate memory */
253*088332b5SXin Li   void *ud;         /* auxiliary data to 'frealloc' */
254*088332b5SXin Li   l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */
255*088332b5SXin Li   l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */
256*088332b5SXin Li   lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */
257*088332b5SXin Li   lu_mem lastatomic;  /* see function 'genstep' in file 'lgc.c' */
258*088332b5SXin Li   stringtable strt;  /* hash table for strings */
259*088332b5SXin Li   TValue l_registry;
260*088332b5SXin Li   TValue nilvalue;  /* a nil value */
261*088332b5SXin Li   unsigned int seed;  /* randomized seed for hashes */
262*088332b5SXin Li   lu_byte currentwhite;
263*088332b5SXin Li   lu_byte gcstate;  /* state of garbage collector */
264*088332b5SXin Li   lu_byte gckind;  /* kind of GC running */
265*088332b5SXin Li   lu_byte genminormul;  /* control for minor generational collections */
266*088332b5SXin Li   lu_byte genmajormul;  /* control for major generational collections */
267*088332b5SXin Li   lu_byte gcrunning;  /* true if GC is running */
268*088332b5SXin Li   lu_byte gcemergency;  /* true if this is an emergency collection */
269*088332b5SXin Li   lu_byte gcpause;  /* size of pause between successive GCs */
270*088332b5SXin Li   lu_byte gcstepmul;  /* GC "speed" */
271*088332b5SXin Li   lu_byte gcstepsize;  /* (log2 of) GC granularity */
272*088332b5SXin Li   GCObject *allgc;  /* list of all collectable objects */
273*088332b5SXin Li   GCObject **sweepgc;  /* current position of sweep in list */
274*088332b5SXin Li   GCObject *finobj;  /* list of collectable objects with finalizers */
275*088332b5SXin Li   GCObject *gray;  /* list of gray objects */
276*088332b5SXin Li   GCObject *grayagain;  /* list of objects to be traversed atomically */
277*088332b5SXin Li   GCObject *weak;  /* list of tables with weak values */
278*088332b5SXin Li   GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */
279*088332b5SXin Li   GCObject *allweak;  /* list of all-weak tables */
280*088332b5SXin Li   GCObject *tobefnz;  /* list of userdata to be GC */
281*088332b5SXin Li   GCObject *fixedgc;  /* list of objects not to be collected */
282*088332b5SXin Li   /* fields for generational collector */
283*088332b5SXin Li   GCObject *survival;  /* start of objects that survived one GC cycle */
284*088332b5SXin Li   GCObject *old1;  /* start of old1 objects */
285*088332b5SXin Li   GCObject *reallyold;  /* objects more than one cycle old ("really old") */
286*088332b5SXin Li   GCObject *firstold1;  /* first OLD1 object in the list (if any) */
287*088332b5SXin Li   GCObject *finobjsur;  /* list of survival objects with finalizers */
288*088332b5SXin Li   GCObject *finobjold1;  /* list of old1 objects with finalizers */
289*088332b5SXin Li   GCObject *finobjrold;  /* list of really old objects with finalizers */
290*088332b5SXin Li   struct lua_State *twups;  /* list of threads with open upvalues */
291*088332b5SXin Li   lua_CFunction panic;  /* to be called in unprotected errors */
292*088332b5SXin Li   struct lua_State *mainthread;
293*088332b5SXin Li   TString *memerrmsg;  /* message for memory-allocation errors */
294*088332b5SXin Li   TString *tmname[TM_N];  /* array with tag-method names */
295*088332b5SXin Li   struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */
296*088332b5SXin Li   TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */
297*088332b5SXin Li   lua_WarnFunction warnf;  /* warning function */
298*088332b5SXin Li   void *ud_warn;         /* auxiliary data to 'warnf' */
299*088332b5SXin Li   unsigned int Cstacklimit;  /* current limit for the C stack */
300*088332b5SXin Li } global_State;
301*088332b5SXin Li 
302*088332b5SXin Li 
303*088332b5SXin Li /*
304*088332b5SXin Li ** 'per thread' state
305*088332b5SXin Li */
306*088332b5SXin Li struct lua_State {
307*088332b5SXin Li   CommonHeader;
308*088332b5SXin Li   lu_byte status;
309*088332b5SXin Li   lu_byte allowhook;
310*088332b5SXin Li   unsigned short nci;  /* number of items in 'ci' list */
311*088332b5SXin Li   StkId top;  /* first free slot in the stack */
312*088332b5SXin Li   global_State *l_G;
313*088332b5SXin Li   CallInfo *ci;  /* call info for current function */
314*088332b5SXin Li   StkId stack_last;  /* last free slot in the stack */
315*088332b5SXin Li   StkId stack;  /* stack base */
316*088332b5SXin Li   UpVal *openupval;  /* list of open upvalues in this stack */
317*088332b5SXin Li   GCObject *gclist;
318*088332b5SXin Li   struct lua_State *twups;  /* list of threads with open upvalues */
319*088332b5SXin Li   struct lua_longjmp *errorJmp;  /* current error recover point */
320*088332b5SXin Li   CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */
321*088332b5SXin Li   volatile lua_Hook hook;
322*088332b5SXin Li   ptrdiff_t errfunc;  /* current error handling function (stack index) */
323*088332b5SXin Li   l_uint32 nCcalls;  /* number of allowed nested C calls - 'nci' */
324*088332b5SXin Li   int oldpc;  /* last pc traced */
325*088332b5SXin Li   int stacksize;
326*088332b5SXin Li   int basehookcount;
327*088332b5SXin Li   int hookcount;
328*088332b5SXin Li   volatile l_signalT hookmask;
329*088332b5SXin Li };
330*088332b5SXin Li 
331*088332b5SXin Li 
332*088332b5SXin Li #define G(L)	(L->l_G)
333*088332b5SXin Li 
334*088332b5SXin Li 
335*088332b5SXin Li /*
336*088332b5SXin Li ** Union of all collectable objects (only for conversions)
337*088332b5SXin Li ** ISO C99, 6.5.2.3 p.5:
338*088332b5SXin Li ** "if a union contains several structures that share a common initial
339*088332b5SXin Li ** sequence [...], and if the union object currently contains one
340*088332b5SXin Li ** of these structures, it is permitted to inspect the common initial
341*088332b5SXin Li ** part of any of them anywhere that a declaration of the complete type
342*088332b5SXin Li ** of the union is visible."
343*088332b5SXin Li */
344*088332b5SXin Li union GCUnion {
345*088332b5SXin Li   GCObject gc;  /* common header */
346*088332b5SXin Li   struct TString ts;
347*088332b5SXin Li   struct Udata u;
348*088332b5SXin Li   union Closure cl;
349*088332b5SXin Li   struct Table h;
350*088332b5SXin Li   struct Proto p;
351*088332b5SXin Li   struct lua_State th;  /* thread */
352*088332b5SXin Li   struct UpVal upv;
353*088332b5SXin Li };
354*088332b5SXin Li 
355*088332b5SXin Li 
356*088332b5SXin Li /*
357*088332b5SXin Li ** ISO C99, 6.7.2.1 p.14:
358*088332b5SXin Li ** "A pointer to a union object, suitably converted, points to each of
359*088332b5SXin Li ** its members [...], and vice versa."
360*088332b5SXin Li */
361*088332b5SXin Li #define cast_u(o)	cast(union GCUnion *, (o))
362*088332b5SXin Li 
363*088332b5SXin Li /* macros to convert a GCObject into a specific value */
364*088332b5SXin Li #define gco2ts(o)  \
365*088332b5SXin Li 	check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
366*088332b5SXin Li #define gco2u(o)  check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
367*088332b5SXin Li #define gco2lcl(o)  check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
368*088332b5SXin Li #define gco2ccl(o)  check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
369*088332b5SXin Li #define gco2cl(o)  \
370*088332b5SXin Li 	check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
371*088332b5SXin Li #define gco2t(o)  check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
372*088332b5SXin Li #define gco2p(o)  check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
373*088332b5SXin Li #define gco2th(o)  check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
374*088332b5SXin Li #define gco2upv(o)	check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
375*088332b5SXin Li 
376*088332b5SXin Li 
377*088332b5SXin Li /*
378*088332b5SXin Li ** macro to convert a Lua object into a GCObject
379*088332b5SXin Li ** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
380*088332b5SXin Li */
381*088332b5SXin Li #define obj2gco(v)	check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
382*088332b5SXin Li 
383*088332b5SXin Li 
384*088332b5SXin Li /* actual number of total bytes allocated */
385*088332b5SXin Li #define gettotalbytes(g)	cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
386*088332b5SXin Li 
387*088332b5SXin Li LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
388*088332b5SXin Li LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
389*088332b5SXin Li LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
390*088332b5SXin Li LUAI_FUNC void luaE_freeCI (lua_State *L);
391*088332b5SXin Li LUAI_FUNC void luaE_shrinkCI (lua_State *L);
392*088332b5SXin Li LUAI_FUNC void luaE_enterCcall (lua_State *L);
393*088332b5SXin Li LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
394*088332b5SXin Li LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
395*088332b5SXin Li 
396*088332b5SXin Li 
397*088332b5SXin Li #define luaE_exitCcall(L)	((L)->nCcalls++)
398*088332b5SXin Li 
399*088332b5SXin Li #endif
400*088332b5SXin Li 
401