Skip to content

Commit 0eaccb0

Browse files
author
Release Manager
committed
gh-35887: gap: switch to libgap API for GAP function calls ### 📚 Description Switch to the official libgap API for making function calls. <s>This also simplifies the code quite a bit.</s> And it makes it possible to call non-standard GAP functions (i.e. functions which are not `T_FUNCTION` but just an arbitrary objects for which a function call method has been installed). <s>As a caveat, I could *not* try this at all, as I currently cannot compile SageMath (it runs into weird errors, and I don't have time to debug this, sorry). In particular I just looked at the Cython documentation to find out how to get a raw pointer to the content of an array; but I am not even sure that I got the syntax right, let alone the semantics. But I figured it's worth a shot.</s> UPDATE: I decided to not try to use `GAP_CallFuncArray` anymore; it just is impossible for me to figure out the right way to call it from Cython when I can only test my changes by pushing them here. Instead a more modest but hopefully less problematic approach is now used. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [ ] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35887 Reported by: Max Horn Reviewer(s): Frédéric Chapoton
2 parents 0f23d09 + 5af9711 commit 0eaccb0

File tree

2 files changed

+8
-37
lines changed

2 files changed

+8
-37
lines changed

src/sage/libs/gap/element.pyx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,53 +2488,32 @@ cdef class GapElement_Function(GapElement):
24882488
"""
24892489
cdef Obj result = NULL
24902490
cdef Obj arg_list
2491-
cdef int i, n = len(args)
2491+
cdef int n = len(args)
24922492

2493-
if n > 0:
2493+
if n > 0 and n <= 3:
24942494
libgap = self.parent()
24952495
a = [x if isinstance(x, GapElement) else libgap(x) for x in args]
24962496

24972497
try:
24982498
sig_GAP_Enter()
24992499
sig_on()
25002500
if n == 0:
2501-
result = CALL_0ARGS(self.value)
2501+
result = GAP_CallFunc0Args(self.value)
25022502
elif n == 1:
2503-
result = CALL_1ARGS(self.value,
2503+
result = GAP_CallFunc1Args(self.value,
25042504
(<GapElement>a[0]).value)
25052505
elif n == 2:
2506-
result = CALL_2ARGS(self.value,
2506+
result = GAP_CallFunc2Args(self.value,
25072507
(<GapElement>a[0]).value,
25082508
(<GapElement>a[1]).value)
25092509
elif n == 3:
2510-
result = CALL_3ARGS(self.value,
2510+
result = GAP_CallFunc3Args(self.value,
25112511
(<GapElement>a[0]).value,
25122512
(<GapElement>a[1]).value,
25132513
(<GapElement>a[2]).value)
2514-
elif n == 4:
2515-
result = CALL_4ARGS(self.value,
2516-
(<GapElement>a[0]).value,
2517-
(<GapElement>a[1]).value,
2518-
(<GapElement>a[2]).value,
2519-
(<GapElement>a[3]).value)
2520-
elif n == 5:
2521-
result = CALL_5ARGS(self.value,
2522-
(<GapElement>a[0]).value,
2523-
(<GapElement>a[1]).value,
2524-
(<GapElement>a[2]).value,
2525-
(<GapElement>a[3]).value,
2526-
(<GapElement>a[4]).value)
2527-
elif n == 6:
2528-
result = CALL_6ARGS(self.value,
2529-
(<GapElement>a[0]).value,
2530-
(<GapElement>a[1]).value,
2531-
(<GapElement>a[2]).value,
2532-
(<GapElement>a[3]).value,
2533-
(<GapElement>a[4]).value,
2534-
(<GapElement>a[5]).value)
2535-
elif n >= 7:
2514+
else:
25362515
arg_list = make_gap_list(args)
2537-
result = CALL_XARGS(self.value, arg_list)
2516+
result = GAP_CallFuncList(self.value, arg_list)
25382517
sig_off()
25392518
finally:
25402519
GAP_Leave()

src/sage/libs/gap/gap_includes.pxd

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ cdef extern from "gap/system.h" nogil:
2424

2525
cdef extern from "gap/calls.h" nogil:
2626
bint IS_FUNC(Obj)
27-
Obj CALL_0ARGS(Obj f) # 0 arguments
28-
Obj CALL_1ARGS(Obj f, Obj a1) # 1 argument
29-
Obj CALL_2ARGS(Obj f, Obj a1, Obj a2)
30-
Obj CALL_3ARGS(Obj f, Obj a1, Obj a2, Obj a3)
31-
Obj CALL_4ARGS(Obj f, Obj a1, Obj a2, Obj a3, Obj a4)
32-
Obj CALL_5ARGS(Obj f, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5)
33-
Obj CALL_6ARGS(Obj f, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5, Obj a6)
34-
Obj CALL_XARGS(Obj f, Obj args) # more than 6 arguments
3527

3628

3729
cdef extern from "gap/libgap-api.h" nogil:

0 commit comments

Comments
 (0)