Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segmentation fault in singular interface code #39293

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/sage/libs/singular/singular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,13 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept:
(a + 1)
sage: R(F.gen()^5) + 1
(-a^2 + a + 2)

Ensures :issue:`36101` is fixed::

sage: RR.<x, y, r, s0, c0, s1, c1> = AA[]
sage: f = -4*r^2+(((1+2*AA(cos(pi/6)))*c0*r+2*c1*r+(1+2*AA(cos(pi/6)))*s0*r+2*s1*r)/2-1/2)^2+((1-(1+2*AA(cos(pi/6)))*c0*r-2*c1*r+(1+2*AA(cos(pi/6)))*s0*r+2*s1*r)/2-1/2)^2
sage: f.change_ring( QuadraticField(3) )
...
"""
cdef int i
cdef number *n1
Expand All @@ -1403,13 +1410,6 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept:
cdef number *apow1
cdef number *apow2

cdef nMapFunc nMapFuncPtr = NULL

nMapFuncPtr = naSetMap(_ring.cf, currRing.cf) # choose correct mapping function

if nMapFuncPtr is NULL:
raise RuntimeError("Failed to determine nMapFuncPtr")

elem = list(elem)

if _ring != currRing:
Expand All @@ -1432,7 +1432,10 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept:
rComplete(qqr,1)
qqr.ShortOut = 0

nMapFuncPtr = naSetMap(qqr.cf, _ring.cf) # choose correct mapping function
assert _ring.cf.type == n_algExt # if false naSetMap will segmentation fault (should never happen)
cdef nMapFunc nMapFuncPtr = naSetMap(qqr.cf, _ring.cf) # choose correct mapping function
if nMapFuncPtr is NULL:
raise RuntimeError("Failed to determine nMapFuncPtr")
cdef poly *_p
for i from 0 <= i < len(elem):
nlCoeff = nlInit2gmp( mpq_numref((<Rational>elem[i]).value), mpq_denref((<Rational>elem[i]).value), qqr.cf )
Expand Down
Loading