[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] lrexlib 2.7.2 released
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 10 Jan 2013 10:37:19 -0200
> > #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