# 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
|
|
52 | 52 | cdef to_python(self, leftv* to_convert) |
53 | 53 | |
54 | 54 | cdef class BaseCallHandler: |
55 | | cdef leftv* handle_call(self, Converter argument_list) except NULL |
| 55 | cdef leftv* handle_call(self, Converter argument_list) |
56 | 56 | cdef bint free_res(self) |
57 | 57 | |
58 | 58 | cdef class LibraryCallHandler(BaseCallHandler): |
diff -r 8dec8b43ccca -r 5b0d31501768 sage/libs/singular/function.pyx
a
|
b
|
|
91 | 91 | from 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 |
92 | 92 | from sage.libs.singular.decl cimport IsCmd, rChangeCurrRing, currRing, p_Copy |
93 | 93 | from sage.libs.singular.decl cimport IDROOT, enterid, currRingHdl, memcpy, IDNEXT, IDTYP, IDPACKAGE |
94 | | from sage.libs.singular.decl cimport errorreported, verbose, Sy_bit |
| 94 | from sage.libs.singular.decl cimport errorreported, verbose, Sy_bit, currentVoice, myynest |
95 | 95 | from sage.libs.singular.decl cimport intvec_new_int3, intvec_new, matrix, mpNew |
96 | 96 | from sage.libs.singular.decl cimport p_Add_q, p_SetComp, p_GetComp, pNext, p_Setm, IDELEMS |
97 | 97 | from sage.libs.singular.decl cimport idInit, syStrategy, atSet, atGet, setFlag, FLAG_STD |
… |
… |
|
784 | 784 | A call handler is an abstraction which hides the details of the |
785 | 785 | implementation differences between kernel and library functions. |
786 | 786 | """ |
787 | | cdef leftv* handle_call(self, Converter argument_list) except NULL: |
| 787 | cdef leftv* handle_call(self, Converter argument_list): |
788 | 788 | """ |
789 | 789 | Actual function call. |
790 | 790 | """ |
791 | | raise NotImplementedError |
| 791 | return NULL |
792 | 792 | |
793 | 793 | cdef bint free_res(self): |
794 | 794 | """ |
… |
… |
|
979 | 979 | sage: size(1,2, ring=P) |
980 | 980 | Traceback (most recent call last): |
981 | 981 | ... |
982 | | RuntimeError |
| 982 | RuntimeError: An error occurred when calling the Singular function 'size'. |
983 | 983 | |
984 | 984 | sage: size('foobar', ring=P) |
985 | 985 | 6 |
… |
… |
|
995 | 995 | So we tell Singular that ``I`` is indeed a Groebner basis:: |
996 | 996 | |
997 | 997 | 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, ...]] |
998 | 1016 | """ |
999 | 1017 | if ring is None: |
1000 | 1018 | ring = self.common_ring(args, ring) |
… |
… |
|
1141 | 1159 | cdef inline call_function(SingularFunction self, tuple args, MPolynomialRing_libsingular R, bint signal_handler=True, attributes=None): |
1142 | 1160 | global currRingHdl |
1143 | 1161 | global errorreported |
| 1162 | global currentVoice |
| 1163 | global myynest |
1144 | 1164 | |
1145 | 1165 | cdef ring *si_ring = R._ring |
1146 | 1166 | |
… |
… |
|
1156 | 1176 | |
1157 | 1177 | cdef leftv * _res |
1158 | 1178 | |
| 1179 | currentVoice = NULL |
| 1180 | myynest = 0 |
| 1181 | errorreported = 0 |
| 1182 | |
1159 | 1183 | with opt_ctx: # we are preserving the global options state here |
1160 | 1184 | if signal_handler: |
1161 | 1185 | _sig_on |
… |
… |
|
1164 | 1188 | else: |
1165 | 1189 | _res = self.call_handler.handle_call(argument_list) |
1166 | 1190 | |
| 1191 | if myynest: |
| 1192 | myynest = 0 |
| 1193 | |
| 1194 | if currentVoice: |
| 1195 | currentVoice = NULL |
| 1196 | |
1167 | 1197 | if errorreported: |
1168 | 1198 | errorreported = 0 |
1169 | | raise RuntimeError |
| 1199 | raise RuntimeError("An error occurred when calling the Singular function '%s'."%(self._name)) |
1170 | 1200 | |
1171 | 1201 | res = argument_list.to_python(_res) |
1172 | 1202 | |
diff -r 8dec8b43ccca -r 5b0d31501768 sage/libs/singular/singular-cdefs.pxi
a
|
b
|
|
362 | 362 | |
363 | 363 | cdef int errorreported |
364 | 364 | cdef int verbose |
| 365 | cdef void * currentVoice |
| 366 | cdef int myynest |
365 | 367 | |
366 | 368 | # |
367 | 369 | # FUNCTIONS |