[Gambas-devel] bug in object creation, or in my pcre component?

Benoit Minisini gambas at ...1...
Tue Jan 25 17:05:35 CET 2005


On Friday 21 January 2005 19:15, Rob wrote:
> Using the latest version of pcre I posted to the list, I noticed
> some crashing behavior.
>
> r = new Regexp("foo", "(foo)")
> print r.submatches[1].text
> ...
> r = new Regexp("bar", "(bar)")
> print r.submatches[1].text
>
> causes a segmentation fault in gbx2 on the last line, but this
> code:
>
> r = new Regexp("foo", "(foo)")
> print r.submatches[1].text
> ...
> r = NULL
> r = new Regexp("bar", "(bar)")
> print r.submatches[1].text
>
> does not.  Near as I can figure from sticking a bunch of
> fprintf(stderr, ...)'s in my pcre component is that the Gambas
> interpreter somehow instantiates the new component before
> freeing the old one, resulting in r containing a null pointer
> (on the C side), and forcing it to be done in two steps gets
> around the problem.
>
> So is there a problem in my component's cleanup code or is it an
> interpreter thing?
>
> Rob
>

Another point. You did:

  GB.NewString(&tmp, GB.ToZeroString(ARG(subject)), 0);

As 'subject' is already a GB_STRING parameter, you create a useless temporary 
string. Instead, do that:

  GB.NewString(&tmp, STRING(subject), LENGTH(subject));

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list