diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-19 17:34:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-19 17:34:22 -0300 |
commit | f407b3c4a1bc9667867ec51e835c20d97aab55a2 (patch) | |
tree | ad629983fbde70d5446411d765a99a1b724eb82b /ldo.c | |
parent | a546138d158d79d44b2c5b42630be00d306f4e7c (diff) | |
download | lua-f407b3c4a1bc9667867ec51e835c20d97aab55a2.tar.gz lua-f407b3c4a1bc9667867ec51e835c20d97aab55a2.tar.bz2 lua-f407b3c4a1bc9667867ec51e835c20d97aab55a2.zip |
Using CIST_CLSRET instead of trick with 'nresults'
The callstatus flag CIST_CLSRET is used in all tests for the
presence of variables to be closed in C functions.
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -462,22 +462,23 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
462 | StkId firstresult; | 462 | StkId firstresult; |
463 | int i; | 463 | int i; |
464 | switch (wanted) { /* handle typical cases separately */ | 464 | switch (wanted) { /* handle typical cases separately */ |
465 | case 0: /* no values needed */ | 465 | case 0 + 1: /* no values needed */ |
466 | L->top.p = res; | 466 | L->top.p = res; |
467 | return; | 467 | return; |
468 | case 1: /* one value needed */ | 468 | case 1 + 1: /* one value needed */ |
469 | if (nres == 0) /* no results? */ | 469 | if (nres == 0) /* no results? */ |
470 | setnilvalue(s2v(res)); /* adjust with nil */ | 470 | setnilvalue(s2v(res)); /* adjust with nil */ |
471 | else /* at least one result */ | 471 | else /* at least one result */ |
472 | setobjs2s(L, res, L->top.p - nres); /* move it to proper place */ | 472 | setobjs2s(L, res, L->top.p - nres); /* move it to proper place */ |
473 | L->top.p = res + 1; | 473 | L->top.p = res + 1; |
474 | return; | 474 | return; |
475 | case LUA_MULTRET: | 475 | case LUA_MULTRET + 1: |
476 | wanted = nres; /* we want all results */ | 476 | wanted = nres; /* we want all results */ |
477 | break; | 477 | break; |
478 | default: /* two/more results and/or to-be-closed variables */ | 478 | default: /* two/more results and/or to-be-closed variables */ |
479 | if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ | 479 | if (!(wanted & CIST_CLSRET)) |
480 | L->ci->callstatus |= CIST_CLSRET; /* in case of yields */ | 480 | wanted--; |
481 | else { /* to-be-closed variables? */ | ||
481 | L->ci->u2.nres = nres; | 482 | L->ci->u2.nres = nres; |
482 | res = luaF_close(L, res, CLOSEKTOP, 1); | 483 | res = luaF_close(L, res, CLOSEKTOP, 1); |
483 | L->ci->callstatus &= ~CIST_CLSRET; | 484 | L->ci->callstatus &= ~CIST_CLSRET; |
@@ -486,7 +487,7 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
486 | rethook(L, L->ci, nres); | 487 | rethook(L, L->ci, nres); |
487 | res = restorestack(L, savedres); /* hook can move stack */ | 488 | res = restorestack(L, savedres); /* hook can move stack */ |
488 | } | 489 | } |
489 | wanted = decodeNresults(wanted); | 490 | wanted = (wanted & ~CIST_CLSRET) - 1; |
490 | if (wanted == LUA_MULTRET) | 491 | if (wanted == LUA_MULTRET) |
491 | wanted = nres; /* we want all results */ | 492 | wanted = nres; /* we want all results */ |
492 | } | 493 | } |
@@ -511,8 +512,10 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
511 | ** that. | 512 | ** that. |
512 | */ | 513 | */ |
513 | void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { | 514 | void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { |
514 | int wanted = ci->nresults; | 515 | int wanted = ci->nresults + 1; |
515 | if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted))) | 516 | if (ci->callstatus & CIST_CLSRET) |
517 | wanted |= CIST_CLSRET; /* don't check hook in this case */ | ||
518 | else if (l_unlikely(L->hookmask)) | ||
516 | rethook(L, ci, nres); | 519 | rethook(L, ci, nres); |
517 | /* move results to proper place */ | 520 | /* move results to proper place */ |
518 | moveresults(L, ci->func.p, nres, wanted); | 521 | moveresults(L, ci->func.p, nres, wanted); |
@@ -736,7 +739,6 @@ static int finishpcallk (lua_State *L, CallInfo *ci) { | |||
736 | static void finishCcall (lua_State *L, CallInfo *ci) { | 739 | static void finishCcall (lua_State *L, CallInfo *ci) { |
737 | int n; /* actual number of results from C function */ | 740 | int n; /* actual number of results from C function */ |
738 | if (ci->callstatus & CIST_CLSRET) { /* was returning? */ | 741 | if (ci->callstatus & CIST_CLSRET) { /* was returning? */ |
739 | lua_assert(hastocloseCfunc(ci->nresults)); | ||
740 | n = ci->u2.nres; /* just redo 'luaD_poscall' */ | 742 | n = ci->u2.nres; /* just redo 'luaD_poscall' */ |
741 | /* don't need to reset CIST_CLSRET, as it will be set again anyway */ | 743 | /* don't need to reset CIST_CLSRET, as it will be set again anyway */ |
742 | } | 744 | } |