[ANN] lrexlib 2.7.2 released

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

[ANN] lrexlib 2.7.2 released

Reuben Thomas-5
I am happy to announce the release of lrexlib 2.7.2,
Lua binding for regex libraries.

  * Fixed the use of alternative allocators, and a memory leak.
  * Simplify the build system further.
  * Change rockspec to build from git now that github no longer
    supports downloads.

Install it as luarock lrexlib-gnu-2.7.2, lrexlib-oniguruma-2.7.2,
lrexlib-pcre-2.7.2, lrexlib-posix-2.7.2, lrexlib-tre-2.7.2 (see
http://luarocks.org/repositories/rocks )
lrexlib's home page is at https://github.com/rrthomas/lrexlib

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] lrexlib 2.7.2 released

Reuben Thomas-5

On 9 January 2013, someone asked me:
Hi,
out of curiosity, why did you change rlexlib to use Lua's allocator?  I tried finding any comments/notes explaining why, in the change notes and on the mailing list, but couldn't find it.

[Although this question was not asked on lua-l, I thought it would be good to send a reply there.]

lrexlib 2.7.x uses, where possible, the Lua state's allocator, rather than malloc. This is done because it seems to me this is what one would expect: if one chooses a different allocator for one's Lua state, e.g. for debugging or performance reasons, then it should be used for everything.

Unfortunately, it's not possible to use it for absolutely everything, because some memory is allocated and/or freed by a given regex library.

I notice now that PCRE allows its allocator functions to be overridden, so I shall do that; unfortunately, GNU, POSIX, oniguruma and TRE all don't.
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] lrexlib 2.7.2 released

Reuben Thomas-5

On Jan 9, 2013 1:02 PM, "Reuben Thomas" <[hidden email]> wrote:
>
>
> I notice now that PCRE allows its allocator functions to be overridden, so I shall do that; unfortunately, GNU, POSIX, oniguruma and TRE all don't.

Unfortunately, PCRE uses global variables to override the allocation functions, so lrexlib would have to set them before every API call. So I won't be making this change.

Reply | Threaded
Open this post in threaded view
|

RE: [ANN] lrexlib 2.7.2 released

Thijs Schreijer
In reply to this post by Reuben Thomas-5
> [Although this question was not asked on lua-l, I thought it would be good
> to send a reply there.] lrexlib 2.7.x uses, where possible, the Lua
> state's allocator, rather than malloc. This is done because it seems to me
> this is what one would expect: if one chooses a different allocator for
> one's Lua state, e.g. for debugging or performance reasons, then it should
> be used for everything.
>
> Unfortunately, it's not possible to use it for absolutely everything,
> because some memory is allocated and/or freed by a given regex library.
> I notice now that PCRE allows its allocator functions to be overridden, so
> I shall do that; unfortunately, GNU, POSIX, oniguruma and TRE all don't.

Is this generally considered good practice? The thought never crossed my mind.
Anyone else doing this, or explicitly not doing this?

Haven't looked into it yet, but is there an easy way to convert from malloc and free to using the Lua allocator? Some macros perhaps? Any example code?

Thijs


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] lrexlib 2.7.2 released

Luiz Henrique de Figueiredo
> is there an easy way to convert from malloc and free to using the Lua allocator? Some macros perhaps? Any example code?

#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.

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] lrexlib 2.7.2 released

liam mail
On 10 January 2013 00:38, Luiz Henrique de Figueiredo
<[hidden email]> wrote:

>> is there an easy way to convert from malloc and free to using the Lua allocator? Some macros perhaps? Any example code?
>
> #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.

--Liam

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] lrexlib 2.7.2 released

Roberto Ierusalimschy
> > #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