| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /* | |||
| 2 | ** $Id: lstate.c $ | |||
| 3 | ** Global State | |||
| 4 | ** See Copyright Notice in lua.h | |||
| 5 | */ | |||
| 6 | ||||
| 7 | #define lstate_c | |||
| 8 | #define LUA_CORE | |||
| 9 | ||||
| 10 | #include "lprefix.h" | |||
| 11 | ||||
| 12 | ||||
| 13 | #include <stddef.h> | |||
| 14 | #include <string.h> | |||
| 15 | ||||
| 16 | #include "lua.h" | |||
| 17 | ||||
| 18 | #include "lapi.h" | |||
| 19 | #include "ldebug.h" | |||
| 20 | #include "ldo.h" | |||
| 21 | #include "lfunc.h" | |||
| 22 | #include "lgc.h" | |||
| 23 | #include "llex.h" | |||
| 24 | #include "lmem.h" | |||
| 25 | #include "lstate.h" | |||
| 26 | #include "lstring.h" | |||
| 27 | #include "ltable.h" | |||
| 28 | #include "ltm.h" | |||
| 29 | ||||
| 30 | ||||
| 31 | ||||
| 32 | /* | |||
| 33 | ** thread state + extra space | |||
| 34 | */ | |||
| 35 | typedef struct LX { | |||
| 36 | lu_byte extra_[LUA_EXTRASPACE]; | |||
| 37 | lua_State l; | |||
| 38 | } LX; | |||
| 39 | ||||
| 40 | ||||
| 41 | /* | |||
| 42 | ** Main thread combines a thread state and the global state | |||
| 43 | */ | |||
| 44 | typedef struct LG { | |||
| 45 | LX l; | |||
| 46 | global_State g; | |||
| 47 | } LG; | |||
| 48 | ||||
| 49 | ||||
| 50 | ||||
| 51 | #define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l))) | |||
| 52 | ||||
| 53 | ||||
| 54 | /* | |||
| 55 | ** A macro to create a "random" seed when a state is created; | |||
| 56 | ** the seed is used to randomize string hashes. | |||
| 57 | */ | |||
| 58 | #if !defined(luai_makeseed) | |||
| 59 | ||||
| 60 | #include <time.h> | |||
| 61 | ||||
| 62 | /* | |||
| 63 | ** Compute an initial seed with some level of randomness. | |||
| 64 | ** Rely on Address Space Layout Randomization (if present) and | |||
| 65 | ** current time. | |||
| 66 | */ | |||
| 67 | #define addbuff(b,p,e) \ | |||
| 68 | { size_t t = cast_sizet(e); \ | |||
| 69 | memcpy(b + p, &t, sizeof(t)); p += sizeof(t); } | |||
| 70 | ||||
| 71 | 297 | static unsigned int luai_makeseed (lua_State *L) { | ||
| 72 | char buff[3 * sizeof(size_t)]; | |||
| 73 | 297 | unsigned int h = cast_uint(time(NULL)); | ||
| 74 | 297 | int p = 0; | ||
| 75 | 297 | addbuff(buff, p, L); /* heap variable */ | ||
| 76 | 297 | addbuff(buff, p, &h); /* local variable */ | ||
| 77 | 297 | addbuff(buff, p, &lua_newstate); /* public function */ | ||
| 78 | lua_assert(p == sizeof(buff)); | |||
| 79 | 297 | return luaS_hash(buff, p, h); | ||
| 80 | } | |||
| 81 | ||||
| 82 | #endif | |||
| 83 | ||||
| 84 | ||||
| 85 | /* | |||
| 86 | ** set GCdebt to a new value keeping the value (totalbytes + GCdebt) | |||
| 87 | ** invariant (and avoiding underflows in 'totalbytes') | |||
| 88 | */ | |||
| 89 | 891 | void luaE_setdebt (global_State *g, l_mem debt) { | ||
| 90 | 891 | l_mem tb = gettotalbytes(g); | ||
| 91 | lua_assert(tb > 0); | |||
| 92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 891 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 891 times.
|
891 | if (debt < tb - MAX_LMEM) |
| 93 | ✗ | debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */ | ||
| 94 | 891 | g->totalbytes = tb - debt; | ||
| 95 | 891 | g->GCdebt = debt; | ||
| 96 | 891 | } | ||
| 97 | ||||
| 98 | ||||
| 99 | ✗ | LUA_API int lua_setcstacklimit (lua_State *L, unsigned int limit) { | ||
| 100 | UNUSED(L); UNUSED(limit); | |||
| 101 | ✗ | return LUAI_MAXCCALLS; /* warning?? */ | ||
| 102 | } | |||
| 103 | ||||
| 104 | ||||
| 105 | 594 | CallInfo *luaE_extendCI (lua_State *L) { | ||
| 106 | CallInfo *ci; | |||
| 107 | lua_assert(L->ci->next == NULL); | |||
| 108 | 594 | ci = luaM_new(L, CallInfo); | ||
| 109 | lua_assert(L->ci->next == NULL); | |||
| 110 | 594 | L->ci->next = ci; | ||
| 111 | 594 | ci->previous = L->ci; | ||
| 112 | 594 | ci->next = NULL; | ||
| 113 | 594 | ci->u.l.trap = 0; | ||
| 114 | 594 | L->nci++; | ||
| 115 | 594 | return ci; | ||
| 116 | } | |||
| 117 | ||||
| 118 | ||||
| 119 | /* | |||
| 120 | ** free all CallInfo structures not in use by a thread | |||
| 121 | */ | |||
| 122 | 297 | void luaE_freeCI (lua_State *L) { | ||
| 123 | 297 | CallInfo *ci = L->ci; | ||
| 124 | 297 | CallInfo *next = ci->next; | ||
| 125 | 297 | ci->next = NULL; | ||
| 126 |
2/2✓ Branch 0 taken 588 times.
✓ Branch 1 taken 297 times.
|
2/2✓ Decision 'true' taken 588 times.
✓ Decision 'false' taken 297 times.
|
885 | while ((ci = next) != NULL) { |
| 127 | 588 | next = ci->next; | ||
| 128 | 588 | luaM_free(L, ci); | ||
| 129 | 588 | L->nci--; | ||
| 130 | } | |||
| 131 | 297 | } | ||
| 132 | ||||
| 133 | ||||
| 134 | /* | |||
| 135 | ** free half of the CallInfo structures not in use by a thread, | |||
| 136 | ** keeping the first one. | |||
| 137 | */ | |||
| 138 | 898 | void luaE_shrinkCI (lua_State *L) { | ||
| 139 | 898 | CallInfo *ci = L->ci->next; /* first free CallInfo */ | ||
| 140 | CallInfo *next; | |||
| 141 |
2/2✓ Branch 0 taken 297 times.
✓ Branch 1 taken 601 times.
|
2/2✓ Decision 'true' taken 297 times.
✓ Decision 'false' taken 601 times.
|
898 | if (ci == NULL) |
| 142 | 297 | return; /* no extra elements */ | ||
| 143 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 595 times.
|
2/2✓ Decision 'true' taken 6 times.
✓ Decision 'false' taken 595 times.
|
601 | while ((next = ci->next) != NULL) { /* two extra elements? */ |
| 144 | 6 | CallInfo *next2 = next->next; /* next's next */ | ||
| 145 | 6 | ci->next = next2; /* remove next from the list */ | ||
| 146 | 6 | L->nci--; | ||
| 147 | 6 | luaM_free(L, next); /* free next */ | ||
| 148 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 6 times.
✗ Decision 'false' not taken.
|
6 | if (next2 == NULL) |
| 149 | 6 | break; /* no more elements */ | ||
| 150 | else { | |||
| 151 | ✗ | next2->previous = ci; | ||
| 152 | ✗ | ci = next2; /* continue */ | ||
| 153 | } | |||
| 154 | } | |||
| 155 | } | |||
| 156 | ||||
| 157 | ||||
| 158 | /* | |||
| 159 | ** Called when 'getCcalls(L)' larger or equal to LUAI_MAXCCALLS. | |||
| 160 | ** If equal, raises an overflow error. If value is larger than | |||
| 161 | ** LUAI_MAXCCALLS (which means it is handling an overflow) but | |||
| 162 | ** not much larger, does not report an error (to allow overflow | |||
| 163 | ** handling to work). | |||
| 164 | */ | |||
| 165 | ✗ | void luaE_checkcstack (lua_State *L) { | ||
| 166 | ✗ | if (getCcalls(L) == LUAI_MAXCCALLS) | ||
| 167 | ✗ | luaG_runerror(L, "C stack overflow"); | ||
| 168 | ✗ | else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11)) | ||
| 169 | ✗ | luaD_throw(L, LUA_ERRERR); /* error while handling stack error */ | ||
| 170 | ✗ | } | ||
| 171 | ||||
| 172 | ||||
| 173 | 6105 | LUAI_FUNC void luaE_incCstack (lua_State *L) { | ||
| 174 | 6105 | L->nCcalls++; | ||
| 175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6105 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 6105 times.
|
6105 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) |
| 176 | ✗ | luaE_checkcstack(L); | ||
| 177 | 6105 | } | ||
| 178 | ||||
| 179 | ||||
| 180 | 297 | static void stack_init (lua_State *L1, lua_State *L) { | ||
| 181 | int i; CallInfo *ci; | |||
| 182 | /* initialize stack array */ | |||
| 183 | 297 | L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue); | ||
| 184 | 297 | L1->tbclist.p = L1->stack.p; | ||
| 185 |
2/2✓ Branch 0 taken 13365 times.
✓ Branch 1 taken 297 times.
|
2/2✓ Decision 'true' taken 13365 times.
✓ Decision 'false' taken 297 times.
|
13662 | for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++) |
| 186 | 13365 | setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */ | ||
| 187 | 297 | L1->top.p = L1->stack.p; | ||
| 188 | 297 | L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE; | ||
| 189 | /* initialize first ci */ | |||
| 190 | 297 | ci = &L1->base_ci; | ||
| 191 | 297 | ci->next = ci->previous = NULL; | ||
| 192 | 297 | ci->callstatus = CIST_C; | ||
| 193 | 297 | ci->func.p = L1->top.p; | ||
| 194 | 297 | ci->u.c.k = NULL; | ||
| 195 | 297 | ci->nresults = 0; | ||
| 196 | 297 | setnilvalue(s2v(L1->top.p)); /* 'function' entry for this 'ci' */ | ||
| 197 | 297 | L1->top.p++; | ||
| 198 | 297 | ci->top.p = L1->top.p + LUA_MINSTACK; | ||
| 199 | 297 | L1->ci = ci; | ||
| 200 | 297 | } | ||
| 201 | ||||
| 202 | ||||
| 203 | 297 | static void freestack (lua_State *L) { | ||
| 204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 297 times.
|
297 | if (L->stack.p == NULL) |
| 205 | ✗ | return; /* stack not completely built yet */ | ||
| 206 | 297 | L->ci = &L->base_ci; /* free the entire 'ci' list */ | ||
| 207 | 297 | luaE_freeCI(L); | ||
| 208 | lua_assert(L->nci == 0); | |||
| 209 | 297 | luaM_freearray(L, L->stack.p, stacksize(L) + EXTRA_STACK); /* free stack */ | ||
| 210 | } | |||
| 211 | ||||
| 212 | ||||
| 213 | /* | |||
| 214 | ** Create registry table and its predefined values | |||
| 215 | */ | |||
| 216 | 297 | static void init_registry (lua_State *L, global_State *g) { | ||
| 217 | /* create registry */ | |||
| 218 | 297 | Table *registry = luaH_new(L); | ||
| 219 | 297 | sethvalue(L, &g->l_registry, registry); | ||
| 220 | 297 | luaH_resize(L, registry, LUA_RIDX_LAST, 0); | ||
| 221 | /* registry[LUA_RIDX_MAINTHREAD] = L */ | |||
| 222 | 297 | setthvalue(L, ®istry->array[LUA_RIDX_MAINTHREAD - 1], L); | ||
| 223 | /* registry[LUA_RIDX_GLOBALS] = new table (table of globals) */ | |||
| 224 | 297 | sethvalue(L, ®istry->array[LUA_RIDX_GLOBALS - 1], luaH_new(L)); | ||
| 225 | 297 | } | ||
| 226 | ||||
| 227 | ||||
| 228 | /* | |||
| 229 | ** open parts of the state that may cause memory-allocation errors. | |||
| 230 | */ | |||
| 231 | 297 | static void f_luaopen (lua_State *L, void *ud) { | ||
| 232 | 297 | global_State *g = G(L); | ||
| 233 | UNUSED(ud); | |||
| 234 | 297 | stack_init(L, L); /* init stack */ | ||
| 235 | 297 | init_registry(L, g); | ||
| 236 | 297 | luaS_init(L); | ||
| 237 | 297 | luaT_init(L); | ||
| 238 | 297 | luaX_init(L); | ||
| 239 | 297 | g->gcstp = 0; /* allow gc */ | ||
| 240 | 297 | setnilvalue(&g->nilvalue); /* now state is complete */ | ||
| 241 | luai_userstateopen(L); | |||
| 242 | 297 | } | ||
| 243 | ||||
| 244 | ||||
| 245 | /* | |||
| 246 | ** preinitialize a thread with consistent values without allocating | |||
| 247 | ** any memory (to avoid errors) | |||
| 248 | */ | |||
| 249 | 297 | static void preinit_thread (lua_State *L, global_State *g) { | ||
| 250 | 297 | G(L) = g; | ||
| 251 | 297 | L->stack.p = NULL; | ||
| 252 | 297 | L->ci = NULL; | ||
| 253 | 297 | L->nci = 0; | ||
| 254 | 297 | L->twups = L; /* thread has no upvalues */ | ||
| 255 | 297 | L->nCcalls = 0; | ||
| 256 | 297 | L->errorJmp = NULL; | ||
| 257 | 297 | L->hook = NULL; | ||
| 258 | 297 | L->hookmask = 0; | ||
| 259 | 297 | L->basehookcount = 0; | ||
| 260 | 297 | L->allowhook = 1; | ||
| 261 | 297 | resethookcount(L); | ||
| 262 | 297 | L->openupval = NULL; | ||
| 263 | 297 | L->status = LUA_OK; | ||
| 264 | 297 | L->errfunc = 0; | ||
| 265 | 297 | L->oldpc = 0; | ||
| 266 | 297 | } | ||
| 267 | ||||
| 268 | ||||
| 269 | 297 | static void close_state (lua_State *L) { | ||
| 270 | 297 | global_State *g = G(L); | ||
| 271 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 297 times.
|
297 | if (!completestate(g)) /* closing a partially built state? */ |
| 272 | ✗ | luaC_freeallobjects(L); /* just collect its objects */ | ||
| 273 | else { /* closing a fully built state */ | |||
| 274 | 297 | L->ci = &L->base_ci; /* unwind CallInfo list */ | ||
| 275 | 297 | luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */ | ||
| 276 | 297 | luaC_freeallobjects(L); /* collect all objects */ | ||
| 277 | luai_userstateclose(L); | |||
| 278 | } | |||
| 279 | 297 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); | ||
| 280 | 297 | freestack(L); | ||
| 281 | lua_assert(gettotalbytes(g) == sizeof(LG)); | |||
| 282 | 297 | (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ | ||
| 283 | 297 | } | ||
| 284 | ||||
| 285 | ||||
| 286 | ✗ | LUA_API lua_State *lua_newthread (lua_State *L) { | ||
| 287 | ✗ | global_State *g = G(L); | ||
| 288 | GCObject *o; | |||
| 289 | lua_State *L1; | |||
| 290 | lua_lock(L); | |||
| 291 | ✗ | luaC_checkGC(L); | ||
| 292 | /* create new thread */ | |||
| 293 | ✗ | o = luaC_newobjdt(L, LUA_TTHREAD, sizeof(LX), offsetof(LX, l)); | ||
| 294 | ✗ | L1 = gco2th(o); | ||
| 295 | /* anchor it on L stack */ | |||
| 296 | ✗ | setthvalue2s(L, L->top.p, L1); | ||
| 297 | ✗ | api_incr_top(L); | ||
| 298 | ✗ | preinit_thread(L1, g); | ||
| 299 | ✗ | L1->hookmask = L->hookmask; | ||
| 300 | ✗ | L1->basehookcount = L->basehookcount; | ||
| 301 | ✗ | L1->hook = L->hook; | ||
| 302 | ✗ | resethookcount(L1); | ||
| 303 | /* initialize L1 extra space */ | |||
| 304 | ✗ | memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread), | ||
| 305 | LUA_EXTRASPACE); | |||
| 306 | luai_userstatethread(L, L1); | |||
| 307 | ✗ | stack_init(L1, L); /* init stack */ | ||
| 308 | lua_unlock(L); | |||
| 309 | ✗ | return L1; | ||
| 310 | } | |||
| 311 | ||||
| 312 | ||||
| 313 | ✗ | void luaE_freethread (lua_State *L, lua_State *L1) { | ||
| 314 | ✗ | LX *l = fromstate(L1); | ||
| 315 | ✗ | luaF_closeupval(L1, L1->stack.p); /* close all upvalues */ | ||
| 316 | lua_assert(L1->openupval == NULL); | |||
| 317 | luai_userstatefree(L, L1); | |||
| 318 | ✗ | freestack(L1); | ||
| 319 | ✗ | luaM_free(L, l); | ||
| 320 | ✗ | } | ||
| 321 | ||||
| 322 | ||||
| 323 | ✗ | int luaE_resetthread (lua_State *L, int status) { | ||
| 324 | ✗ | CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */ | ||
| 325 | ✗ | setnilvalue(s2v(L->stack.p)); /* 'function' entry for basic 'ci' */ | ||
| 326 | ✗ | ci->func.p = L->stack.p; | ||
| 327 | ✗ | ci->callstatus = CIST_C; | ||
| 328 | ✗ | if (status == LUA_YIELD) | ||
| 329 | ✗ | status = LUA_OK; | ||
| 330 | ✗ | L->status = LUA_OK; /* so it can run __close metamethods */ | ||
| 331 | ✗ | status = luaD_closeprotected(L, 1, status); | ||
| 332 | ✗ | if (status != LUA_OK) /* errors? */ | ||
| 333 | ✗ | luaD_seterrorobj(L, status, L->stack.p + 1); | ||
| 334 | else | |||
| 335 | ✗ | L->top.p = L->stack.p + 1; | ||
| 336 | ✗ | ci->top.p = L->top.p + LUA_MINSTACK; | ||
| 337 | ✗ | luaD_reallocstack(L, cast_int(ci->top.p - L->stack.p), 0); | ||
| 338 | ✗ | return status; | ||
| 339 | } | |||
| 340 | ||||
| 341 | ||||
| 342 | ✗ | LUA_API int lua_closethread (lua_State *L, lua_State *from) { | ||
| 343 | int status; | |||
| 344 | lua_lock(L); | |||
| 345 | ✗ | L->nCcalls = (from) ? getCcalls(from) : 0; | ||
| 346 | ✗ | status = luaE_resetthread(L, L->status); | ||
| 347 | lua_unlock(L); | |||
| 348 | ✗ | return status; | ||
| 349 | } | |||
| 350 | ||||
| 351 | ||||
| 352 | /* | |||
| 353 | ** Deprecated! Use 'lua_closethread' instead. | |||
| 354 | */ | |||
| 355 | ✗ | LUA_API int lua_resetthread (lua_State *L) { | ||
| 356 | ✗ | return lua_closethread(L, NULL); | ||
| 357 | } | |||
| 358 | ||||
| 359 | ||||
| 360 | 297 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | ||
| 361 | int i; | |||
| 362 | lua_State *L; | |||
| 363 | global_State *g; | |||
| 364 | 297 | LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG))); | ||
| 365 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 297 times.
|
297 | if (l == NULL) return NULL; |
| 366 | 297 | L = &l->l.l; | ||
| 367 | 297 | g = &l->g; | ||
| 368 | 297 | L->tt = LUA_VTHREAD; | ||
| 369 | 297 | g->currentwhite = bitmask(WHITE0BIT); | ||
| 370 | 297 | L->marked = luaC_white(g); | ||
| 371 | 297 | preinit_thread(L, g); | ||
| 372 | 297 | g->allgc = obj2gco(L); /* by now, only object is the main thread */ | ||
| 373 | 297 | L->next = NULL; | ||
| 374 | 297 | incnny(L); /* main thread is always non yieldable */ | ||
| 375 | 297 | g->frealloc = f; | ||
| 376 | 297 | g->ud = ud; | ||
| 377 | 297 | g->warnf = NULL; | ||
| 378 | 297 | g->ud_warn = NULL; | ||
| 379 | 297 | g->mainthread = L; | ||
| 380 | 297 | g->seed = luai_makeseed(L); | ||
| 381 | 297 | g->gcstp = GCSTPGC; /* no GC while building state */ | ||
| 382 | 297 | g->strt.size = g->strt.nuse = 0; | ||
| 383 | 297 | g->strt.hash = NULL; | ||
| 384 | 297 | setnilvalue(&g->l_registry); | ||
| 385 | 297 | g->panic = NULL; | ||
| 386 | 297 | g->gcstate = GCSpause; | ||
| 387 | 297 | g->gckind = KGC_INC; | ||
| 388 | 297 | g->gcstopem = 0; | ||
| 389 | 297 | g->gcemergency = 0; | ||
| 390 | 297 | g->finobj = g->tobefnz = g->fixedgc = NULL; | ||
| 391 | 297 | g->firstold1 = g->survival = g->old1 = g->reallyold = NULL; | ||
| 392 | 297 | g->finobjsur = g->finobjold1 = g->finobjrold = NULL; | ||
| 393 | 297 | g->sweepgc = NULL; | ||
| 394 | 297 | g->gray = g->grayagain = NULL; | ||
| 395 | 297 | g->weak = g->ephemeron = g->allweak = NULL; | ||
| 396 | 297 | g->twups = NULL; | ||
| 397 | 297 | g->totalbytes = sizeof(LG); | ||
| 398 | 297 | g->GCdebt = 0; | ||
| 399 | 297 | g->lastatomic = 0; | ||
| 400 | 297 | setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ | ||
| 401 | 297 | setgcparam(g->gcpause, LUAI_GCPAUSE); | ||
| 402 | 297 | setgcparam(g->gcstepmul, LUAI_GCMUL); | ||
| 403 | 297 | g->gcstepsize = LUAI_GCSTEPSIZE; | ||
| 404 | 297 | setgcparam(g->genmajormul, LUAI_GENMAJORMUL); | ||
| 405 | 297 | g->genminormul = LUAI_GENMINORMUL; | ||
| 406 |
2/2✓ Branch 0 taken 2673 times.
✓ Branch 1 taken 297 times.
|
2/2✓ Decision 'true' taken 2673 times.
✓ Decision 'false' taken 297 times.
|
2970 | for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; |
| 407 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 297 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 297 times.
|
297 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { |
| 408 | /* memory allocation error: free partial state */ | |||
| 409 | ✗ | close_state(L); | ||
| 410 | ✗ | L = NULL; | ||
| 411 | } | |||
| 412 | 297 | return L; | ||
| 413 | } | |||
| 414 | ||||
| 415 | ||||
| 416 | 297 | LUA_API void lua_close (lua_State *L) { | ||
| 417 | lua_lock(L); | |||
| 418 | 297 | L = G(L)->mainthread; /* only the main thread can be closed */ | ||
| 419 | 297 | close_state(L); | ||
| 420 | 297 | } | ||
| 421 | ||||
| 422 | ||||
| 423 | ✗ | void luaE_warning (lua_State *L, const char *msg, int tocont) { | ||
| 424 | ✗ | lua_WarnFunction wf = G(L)->warnf; | ||
| 425 | ✗ | if (wf != NULL) | ||
| 426 | ✗ | wf(G(L)->ud_warn, msg, tocont); | ||
| 427 | ✗ | } | ||
| 428 | ||||
| 429 | ||||
| 430 | /* | |||
| 431 | ** Generate a warning from an error message | |||
| 432 | */ | |||
| 433 | ✗ | void luaE_warnerror (lua_State *L, const char *where) { | ||
| 434 | ✗ | TValue *errobj = s2v(L->top.p - 1); /* error object */ | ||
| 435 | ✗ | const char *msg = (ttisstring(errobj)) | ||
| 436 | ✗ | ? svalue(errobj) | ||
| 437 | ✗ | : "error object is not a string"; | ||
| 438 | /* produce warning "error in %s (%s)" (where, msg) */ | |||
| 439 | ✗ | luaE_warning(L, "error in ", 1); | ||
| 440 | ✗ | luaE_warning(L, where, 1); | ||
| 441 | ✗ | luaE_warning(L, " (", 1); | ||
| 442 | ✗ | luaE_warning(L, msg, 1); | ||
| 443 | ✗ | luaE_warning(L, ")", 0); | ||
| 444 | ✗ | } | ||
| 445 | ||||
| 446 |