From 78bd23b71548d63de7ea502305cd10c48b46e849 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:06:43 +0700 Subject: [PATCH] Fix segmentation fault in singular interface code --- src/sage/libs/singular/singular.pyx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index dd1c5a35239..198b3b53f4c 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -1403,13 +1403,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: @@ -1432,7 +1425,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((elem[i]).value), mpq_denref((elem[i]).value), qqr.cf )