Memory allocation error in lpeg v0.9

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

Memory allocation error in lpeg v0.9

Cedric Mauclair
Hi everyone,

I have compiled Lua 5.1.4 and lpeg 0.9 from the sources on Mac OS X
10.6.4, default flags, nothing special appart the prefix. Lua works
fine, as far as I can tell from my basic usage (I succeeded to build
and use lpdf). lpeg seems to work, but the tests won't succeed. When I
run the tests, it ends up with the message :

lua(1709) malloc: *** error for object 0x10001f6c0: pointer being
freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap

The figures are different each time of course. I have no idea where
this comes from as I didn't went through all the Lua and lpeg C code.
Is there a bug in Lua or in lpeg ? After doing a little research in
the test file ('test.lua'), it stops working in the 'tests for any*n'
part. I commented out the loop, it went a little further as it printed
a '+' but it stopped again with the same awkward message.

Has anybody an idea of what's going on ?

Thanks

-- Cédric
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Linker
Hi Cédric,
  You can add the following line to the test.lua:
collectgarbage("stop")
  It will help you to work around the problem.

--
Regards,
Linker Lin

[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Cedric Mauclair
On Wed, Aug 4, 2010 at 10:50, Linker <[hidden email]> wrote:
> Hi Cédric,
>   You can add the following line to the test.lua:
> collectgarbage("stop")
>   It will help you to work around the problem.

Thank you. I tried that and I got 3 pluses in less than a second. I
imagine that it means 3 tests succeeded. However, I get a 'Bus error'
now. :-(

>
> --
> Regards,
> Linker Lin
> [hidden email]
>

-- Cédric
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Romulo
Have you checked if you are not static linking any of the shared libs?

On 8/4/10, Cedric Mauclair <[hidden email]> wrote:

> On Wed, Aug 4, 2010 at 10:50, Linker <[hidden email]> wrote:
>> Hi Cédric,
>>   You can add the following line to the test.lua:
>> collectgarbage("stop")
>>   It will help you to work around the problem.
>
> Thank you. I tried that and I got 3 pluses in less than a second. I
> imagine that it means 3 tests succeeded. However, I get a 'Bus error'
> now. :-(
>
>>
>> --
>> Regards,
>> Linker Lin
>> [hidden email]
>>
>
> -- Cédric
>

--
Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Cedric Mauclair
Hum... I guess not. I will check.

-- Cédric

On Wed, Aug 4, 2010 at 13:24, Romulo <[hidden email]> wrote:

> Have you checked if you are not static linking any of the shared libs?
>
> On 8/4/10, Cedric Mauclair <[hidden email]> wrote:
>> On Wed, Aug 4, 2010 at 10:50, Linker <[hidden email]> wrote:
>>> Hi Cédric,
>>>   You can add the following line to the test.lua:
>>> collectgarbage("stop")
>>>   It will help you to work around the problem.
>>
>> Thank you. I tried that and I got 3 pluses in less than a second. I
>> imagine that it means 3 tests succeeded. However, I get a 'Bus error'
>> now. :-(
>>
>>>
>>> --
>>> Regards,
>>> Linker Lin
>>> [hidden email]
>>>
>>
>> -- Cédric
>>
>
> --
> Sent from my mobile device
>
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Cedric Mauclair
In my libs directory, I have a liblua.a  (which is a static library if
I understand correctly). I used the following to compile LPeg library:

gcc -Wall -Wextra -pedantic -Waggregate-return -Wbad-function-cast
-Wcast-align -Wcast-qual -Wdeclaration-after-statement
-Wdisabled-optimization -Wmissing-prototypes -Wnested-externs
-Wpointer-arith -Wshadow -Wsign-compare -Wstrict-prototypes -Wundef
-Wwrite-strings  -O2 -DNDEBUG -ansi -I/opt/include   -c -o lpeg.o
lpeg.c

gcc -shared  -L/opt/lib -llua lpeg.o -o lpeg.so

I added the '-llua' part and I believe that's what is messing things
up. If I do not put this however, it doesn't compile with lots of
undefined symbols '_lua_something'. Would a liblua.so fix things? How
can I make one from Lua sources?

Thanks


-- Cédric



On Wed, Aug 4, 2010 at 13:30, Cedric Mauclair <[hidden email]> wrote:

> Hum... I guess not. I will check.
>
> -- Cédric
>
> On Wed, Aug 4, 2010 at 13:24, Romulo <[hidden email]> wrote:
>> Have you checked if you are not static linking any of the shared libs?
>>
>> On 8/4/10, Cedric Mauclair <[hidden email]> wrote:
>>> On Wed, Aug 4, 2010 at 10:50, Linker <[hidden email]> wrote:
>>>> Hi Cédric,
>>>>   You can add the following line to the test.lua:
>>>> collectgarbage("stop")
>>>>   It will help you to work around the problem.
>>>
>>> Thank you. I tried that and I got 3 pluses in less than a second. I
>>> imagine that it means 3 tests succeeded. However, I get a 'Bus error'
>>> now. :-(
>>>
>>>>
>>>> --
>>>> Regards,
>>>> Linker Lin
>>>> [hidden email]
>>>>
>>>
>>> -- Cédric
>>>
>>
>> --
>> Sent from my mobile device
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Thomas Harning Jr.
On Wed, Aug 4, 2010 at 9:20 AM, Cedric Mauclair
<[hidden email]> wrote:

> In my libs directory, I have a liblua.a  (which is a static library if
> I understand correctly). I used the following to compile LPeg library:
>
> gcc -Wall -Wextra -pedantic -Waggregate-return -Wbad-function-cast
> -Wcast-align -Wcast-qual -Wdeclaration-after-statement
> -Wdisabled-optimization -Wmissing-prototypes -Wnested-externs
> -Wpointer-arith -Wshadow -Wsign-compare -Wstrict-prototypes -Wundef
> -Wwrite-strings  -O2 -DNDEBUG -ansi -I/opt/include   -c -o lpeg.o
> lpeg.c
>
> gcc -shared  -L/opt/lib -llua lpeg.o -o lpeg.so
You need to use
gcc -bundle -undefined dynamic_lookup -o lpeg.so lpeg.o

for Mac OSX to safely work.  The -undefined dynamic_lookup makes it
search the namespace of the current process for undefined symbols.
--
Thomas Harning Jr.
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Cedric Mauclair
Wow ! It worked.
Can I ask how I was suppose to know something like that? Is it a well
known bug/trick/idiom for building things on Mac OS X? I think I will
try to do the same with the other Lua libraries I built.

Very much thanks anyway. I hope this will help other non C programers
and/or compilation gurus or whatever like me.

-- Cédric



On Wed, Aug 4, 2010 at 15:32, Thomas Harning Jr. <[hidden email]> wrote:

> On Wed, Aug 4, 2010 at 9:20 AM, Cedric Mauclair
> <[hidden email]> wrote:
>> In my libs directory, I have a liblua.a  (which is a static library if
>> I understand correctly). I used the following to compile LPeg library:
>>
>> gcc -Wall -Wextra -pedantic -Waggregate-return -Wbad-function-cast
>> -Wcast-align -Wcast-qual -Wdeclaration-after-statement
>> -Wdisabled-optimization -Wmissing-prototypes -Wnested-externs
>> -Wpointer-arith -Wshadow -Wsign-compare -Wstrict-prototypes -Wundef
>> -Wwrite-strings  -O2 -DNDEBUG -ansi -I/opt/include   -c -o lpeg.o
>> lpeg.c
>>
>> gcc -shared  -L/opt/lib -llua lpeg.o -o lpeg.so
> You need to use
> gcc -bundle -undefined dynamic_lookup -o lpeg.so lpeg.o
>
> for Mac OSX to safely work.  The -undefined dynamic_lookup makes it
> search the namespace of the current process for undefined symbols.
> --
> Thomas Harning Jr.
>
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

steve donovan
On Wed, Aug 4, 2010 at 3:52 PM, Cedric Mauclair
<[hidden email]> wrote:
> Can I ask how I was suppose to know something like that? Is it a well
> known bug/trick/idiom for building things on Mac OS X?

It's the standard way.  OS X is ... different.
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Luiz Henrique de Figueiredo
In reply to this post by Cedric Mauclair
> Can I ask how I was suppose to know something like that? Is it a well
> known bug/trick/idiom for building things on Mac OS X? I think I will
> try to do the same with the other Lua libraries I built.

See
        http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html#building
        http://lua-users.org/wiki/BuildingModules
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Cedric Mauclair
Oops! I guess someone didn't learn his lessons. Always read the manual
first! Sorry.

Thanks everybody.

-- Cédric



On Wed, Aug 4, 2010 at 15:58, Luiz Henrique de Figueiredo
<[hidden email]> wrote:
>> Can I ask how I was suppose to know something like that? Is it a well
>> known bug/trick/idiom for building things on Mac OS X? I think I will
>> try to do the same with the other Lua libraries I built.
>
> See
>        http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html#building
>        http://lua-users.org/wiki/BuildingModules
>
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation error in lpeg v0.9

Enrico Colombini
In reply to this post by steve donovan
On 04/08/2010 15.53, steve donovan wrote:
> It's the standard way.  OS X is ... different.

"Link different" :-)

   Enrico