Ticket #13447: trac_13447-attempted_improvement.patch

File trac_13447-attempted_improvement.patch, 4.1 KB (added by SimonKing, 7 years ago)

Experiments towards fixing some problems

  • sage/libs/singular/function.pxd

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1348242660 25200
    # Node ID a23a513ba179c3e5a3ccff2a5b40794aadf2f5e8
    # Parent  b715a0070e456d939923fbde2c8b2bac5504ade4
    [mq]: trac_13447-attempted_improvement.patch
    
    diff --git a/sage/libs/singular/function.pxd b/sage/libs/singular/function.pxd
    a b  
    5757    cdef to_python(self, leftv* to_convert)
    5858
    5959cdef class BaseCallHandler:
    60     cdef leftv* handle_call(self, Converter argument_list, singular_ring *_ring=?)
     60    cdef leftv* handle_call(self, Converter argument_list, singular_ring *_ring=?) except NULL
    6161    cdef bint free_res(self)
    6262
    6363cdef class LibraryCallHandler(BaseCallHandler):
  • sage/libs/singular/function.pyx

    diff --git a/sage/libs/singular/function.pyx b/sage/libs/singular/function.pyx
    a b  
    10111011    A call handler is an abstraction which hides the details of the
    10121012    implementation differences between kernel and library functions.
    10131013    """
    1014     cdef leftv* handle_call(self, Converter argument_list, ring *_ring=NULL):
     1014    cdef leftv* handle_call(self, Converter argument_list, ring *_ring=NULL) except NULL:
    10151015        """
    10161016        Actual function call.
    10171017        """
    1018         return NULL
     1018        #return NULL
     1019        raise NotImplementedError
    10191020
    10201021    cdef bint free_res(self):
    10211022        """
     
    10451046        """
    10461047        super(LibraryCallHandler, self).__init__()
    10471048
    1048     cdef leftv* handle_call(self, Converter argument_list, ring *_ring=NULL):
     1049    cdef leftv* handle_call(self, Converter argument_list, ring *_ring=NULL) except NULL:
    10491050        if _ring != currRing: rChangeCurrRing(_ring)
    1050         return iiMake_proc(self.proc_idhdl, NULL, argument_list.args)
     1051        cdef leftv* res = iiMake_proc(self.proc_idhdl, NULL, argument_list.args)
     1052        if res == NULL:
     1053            raise RuntimeError, "Error during Singular library function call '%s'"%self._name
     1054        return res
    10511055       
    10521056    cdef bint free_res(self):
    10531057        """
     
    10801084        self.cmd_n = cmd_n
    10811085        self.arity = arity
    10821086
    1083     cdef leftv* handle_call(self, Converter argument_list, ring *_ring=NULL):
     1087    cdef leftv* handle_call(self, Converter argument_list, ring *_ring=NULL) except NULL:
    10841088        cdef leftv * res
    10851089        res = <leftv*> omAllocBin(sleftv_bin)
    10861090        res.Init()
    10871091        cdef leftv *arg1
    10881092        cdef leftv *arg2
    10891093        cdef leftv *arg3
    1090 
    10911094        cdef int number_of_arguments = len(argument_list)
    10921095
    10931096        # Handle functions with an arbitrary number of arguments, sent
     
    10951098        if self.arity in [CMD_M, ROOT_DECL_LIST, RING_DECL_LIST]:
    10961099            if _ring != currRing: rChangeCurrRing(_ring)
    10971100            iiExprArithM(res, argument_list.args, self.cmd_n)
     1101            if res == NULL:
     1102                raise RuntimeError, "Error during Singular kernel function '%s'"%self._name
    10981103            return res
    10991104
    11001105        if number_of_arguments == 1:
     
    14101415    global myynest
    14111416    global error_messages
    14121417
    1413 
    14141418    cdef ring *si_ring
    14151419    if PY_TYPE_CHECK(R, MPolynomialRing_libsingular):
    14161420        si_ring = (<MPolynomialRing_libsingular>R)._ring
     
    14521456        error_messages.pop()
    14531457
    14541458    # In the Singular interpreter, we must ensure that currRing->ref > 0.
    1455     currRing.ref += 1
     1459    si_ring.ref += 1
    14561460    try:
    14571461        with opt_ctx: # we are preserving the global options state here
    14581462            if signal_handler:
     
    14821486
    14831487        return res
    14841488    finally:
    1485         currRing.ref -= 1
     1489        si_ring.ref -= 1
    14861490       
    14871491cdef class SingularLibraryFunction(SingularFunction):
    14881492    """
     
    15091513            [y - 1, x + 1]
    15101514        """
    15111515        super(SingularLibraryFunction,self).__init__(name)
    1512         # the following will yield a NameError, if the function
    1513         # is not defined in a previously loaded library
    1514         self.call_handler = self.get_call_handler()
     1516        if ggetid(name)==NULL:
     1517            raise NameError("Function '%s' is not defined."%name)
    15151518
    15161519    cdef BaseCallHandler get_call_handler(self):
    15171520        cdef idhdl* singular_idhdl = ggetid(self._name)