Clean up by iiExprArith(Intern)

10 views
Skip to first unread message

Jean-Pierre Flori

unread,
Oct 25, 2016, 6:11:55 AM10/25/16
to libsingular-devel
Hello all,

I see that the following commit
* https://github.com/Singular/Sources/commit/86ce458e1269a1d57e682c12b9154dd1f1459354
claims that iiExprArithIntern does no clean up as iiExprArith does it.
But it seems to me iiExprArith directly returns when calling iiExprArithIntern:
* https://github.com/Singular/Sources/blob/spielwiese/Singular/iparith.cc#L8142

This unfortunately makes Sage code segfault when going from 4.0.3p3 to 4.0.3p4 although I thing that Sage's code is also faulty.
What we do is calling iiExprArith and then calling the CleanUp function on the args we passed to it, with for some reason the ring set to NULL.

Before it was ok because the iiExprArithIntern already called the CleanUp function with the ring set and the args were cleaned up within the call to iiExprArith.
Therefore when Sage called a second time on the args without a ring set, the args were already empty and the CleanUp function did nothing.

Now when iiExprArith returns the args are not cleaned up anymore.
We then call the CleanUp function on them with a ring set to NULL and boom.

Any advice welcome!

Best,
JPF

Jean-Pierre Flori

unread,
Oct 25, 2016, 6:30:58 AM10/25/16
to libsingular-devel
In particular in Sage, we clean up args for kernel functions :
* https://github.com/sagemath/sage/blob/master/src/sage/libs/singular/function.pyx#L1153
but not for library functions :
* https://github.com/sagemath/sage/blob/master/src/sage/libs/singular/function.pyx#L1068

I don't know enough to tell why we do so.
Although the previous message shows there is an issue.

Maybe the difference is just about calling omFreeBin in the kernel case ourselves but not in the library case.
And we should never care about sleftv::CleanUp.
These are the only things our free_leftv function does:
* https://github.com/sagemath/sage/blob/master/src/sage/libs/singular/function.pyx#L357

han...@mathematik.uni-kl.de

unread,
Nov 2, 2016, 8:52:39 AM11/2/16
to libsingu...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups
> "libsingular-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to libsingular-de...@googlegroups.com.
> To post to this group, send email to libsingu...@googlegroups.com.
> Visit this group at https://groups.google.com/group/libsingular-devel.
> For more options, visit https://groups.google.com/d/optout.
Fixed with
https://github.com/Singular/Sources/commit/76a7291160a6ba0f7e662bf112de635f35663c1d

Calls to iiExprArith[1-3] shall provide pointers to the arguments (leftv).
For these arguments sleftv::CleanUp(currRing) is called - no need to do
it in Sage, but an additional CleanUp does not harm.
So the contents of these arguments are recycled,
but the memory blocks itself remain (because in Singular they are not
dynamic storage blocks but part of an array): omFree (or the
corresponding free-routine to the allocation) must be called.

For functions with a variable number of arguments (iiExprArithM) the
arguments are passed as a linked list and CleanUp recycles all content
and all memory blocks but the first - they must be allocted by routines
from omalloc.

Calling library function should be equivalent to iiExprArithM.

Hans
Reply all
Reply to author
Forward
0 new messages