Skip to content

Commit 2412b2b

Browse files
author
Release Manager
committed
gh-39293: Fix segmentation fault in singular interface code Fixes #36101 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39293 Reported by: user202729 Reviewer(s): Marc Mezzarobba
2 parents 80dd3a6 + b9cf5a9 commit 2412b2b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/sage/libs/singular/singular.pyx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,13 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept:
13931393
(a + 1)
13941394
sage: R(F.gen()^5) + 1
13951395
(-a^2 + a + 2)
1396+
1397+
Ensures :issue:`36101` is fixed::
1398+
1399+
sage: RR.<x, y, r, s0, c0, s1, c1> = AA[]
1400+
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
1401+
sage: f.change_ring( QuadraticField(3) )
1402+
...
13961403
"""
13971404
cdef int i
13981405
cdef number *n1
@@ -1403,13 +1410,6 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept:
14031410
cdef number *apow1
14041411
cdef number *apow2
14051412

1406-
cdef nMapFunc nMapFuncPtr = NULL
1407-
1408-
nMapFuncPtr = naSetMap(_ring.cf, currRing.cf) # choose correct mapping function
1409-
1410-
if nMapFuncPtr is NULL:
1411-
raise RuntimeError("Failed to determine nMapFuncPtr")
1412-
14131413
elem = list(elem)
14141414

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

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

0 commit comments

Comments
 (0)