]>
git.proxmox.com Git - mirror_zfs.git/blob - module/lua/ldo.c
3 ** $Id: ldo.c,v 2.108.1.3 2013/11/08 18:22:50 roberto Exp $
4 ** Stack and Call structure of Lua
5 ** See Copyright Notice in lua.h
12 #include <sys/lua/lua.h>
35 ** {======================================================
36 ** Error-recovery functions
37 ** =======================================================
41 ** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By
42 ** default, Lua handles errors with exceptions when compiling as
43 ** C++ code, with _longjmp/_setjmp when asked to use them, and with
44 ** longjmp/setjmp otherwise.
46 #if !defined(LUAI_THROW)
52 #elif defined(__x86_64__)
54 #elif defined(__sparc__) && defined(__arch64__)
56 #elif defined(__powerpc__)
57 #define JMP_BUF_CNT 26
58 #elif defined(__aarch64__)
59 #define JMP_BUF_CNT 64
60 #elif defined(__arm__)
61 #define JMP_BUF_CNT 65
62 #elif defined(__mips__)
63 #define JMP_BUF_CNT 12
64 #elif defined(__s390x__)
70 typedef struct _label_t
{ long long unsigned val
[JMP_BUF_CNT
]; } label_t
;
72 int setjmp(label_t
*) __attribute__ ((__nothrow__
));
73 extern void longjmp(label_t
*) __attribute__((__noreturn__
));
75 #define LUAI_THROW(L,c) longjmp(&(c)->b)
76 #define LUAI_TRY(L,c,a) if (setjmp(&(c)->b) == 0) { a }
77 #define luai_jmpbuf label_t
79 /* unsupported archs will build but not be able to run lua programs */
81 int setjmp (label_t
*buf
) {
85 void longjmp (label_t
* buf
) {
92 #if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
94 #define LUAI_THROW(L,c) throw(c)
95 #define LUAI_TRY(L,c,a) \
96 try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
97 #define luai_jmpbuf int /* dummy variable */
99 #elif defined(LUA_USE_ULONGJMP)
100 /* in Unix, try _longjmp/_setjmp (more efficient) */
101 #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
102 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
103 #define luai_jmpbuf jmp_buf
106 /* default handling with long jumps */
107 #define LUAI_THROW(L,c) longjmp((c)->b, 1)
108 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
109 #define luai_jmpbuf jmp_buf
115 #endif /* LUAI_THROW */
118 /* chain list of long jump buffers */
120 struct lua_longjmp
*previous
;
122 volatile int status
; /* error code */
126 static void seterrorobj (lua_State
*L
, int errcode
, StkId oldtop
) {
128 case LUA_ERRMEM
: { /* memory error? */
129 setsvalue2s(L
, oldtop
, G(L
)->memerrmsg
); /* reuse preregistered msg. */
133 setsvalue2s(L
, oldtop
, luaS_newliteral(L
, "error in error handling"));
137 setobjs2s(L
, oldtop
, L
->top
- 1); /* error message on current top */
145 l_noret
luaD_throw (lua_State
*L
, int errcode
) {
146 if (L
->errorJmp
) { /* thread has an error handler? */
147 L
->errorJmp
->status
= errcode
; /* set status */
148 LUAI_THROW(L
, L
->errorJmp
); /* jump to it */
150 else { /* thread has no error handler */
151 L
->status
= cast_byte(errcode
); /* mark it as dead */
152 if (G(L
)->mainthread
->errorJmp
) { /* main thread has a handler? */
153 setobjs2s(L
, G(L
)->mainthread
->top
++, L
->top
- 1); /* copy error obj. */
154 luaD_throw(G(L
)->mainthread
, errcode
); /* re-throw in main thread */
156 else { /* no handler at all; abort */
157 if (G(L
)->panic
) { /* panic function? */
159 G(L
)->panic(L
); /* call it (last chance to jump out) */
161 panic("no error handler");
167 int luaD_rawrunprotected (lua_State
*L
, Pfunc f
, void *ud
) {
168 unsigned short oldnCcalls
= L
->nCcalls
;
169 struct lua_longjmp lj
;
171 lj
.previous
= L
->errorJmp
; /* chain new error handler */
176 L
->errorJmp
= lj
.previous
; /* restore old error handler */
177 L
->nCcalls
= oldnCcalls
;
181 /* }====================================================== */
184 static void correctstack (lua_State
*L
, TValue
*oldstack
) {
187 L
->top
= (L
->top
- oldstack
) + L
->stack
;
188 for (up
= L
->openupval
; up
!= NULL
; up
= up
->gch
.next
)
189 gco2uv(up
)->v
= (gco2uv(up
)->v
- oldstack
) + L
->stack
;
190 for (ci
= L
->ci
; ci
!= NULL
; ci
= ci
->previous
) {
191 ci
->top
= (ci
->top
- oldstack
) + L
->stack
;
192 ci
->func
= (ci
->func
- oldstack
) + L
->stack
;
194 ci
->u
.l
.base
= (ci
->u
.l
.base
- oldstack
) + L
->stack
;
199 /* some space for error handling */
200 #define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
203 void luaD_reallocstack (lua_State
*L
, int newsize
) {
204 TValue
*oldstack
= L
->stack
;
205 int lim
= L
->stacksize
;
206 lua_assert(newsize
<= LUAI_MAXSTACK
|| newsize
== ERRORSTACKSIZE
);
207 lua_assert(L
->stack_last
- L
->stack
== L
->stacksize
- EXTRA_STACK
);
208 luaM_reallocvector(L
, L
->stack
, L
->stacksize
, newsize
, TValue
);
209 for (; lim
< newsize
; lim
++)
210 setnilvalue(L
->stack
+ lim
); /* erase new segment */
211 L
->stacksize
= newsize
;
212 L
->stack_last
= L
->stack
+ newsize
- EXTRA_STACK
;
213 correctstack(L
, oldstack
);
217 void luaD_growstack (lua_State
*L
, int n
) {
218 int size
= L
->stacksize
;
219 if (size
> LUAI_MAXSTACK
) /* error after extra size? */
220 luaD_throw(L
, LUA_ERRERR
);
222 int needed
= cast_int(L
->top
- L
->stack
) + n
+ EXTRA_STACK
;
223 int newsize
= 2 * size
;
224 if (newsize
> LUAI_MAXSTACK
) newsize
= LUAI_MAXSTACK
;
225 if (newsize
< needed
) newsize
= needed
;
226 if (newsize
> LUAI_MAXSTACK
) { /* stack overflow? */
227 luaD_reallocstack(L
, ERRORSTACKSIZE
);
228 luaG_runerror(L
, "stack overflow");
231 luaD_reallocstack(L
, newsize
);
236 static int stackinuse (lua_State
*L
) {
239 for (ci
= L
->ci
; ci
!= NULL
; ci
= ci
->previous
) {
240 lua_assert(ci
->top
<= L
->stack_last
);
241 if (lim
< ci
->top
) lim
= ci
->top
;
243 return cast_int(lim
- L
->stack
) + 1; /* part of stack in use */
247 void luaD_shrinkstack (lua_State
*L
) {
248 int inuse
= stackinuse(L
);
249 int goodsize
= inuse
+ (inuse
/ 8) + 2*EXTRA_STACK
;
250 if (goodsize
> LUAI_MAXSTACK
) goodsize
= LUAI_MAXSTACK
;
251 if (inuse
> LUAI_MAXSTACK
|| /* handling stack overflow? */
252 goodsize
>= L
->stacksize
) /* would grow instead of shrink? */
253 condmovestack(L
); /* don't change stack (change only for debugging) */
255 luaD_reallocstack(L
, goodsize
); /* shrink it */
259 void luaD_hook (lua_State
*L
, int event
, int line
) {
260 lua_Hook hook
= L
->hook
;
261 if (hook
&& L
->allowhook
) {
262 CallInfo
*ci
= L
->ci
;
263 ptrdiff_t top
= savestack(L
, L
->top
);
264 ptrdiff_t ci_top
= savestack(L
, ci
->top
);
267 ar
.currentline
= line
;
269 luaD_checkstack(L
, LUA_MINSTACK
); /* ensure minimum stack size */
270 ci
->top
= L
->top
+ LUA_MINSTACK
;
271 lua_assert(ci
->top
<= L
->stack_last
);
272 L
->allowhook
= 0; /* cannot call hooks inside a hook */
273 ci
->callstatus
|= CIST_HOOKED
;
277 lua_assert(!L
->allowhook
);
279 ci
->top
= restorestack(L
, ci_top
);
280 L
->top
= restorestack(L
, top
);
281 ci
->callstatus
&= ~CIST_HOOKED
;
286 static void callhook (lua_State
*L
, CallInfo
*ci
) {
287 int hook
= LUA_HOOKCALL
;
288 ci
->u
.l
.savedpc
++; /* hooks assume 'pc' is already incremented */
289 if (isLua(ci
->previous
) &&
290 GET_OPCODE(*(ci
->previous
->u
.l
.savedpc
- 1)) == OP_TAILCALL
) {
291 ci
->callstatus
|= CIST_TAIL
;
292 hook
= LUA_HOOKTAILCALL
;
294 luaD_hook(L
, hook
, -1);
295 ci
->u
.l
.savedpc
--; /* correct 'pc' */
299 static StkId
adjust_varargs (lua_State
*L
, Proto
*p
, int actual
) {
301 int nfixargs
= p
->numparams
;
303 lua_assert(actual
>= nfixargs
);
304 /* move fixed parameters to final position */
305 luaD_checkstack(L
, p
->maxstacksize
); /* check again for new 'base' */
306 fixed
= L
->top
- actual
; /* first fixed argument */
307 base
= L
->top
; /* final position of first argument */
308 for (i
=0; i
<nfixargs
; i
++) {
309 setobjs2s(L
, L
->top
++, fixed
+ i
);
310 setnilvalue(fixed
+ i
);
316 static StkId
tryfuncTM (lua_State
*L
, StkId func
) {
317 const TValue
*tm
= luaT_gettmbyobj(L
, func
, TM_CALL
);
319 ptrdiff_t funcr
= savestack(L
, func
);
320 if (!ttisfunction(tm
))
321 luaG_typeerror(L
, func
, "call");
322 /* Open a hole inside the stack at `func' */
323 for (p
= L
->top
; p
> func
; p
--) setobjs2s(L
, p
, p
-1);
325 func
= restorestack(L
, funcr
); /* previous call may change stack */
326 setobj2s(L
, func
, tm
); /* tag method is the new function to be called */
332 #define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))
336 ** returns true if function has been executed (C function)
338 int luaD_precall (lua_State
*L
, StkId func
, int nresults
) {
341 int n
; /* number of arguments (Lua) or returns (C) */
342 ptrdiff_t funcr
= savestack(L
, func
);
343 switch (ttype(func
)) {
344 case LUA_TLCF
: /* light C function */
347 case LUA_TCCL
: { /* C closure */
348 f
= clCvalue(func
)->f
;
350 luaD_checkstack(L
, LUA_MINSTACK
); /* ensure minimum stack size */
351 ci
= next_ci(L
); /* now 'enter' new function */
352 ci
->nresults
= nresults
;
353 ci
->func
= restorestack(L
, funcr
);
354 ci
->top
= L
->top
+ LUA_MINSTACK
;
355 lua_assert(ci
->top
<= L
->stack_last
);
357 luaC_checkGC(L
); /* stack grow uses memory */
358 if (L
->hookmask
& LUA_MASKCALL
)
359 luaD_hook(L
, LUA_HOOKCALL
, -1);
361 n
= (*f
)(L
); /* do the actual call */
363 api_checknelems(L
, n
);
364 luaD_poscall(L
, L
->top
- n
);
367 case LUA_TLCL
: { /* Lua function: prepare its call */
369 Proto
*p
= clLvalue(func
)->p
;
370 n
= cast_int(L
->top
- func
) - 1; /* number of real arguments */
371 luaD_checkstack(L
, p
->maxstacksize
);
372 for (; n
< p
->numparams
; n
++)
373 setnilvalue(L
->top
++); /* complete missing arguments */
375 func
= restorestack(L
, funcr
);
379 base
= adjust_varargs(L
, p
, n
);
380 func
= restorestack(L
, funcr
); /* previous call can change stack */
382 ci
= next_ci(L
); /* now 'enter' new function */
383 ci
->nresults
= nresults
;
386 ci
->top
= base
+ p
->maxstacksize
;
387 lua_assert(ci
->top
<= L
->stack_last
);
388 ci
->u
.l
.savedpc
= p
->code
; /* starting point */
389 ci
->callstatus
= CIST_LUA
;
391 luaC_checkGC(L
); /* stack grow uses memory */
392 if (L
->hookmask
& LUA_MASKCALL
)
396 default: { /* not a function */
397 func
= tryfuncTM(L
, func
); /* retry with 'function' tag method */
398 return luaD_precall(L
, func
, nresults
); /* now it must be a function */
404 int luaD_poscall (lua_State
*L
, StkId firstResult
) {
407 CallInfo
*ci
= L
->ci
;
408 if (L
->hookmask
& (LUA_MASKRET
| LUA_MASKLINE
)) {
409 if (L
->hookmask
& LUA_MASKRET
) {
410 ptrdiff_t fr
= savestack(L
, firstResult
); /* hook may change stack */
411 luaD_hook(L
, LUA_HOOKRET
, -1);
412 firstResult
= restorestack(L
, fr
);
414 L
->oldpc
= ci
->previous
->u
.l
.savedpc
; /* 'oldpc' for caller function */
416 res
= ci
->func
; /* res == final position of 1st result */
417 wanted
= ci
->nresults
;
418 L
->ci
= ci
= ci
->previous
; /* back to caller */
419 /* move results to correct place */
420 for (i
= wanted
; i
!= 0 && firstResult
< L
->top
; i
--)
421 setobjs2s(L
, res
++, firstResult
++);
425 return (wanted
- LUA_MULTRET
); /* 0 iff wanted == LUA_MULTRET */
430 ** Call a function (C or Lua). The function to be called is at *func.
431 ** The arguments are on the stack, right after the function.
432 ** When returns, all the results are on the stack, starting at the original
433 ** function position.
435 void luaD_call (lua_State
*L
, StkId func
, int nResults
, int allowyield
) {
436 if (++L
->nCcalls
>= LUAI_MAXCCALLS
) {
437 if (L
->nCcalls
== LUAI_MAXCCALLS
)
438 luaG_runerror(L
, "C stack overflow");
439 else if (L
->nCcalls
>= (LUAI_MAXCCALLS
+ (LUAI_MAXCCALLS
>>3)))
440 luaD_throw(L
, LUA_ERRERR
); /* error while handing stack error */
442 if (!allowyield
) L
->nny
++;
443 if (!luaD_precall(L
, func
, nResults
)) /* is a Lua function? */
444 luaV_execute(L
); /* call it */
445 if (!allowyield
) L
->nny
--;
450 static void finishCcall (lua_State
*L
) {
451 CallInfo
*ci
= L
->ci
;
453 lua_assert(ci
->u
.c
.k
!= NULL
); /* must have a continuation */
454 lua_assert(L
->nny
== 0);
455 if (ci
->callstatus
& CIST_YPCALL
) { /* was inside a pcall? */
456 ci
->callstatus
&= ~CIST_YPCALL
; /* finish 'lua_pcall' */
457 L
->errfunc
= ci
->u
.c
.old_errfunc
;
459 /* finish 'lua_callk'/'lua_pcall' */
460 adjustresults(L
, ci
->nresults
);
461 /* call continuation function */
462 if (!(ci
->callstatus
& CIST_STAT
)) /* no call status? */
463 ci
->u
.c
.status
= LUA_YIELD
; /* 'default' status */
464 lua_assert(ci
->u
.c
.status
!= LUA_OK
);
465 ci
->callstatus
= (ci
->callstatus
& ~(CIST_YPCALL
| CIST_STAT
)) | CIST_YIELDED
;
469 api_checknelems(L
, n
);
470 /* finish 'luaD_precall' */
471 luaD_poscall(L
, L
->top
- n
);
475 static void unroll (lua_State
*L
, void *ud
) {
478 if (L
->ci
== &L
->base_ci
) /* stack is empty? */
479 return; /* coroutine finished normally */
480 if (!isLua(L
->ci
)) /* C function? */
482 else { /* Lua function */
483 luaV_finishOp(L
); /* finish interrupted instruction */
484 luaV_execute(L
); /* execute down to higher C 'boundary' */
491 ** check whether thread has a suspended protected call
493 static CallInfo
*findpcall (lua_State
*L
) {
495 for (ci
= L
->ci
; ci
!= NULL
; ci
= ci
->previous
) { /* search for a pcall */
496 if (ci
->callstatus
& CIST_YPCALL
)
499 return NULL
; /* no pending pcall */
503 static int recover (lua_State
*L
, int status
) {
505 CallInfo
*ci
= findpcall(L
);
506 if (ci
== NULL
) return 0; /* no recovery point */
507 /* "finish" luaD_pcall */
508 oldtop
= restorestack(L
, ci
->extra
);
509 luaF_close(L
, oldtop
);
510 seterrorobj(L
, status
, oldtop
);
512 L
->allowhook
= ci
->u
.c
.old_allowhook
;
513 L
->nny
= 0; /* should be zero to be yieldable */
515 L
->errfunc
= ci
->u
.c
.old_errfunc
;
516 ci
->callstatus
|= CIST_STAT
; /* call has error status */
517 ci
->u
.c
.status
= status
; /* (here it is) */
518 return 1; /* continue running the coroutine */
523 ** signal an error in the call to 'resume', not in the execution of the
524 ** coroutine itself. (Such errors should not be handled by any coroutine
525 ** error handler and should not kill the coroutine.)
527 static l_noret
resume_error (lua_State
*L
, const char *msg
, StkId firstArg
) {
528 L
->top
= firstArg
; /* remove args from the stack */
529 setsvalue2s(L
, L
->top
, luaS_new(L
, msg
)); /* push error message */
531 luaD_throw(L
, -1); /* jump back to 'lua_resume' */
536 ** do the work for 'lua_resume' in protected mode
538 static void resume_cb (lua_State
*L
, void *ud
) {
539 int nCcalls
= L
->nCcalls
;
540 StkId firstArg
= cast(StkId
, ud
);
541 CallInfo
*ci
= L
->ci
;
542 if (nCcalls
>= LUAI_MAXCCALLS
)
543 resume_error(L
, "C stack overflow", firstArg
);
544 if (L
->status
== LUA_OK
) { /* may be starting a coroutine */
545 if (ci
!= &L
->base_ci
) /* not in base level? */
546 resume_error(L
, "cannot resume non-suspended coroutine", firstArg
);
547 /* coroutine is in base level; start running it */
548 if (!luaD_precall(L
, firstArg
- 1, LUA_MULTRET
)) /* Lua function? */
549 luaV_execute(L
); /* call it */
551 else if (L
->status
!= LUA_YIELD
)
552 resume_error(L
, "cannot resume dead coroutine", firstArg
);
553 else { /* resuming from previous yield */
555 ci
->func
= restorestack(L
, ci
->extra
);
556 if (isLua(ci
)) /* yielded inside a hook? */
557 luaV_execute(L
); /* just continue running Lua code */
558 else { /* 'common' yield */
559 if (ci
->u
.c
.k
!= NULL
) { /* does it have a continuation? */
561 ci
->u
.c
.status
= LUA_YIELD
; /* 'default' status */
562 ci
->callstatus
|= CIST_YIELDED
;
564 n
= (*ci
->u
.c
.k
)(L
); /* call continuation */
566 api_checknelems(L
, n
);
567 firstArg
= L
->top
- n
; /* yield results come from continuation */
569 luaD_poscall(L
, firstArg
); /* finish 'luaD_precall' */
573 lua_assert(nCcalls
== L
->nCcalls
);
577 LUA_API
int lua_resume (lua_State
*L
, lua_State
*from
, int nargs
) {
579 int oldnny
= L
->nny
; /* save 'nny' */
581 luai_userstateresume(L
, nargs
);
582 L
->nCcalls
= (from
) ? from
->nCcalls
+ 1 : 1;
583 L
->nny
= 0; /* allow yields */
584 api_checknelems(L
, (L
->status
== LUA_OK
) ? nargs
+ 1 : nargs
);
585 status
= luaD_rawrunprotected(L
, resume_cb
, L
->top
- nargs
);
586 if (status
== -1) /* error calling 'lua_resume'? */
588 else { /* yield or regular error */
589 while (status
!= LUA_OK
&& status
!= LUA_YIELD
) { /* error? */
590 if (recover(L
, status
)) /* recover point? */
591 status
= luaD_rawrunprotected(L
, unroll
, NULL
); /* run continuation */
592 else { /* unrecoverable error */
593 L
->status
= cast_byte(status
); /* mark thread as `dead' */
594 seterrorobj(L
, status
, L
->top
);
599 lua_assert(status
== L
->status
);
601 L
->nny
= oldnny
; /* restore 'nny' */
603 lua_assert(L
->nCcalls
== ((from
) ? from
->nCcalls
: 0));
609 LUA_API
int lua_yieldk (lua_State
*L
, int nresults
, int ctx
, lua_CFunction k
) {
610 CallInfo
*ci
= L
->ci
;
611 luai_userstateyield(L
, nresults
);
613 api_checknelems(L
, nresults
);
615 if (L
!= G(L
)->mainthread
)
616 luaG_runerror(L
, "attempt to yield across a C-call boundary");
618 luaG_runerror(L
, "attempt to yield from outside a coroutine");
620 L
->status
= LUA_YIELD
;
621 ci
->extra
= savestack(L
, ci
->func
); /* save current 'func' */
622 if (isLua(ci
)) { /* inside a hook? */
623 api_check(L
, k
== NULL
, "hooks cannot continue after yielding");
626 if ((ci
->u
.c
.k
= k
) != NULL
) /* is there a continuation? */
627 ci
->u
.c
.ctx
= ctx
; /* save context */
628 ci
->func
= L
->top
- nresults
- 1; /* protect stack below results */
629 luaD_throw(L
, LUA_YIELD
);
631 lua_assert(ci
->callstatus
& CIST_HOOKED
); /* must be inside a hook */
633 return 0; /* return to 'luaD_hook' */
637 int luaD_pcall (lua_State
*L
, Pfunc func
, void *u
,
638 ptrdiff_t old_top
, ptrdiff_t ef
) {
640 CallInfo
*old_ci
= L
->ci
;
641 lu_byte old_allowhooks
= L
->allowhook
;
642 unsigned short old_nny
= L
->nny
;
643 ptrdiff_t old_errfunc
= L
->errfunc
;
645 status
= luaD_rawrunprotected(L
, func
, u
);
646 if (status
!= LUA_OK
) { /* an error occurred? */
647 StkId oldtop
= restorestack(L
, old_top
);
648 luaF_close(L
, oldtop
); /* close possible pending closures */
649 seterrorobj(L
, status
, oldtop
);
651 L
->allowhook
= old_allowhooks
;
655 L
->errfunc
= old_errfunc
;
662 ** Execute a protected parser.
664 struct SParser
{ /* data to `f_parser' */
666 Mbuffer buff
; /* dynamic structure used by the scanner */
667 Dyndata dyd
; /* dynamic structures used by the parser */
673 static void checkmode (lua_State
*L
, const char *mode
, const char *x
) {
674 if (mode
&& strchr(mode
, x
[0]) == NULL
) {
676 "attempt to load a %s chunk (mode is " LUA_QS
")", x
, mode
);
677 luaD_throw(L
, LUA_ERRSYNTAX
);
682 static void f_parser (lua_State
*L
, void *ud
) {
685 struct SParser
*p
= cast(struct SParser
*, ud
);
686 int c
= zgetc(p
->z
); /* read first character */
687 if (c
== LUA_SIGNATURE
[0]) {
688 checkmode(L
, p
->mode
, "binary");
689 cl
= luaU_undump(L
, p
->z
, &p
->buff
, p
->name
);
692 checkmode(L
, p
->mode
, "text");
693 cl
= luaY_parser(L
, p
->z
, &p
->buff
, &p
->dyd
, p
->name
, c
);
695 lua_assert(cl
->l
.nupvalues
== cl
->l
.p
->sizeupvalues
);
696 for (i
= 0; i
< cl
->l
.nupvalues
; i
++) { /* initialize upvalues */
697 UpVal
*up
= luaF_newupval(L
);
698 cl
->l
.upvals
[i
] = up
;
699 luaC_objbarrier(L
, cl
, up
);
704 int luaD_protectedparser (lua_State
*L
, ZIO
*z
, const char *name
,
708 L
->nny
++; /* cannot yield during parsing */
709 p
.z
= z
; p
.name
= name
; p
.mode
= mode
;
710 p
.dyd
.actvar
.arr
= NULL
; p
.dyd
.actvar
.size
= 0;
711 p
.dyd
.gt
.arr
= NULL
; p
.dyd
.gt
.size
= 0;
712 p
.dyd
.label
.arr
= NULL
; p
.dyd
.label
.size
= 0;
713 luaZ_initbuffer(L
, &p
.buff
);
714 status
= luaD_pcall(L
, f_parser
, &p
, savestack(L
, L
->top
), L
->errfunc
);
715 luaZ_freebuffer(L
, &p
.buff
);
716 luaM_freearray(L
, p
.dyd
.actvar
.arr
, p
.dyd
.actvar
.size
);
717 luaM_freearray(L
, p
.dyd
.gt
.arr
, p
.dyd
.gt
.size
);
718 luaM_freearray(L
, p
.dyd
.label
.arr
, p
.dyd
.label
.size
);