[Gambas-user] Segfault when freeing pointer used for Extern

Bruce bbruen at ...2308...
Wed Nov 6 03:01:49 CET 2013


> On Wed, Nov 6, 2013 at 2:56 AM, Benoît Minisini <
> gambas at ...1...> wrote:
> 
> > Now your code:
> >
> > ----------------------------------------------------------------------
> 8*<
> > ----> OP must points at a 16 bytes allocation. So you failed! The
> > library will erase the memory past the allocation, making everything
> > crash sooner or later.

OK! Now I understand.

> >    rtn = UUID_ToStr(OP, SP)
> >
> > ----> That function returns nothing. I don't know why you think Gambas
> > will make it return something. Moreover, if you read the doc, it tells
> > you that SP must point at a 37 bytes allocation. So you failed again,
> > and the library will erase the memory randomly a second time.

Ditto.
(Probably didn't look at it closely enough to see the void in the
declaration.)

> > You really must know C and how a CPU works to deal with extern
> > functions. Alas, Gambas can't help there! Or, at least, it does as much
> > as he can.

Ah there lies the problem! When I learnt programming back in 1972 we had
to carve our cpu's out of a lump of granite with a cold chisel, K&R
hadn't even written troff so I never did get the hang of this newfangled
malloc and pointer and c stuff!  Let alone c++ :-)

On Wed, 2013-11-06 at 03:03 +0200, Jussi Lahtinen wrote:
> Correct code:
8*<

Works fine! 

Thanks Benoît and Jussi,
I was fairly sure I had it wrong, I just couldn't see why.
Unfortunately since my colleague Keith Lawson passed away I have had to
cope with this type of "low level" issue myself without an expert on
tap.

At least give me 2 points of credit for working out that the output
parameters of the library calls were actually pointers to something.

regards
Bruce

p.s. Just saw Benoît's wiki update notice.  Did that page exist before?
I spent an hour this morning looking for something like that.





More information about the User mailing list