Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gh-35805: gap: use libgap API for int conversion
    

    
URL: #35805
Reported by: Max Horn
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Jun 29, 2023
2 parents 6b6475d + 9775853 commit c80cc11
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/sage/groups/perm_gps/permgroup_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ from sage.libs.gap.gap_includes cimport (UInt, UInt2, UInt4, T_PERM2, T_PERM4,
from sage.libs.gap.util cimport initialize
from sage.libs.gap.element cimport (GapElement, GapElement_List,
GapElement_String, GapElement_Permutation, make_GapElement_Permutation)
from sage.libs.gap.gap_includes cimport Obj, INT_INTOBJ, ELM_LIST
from sage.libs.gap.gap_includes cimport Obj, GAP_ValueInt, ELM_LIST

import operator

Expand Down Expand Up @@ -1361,7 +1361,7 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
assert vn <= self.n

for i in range(vn):
j = INT_INTOBJ(ELM_LIST(obj, i+1))
j = GAP_ValueInt(ELM_LIST(obj, i+1))
new.perm[i] = j - 1
for i in range(vn, self.n):
new.perm[i] = i
Expand Down
10 changes: 2 additions & 8 deletions src/sage/libs/gap/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,7 @@ cdef Obj make_gap_integer(sage_int) except NULL:
sage: libgap(1) # indirect doctest
1
"""
cdef Obj result
try:
GAP_Enter()
result = INTOBJ_INT(<int>sage_int)
return result
finally:
GAP_Leave()
return GAP_NewObjIntFromInt(<int>sage_int)


cdef Obj make_gap_string(sage_string) except NULL:
Expand Down Expand Up @@ -1502,7 +1496,7 @@ cdef class GapElement_Integer(GapElement):
if ring is None:
ring = ZZ
if self.is_C_int():
return ring(INT_INTOBJ(self.value))
return ring(GAP_ValueInt(self.value))
else:
# TODO: waste of time!
# gap integers are stored as a mp_limb_t and we have a much more direct
Expand Down
7 changes: 2 additions & 5 deletions src/sage/libs/gap/gap_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ cdef extern from "gap/calls.h" nogil:
Obj CALL_XARGS(Obj f, Obj args) # more than 6 arguments


cdef extern from "gap/intobj.h" nogil:
Obj INTOBJ_INT(Int)
Int INT_INTOBJ(Obj)


cdef extern from "gap/libgap-api.h" nogil:
"""
#define sig_GAP_Enter() {int t = GAP_Enter(); if (!t) sig_error();}
Expand Down Expand Up @@ -78,6 +73,8 @@ cdef extern from "gap/libgap-api.h" nogil:

bint GAP_IsInt(Obj)
bint GAP_IsSmallInt(Obj)
Obj GAP_NewObjIntFromInt(Int val)
Int GAP_ValueInt(Obj)

bint GAP_IsList(Obj lst)
UInt GAP_LenList(Obj lst)
Expand Down

0 comments on commit c80cc11

Please sign in to comment.