lua-users home
lua-l archive

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


> > #define LUA_ALLOC(p,size)       lua_getallocf(L,NULL)(NULL,p,0,size)
> > #define malloc(size)            LUA_ALLOC(NULL,size)
> > #define free(p)                 LUA_ALLOC(p,0)
> > #define realloc(p)              LUA_ALLOC(p,size)
> >
> > This code assumes a Lua state named L in the scope. If that is not the case,
> > fix LUA_ALLOC.
> >
> 
> Be careful as this can result in undefined behaviour as malloc, free
> and realloc can be reserved identifiers, see 7.1.3 C99 for more info.

Moreover, that state may not be using the standard allocator. (That is
the whole point of using allocf instead of malloc, after all). In that
case, the allocator function may need the opaque pointer associated to
it and/or the original size of each bock.

-- Roberto