question about callTMres

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

question about callTMres

Antero Vipunen
Hi,

I noticed a strange code in lvm.c
 > static void callTMres ([skipped]) {
 >   [skipped]
 >   setobj2s(L, L->top, f);  /* push function */
 >   setobj2s(L, L->top+1, p1);  /* 1st argument */
 >   setobj2s(L, L->top+2, p2);  /* 2nd argument */
 >   luaD_checkstack(L, 3);

Why to check stack _after_ not _before_ ``pushing''?

TIA,
  Antero Vipunen.




Reply | Threaded
Open this post in threaded view
|

Re: question about callTMres

Roberto Ierusalimschy
> Why to check stack _after_ not _before_ ``pushing''?

The call to luaD_checkstack may reallocate the stack, invalidating p1
and p2. The stack always has some free slots (EXTRA_STACK) to allow
those pushings.

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: question about callTMres

Antero Vipunen
Roberto Ierusalimschy wrote:

>The call to luaD_checkstack may reallocate the stack, invalidating p1
>and p2. The stack always has some free slots (EXTRA_STACK) to allow
>those pushings.
>  
>
Now I see... Thank you.

AMDG,
  Antero Vipunen.