lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I don't have a 10.7 box handy (and I'm increasingly surly about supporting OS X, since Apple seems to want to run away from gcc AFAICT so they can stop releasing source.)

On May 4, 2013, at 7:14 AM, Luiz Henrique de Figueiredo wrote:

[ "return (*cf)(L);" is broken ]

> This also works but I still don't know why it should be necessary:
> 
> static int aux_close (lua_State *L) {
>  LStream *p = tolstream(L);
>  lua_CFunction cf = p->closef;
>  int rc = (cf)(L);  /* close it */
>  p->closef = NULL;  /* mark stream as closed */
>  return rc;
> }

In other words, a proper tail-call through a function pointer is broken. It's possible the callpoint is not the place where the compiler screwed up; it could have made a mistake when storing the function pointer into the struct luaL_Stream. 

I wonder if the compiler is over-optimizing this case for private symbols; perhaps it's skipping over some amount of prolog because the function is local. Taking the address of a global symbol is a great deal more expensive in ELF at least, since it can't lazy-bind the symbol resolution the way it can just calling a global symbol.

The error may go away if you make the closef functions non-static. This is not a viable fix, of course.

Jay