# 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
|
|
57 | 57 | cdef to_python(self, leftv* to_convert) |
58 | 58 | |
59 | 59 | cdef 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 |
61 | 61 | cdef bint free_res(self) |
62 | 62 | |
63 | 63 | cdef class LibraryCallHandler(BaseCallHandler): |
diff --git a/sage/libs/singular/function.pyx b/sage/libs/singular/function.pyx
a
|
b
|
|
1011 | 1011 | A call handler is an abstraction which hides the details of the |
1012 | 1012 | implementation differences between kernel and library functions. |
1013 | 1013 | """ |
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: |
1015 | 1015 | """ |
1016 | 1016 | Actual function call. |
1017 | 1017 | """ |
1018 | | return NULL |
| 1018 | #return NULL |
| 1019 | raise NotImplementedError |
1019 | 1020 | |
1020 | 1021 | cdef bint free_res(self): |
1021 | 1022 | """ |
… |
… |
|
1045 | 1046 | """ |
1046 | 1047 | super(LibraryCallHandler, self).__init__() |
1047 | 1048 | |
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: |
1049 | 1050 | 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 |
1051 | 1055 | |
1052 | 1056 | cdef bint free_res(self): |
1053 | 1057 | """ |
… |
… |
|
1080 | 1084 | self.cmd_n = cmd_n |
1081 | 1085 | self.arity = arity |
1082 | 1086 | |
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: |
1084 | 1088 | cdef leftv * res |
1085 | 1089 | res = <leftv*> omAllocBin(sleftv_bin) |
1086 | 1090 | res.Init() |
1087 | 1091 | cdef leftv *arg1 |
1088 | 1092 | cdef leftv *arg2 |
1089 | 1093 | cdef leftv *arg3 |
1090 | | |
1091 | 1094 | cdef int number_of_arguments = len(argument_list) |
1092 | 1095 | |
1093 | 1096 | # Handle functions with an arbitrary number of arguments, sent |
… |
… |
|
1095 | 1098 | if self.arity in [CMD_M, ROOT_DECL_LIST, RING_DECL_LIST]: |
1096 | 1099 | if _ring != currRing: rChangeCurrRing(_ring) |
1097 | 1100 | iiExprArithM(res, argument_list.args, self.cmd_n) |
| 1101 | if res == NULL: |
| 1102 | raise RuntimeError, "Error during Singular kernel function '%s'"%self._name |
1098 | 1103 | return res |
1099 | 1104 | |
1100 | 1105 | if number_of_arguments == 1: |
… |
… |
|
1410 | 1415 | global myynest |
1411 | 1416 | global error_messages |
1412 | 1417 | |
1413 | | |
1414 | 1418 | cdef ring *si_ring |
1415 | 1419 | if PY_TYPE_CHECK(R, MPolynomialRing_libsingular): |
1416 | 1420 | si_ring = (<MPolynomialRing_libsingular>R)._ring |
… |
… |
|
1452 | 1456 | error_messages.pop() |
1453 | 1457 | |
1454 | 1458 | # In the Singular interpreter, we must ensure that currRing->ref > 0. |
1455 | | currRing.ref += 1 |
| 1459 | si_ring.ref += 1 |
1456 | 1460 | try: |
1457 | 1461 | with opt_ctx: # we are preserving the global options state here |
1458 | 1462 | if signal_handler: |
… |
… |
|
1482 | 1486 | |
1483 | 1487 | return res |
1484 | 1488 | finally: |
1485 | | currRing.ref -= 1 |
| 1489 | si_ring.ref -= 1 |
1486 | 1490 | |
1487 | 1491 | cdef class SingularLibraryFunction(SingularFunction): |
1488 | 1492 | """ |
… |
… |
|
1509 | 1513 | [y - 1, x + 1] |
1510 | 1514 | """ |
1511 | 1515 | 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) |
1515 | 1518 | |
1516 | 1519 | cdef BaseCallHandler get_call_handler(self): |
1517 | 1520 | cdef idhdl* singular_idhdl = ggetid(self._name) |