Re: bug in simplify_shallow

Bill Allombert <[email protected]>
Newsgroups gmane.comp.mathematics.pari.devel
Message-ID <ZOtHFLdXr0FuLCzY@seventeen>
On Sat, Aug 26, 2023 at 03:47:09PM +0200, Karim Belabas wrote:
> You'll see it with valgrind.
> 
> >From the GP code, I can guess what's happening: the lexical variable L
> will be destroyed (gunclone) when we leave the user function scope. But
> that user function still returns the return value of listput() which is
> the element stored in the list. The latter is a 'clone' (as all list
> entries), so supposedly safe. The lexical variable destructor breaks
> that asumption.
> 
> I don't think the reference count machinery currently in place can
> deal with this. Adding a gcopy somewhere should be enough (but slow down
> all 'listput' operations...). Don't have time to delve in the C code
> right now to confirm this; I'll have a look later if Bill doesn't beat
> me to it :-)

Well, we could probably change listput  (and listinsert) to use the prototype
code m.  But to be honest I did not remember that listput returned x and it is
not explicitly documented, and the implementation is awkward.
(the simple, correct implementation would return gcopy of the original x, not a clone 
of it).

Cheers,
Bill.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.