Ticket #9499: trac_9499.patch

File trac_9499.patch, 4.7 KB (added by malb, 13 years ago)

next attempt

  • sage/libs/singular/function.pxd

    # HG changeset patch
    # User Martin Albrecht <malb@informatik.uni-bremen.de>
    # Date 1279145035 -3600
    # Node ID 5b0d31501768e5ed33d06a557dddd867decdbf06
    # Parent  8dec8b43ccca5f104b1e280cb33c8f4c2c1b8f85
    make the libsingular interface more robust, i.e. allow to use it after some operation went wrong
    
    diff -r 8dec8b43ccca -r 5b0d31501768 sage/libs/singular/function.pxd
    a b  
    5252    cdef to_python(self, leftv* to_convert)
    5353
    5454cdef class BaseCallHandler:
    55     cdef leftv* handle_call(self, Converter argument_list) except NULL
     55    cdef leftv* handle_call(self, Converter argument_list)
    5656    cdef bint free_res(self)
    5757
    5858cdef class LibraryCallHandler(BaseCallHandler):
  • sage/libs/singular/function.pyx

    diff -r 8dec8b43ccca -r 5b0d31501768 sage/libs/singular/function.pyx
    a b  
    9191from sage.libs.singular.decl cimport MODUL_CMD, LIST_CMD, MATRIX_CMD, VECTOR_CMD, STRING_CMD, V_LOAD_LIB, V_REDEFINE, INTMAT_CMD, NONE, PACKAGE_CMD
    9292from sage.libs.singular.decl cimport IsCmd, rChangeCurrRing, currRing, p_Copy
    9393from sage.libs.singular.decl cimport IDROOT, enterid, currRingHdl, memcpy, IDNEXT, IDTYP, IDPACKAGE
    94 from sage.libs.singular.decl cimport errorreported, verbose, Sy_bit
     94from sage.libs.singular.decl cimport errorreported, verbose, Sy_bit, currentVoice, myynest
    9595from sage.libs.singular.decl cimport intvec_new_int3, intvec_new, matrix, mpNew
    9696from sage.libs.singular.decl cimport p_Add_q, p_SetComp, p_GetComp, pNext, p_Setm, IDELEMS
    9797from sage.libs.singular.decl cimport idInit, syStrategy, atSet, atGet, setFlag, FLAG_STD
     
    784784    A call handler is an abstraction which hides the details of the
    785785    implementation differences between kernel and library functions.
    786786    """
    787     cdef leftv* handle_call(self, Converter argument_list) except NULL:
     787    cdef leftv* handle_call(self, Converter argument_list):
    788788        """
    789789        Actual function call.
    790790        """
    791         raise NotImplementedError
     791        return NULL
    792792
    793793    cdef bint free_res(self):
    794794        """
     
    979979            sage: size(1,2, ring=P)
    980980            Traceback (most recent call last):                                         
    981981            ...
    982             RuntimeError
     982            RuntimeError: An error occurred when calling the Singular function 'size'.
    983983
    984984            sage: size('foobar', ring=P)
    985985            6
     
    995995        So we tell Singular that ``I`` is indeed a Groebner basis::
    996996
    997997            sage: hilb(I,attributes={I:{'isSB':1}}) # no complaint from Singular
     998
     999
     1000        TESTS:
     1001
     1002        We show that the interface recovers gracefully from errors::
     1003
     1004            sage: P.<e,d,c,b,a> = PolynomialRing(QQ,5,order='lex')
     1005            sage: I = sage.rings.ideal.Cyclic(P)
     1006
     1007            sage: triangL = sage.libs.singular.ff.triang__lib.triangL
     1008            sage: _ = triangL(I)
     1009            Traceback (most recent call last):
     1010            ...
     1011            RuntimeError: An error occurred when calling the Singular function 'triangL'.
     1012
     1013            sage: G= Ideal(I.groebner_basis())
     1014            sage: triangL(G,attributes={G:{'isSB':1}})
     1015            [[e + d + c + b + a, ...]]
    9981016        """
    9991017        if ring is None:
    10001018            ring = self.common_ring(args, ring)
     
    11411159cdef inline call_function(SingularFunction self, tuple args, MPolynomialRing_libsingular R, bint signal_handler=True, attributes=None):
    11421160    global currRingHdl
    11431161    global errorreported
     1162    global currentVoice
     1163    global myynest
    11441164
    11451165    cdef ring *si_ring = R._ring
    11461166
     
    11561176
    11571177    cdef leftv * _res
    11581178
     1179    currentVoice = NULL
     1180    myynest = 0
     1181    errorreported = 0
     1182
    11591183    with opt_ctx: # we are preserving the global options state here
    11601184        if signal_handler:
    11611185            _sig_on
     
    11641188        else:
    11651189            _res = self.call_handler.handle_call(argument_list)
    11661190   
     1191    if myynest:
     1192        myynest = 0
     1193
     1194    if currentVoice:
     1195        currentVoice = NULL
     1196
    11671197    if errorreported:
    11681198        errorreported = 0
    1169         raise RuntimeError
     1199        raise RuntimeError("An error occurred when calling the Singular function '%s'."%(self._name))
    11701200
    11711201    res = argument_list.to_python(_res)
    11721202   
  • sage/libs/singular/singular-cdefs.pxi

    diff -r 8dec8b43ccca -r 5b0d31501768 sage/libs/singular/singular-cdefs.pxi
    a b  
    362362
    363363    cdef int errorreported
    364364    cdef int verbose
     365    cdef void * currentVoice
     366    cdef int myynest
    365367
    366368    #
    367369    # FUNCTIONS