@@ -135,8 +135,8 @@ import sage.interfaces.abc
135135
136136from sage.libs.gap.libgap import libgap
137137from sage.libs.gap.gap_includes cimport (UInt, UInt2, UInt4, T_PERM2, T_PERM4,
138- NEW_PERM2, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2,
139- CONST_ADDR_PERM4, ADDR_PERM2)
138+ NEW_PERM2, NEW_PERM4, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2,
139+ CONST_ADDR_PERM4, ADDR_PERM2, ADDR_PERM4 )
140140from sage.libs.gap.util cimport initialize
141141from sage.libs.gap.element cimport (GapElement, GapElement_List,
142142 GapElement_String, GapElement_Permutation, make_GapElement_Permutation)
@@ -890,16 +890,32 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
890890 sage: p = SymmetricGroup( 0) . an_element( )
891891 sage: p. _libgap_( )
892892 ( )
893+
894+ Test that we handle large permutations :issue:`39998`::
895+
896+ sage: SymmetricGroup( 2** 17) (( 2** 16,2** 17-1)) . _libgap_( )
897+ ( 65536,131071)
893898 """
894899 if self ._libgap is not None :
895900 return self ._libgap
896901 initialize()
897902
898- cdef Obj res = NEW_PERM2(self .n)
899- cdef UInt2* p = ADDR_PERM2(res)
900903 cdef UInt i
901- for i in range (self .n):
902- p[i] = self .perm[i]
904+ cdef Obj res
905+ cdef UInt2* p2
906+ cdef UInt4* p4
907+ if self .n < 1 << 16 :
908+ # make a new (small) permutation
909+ res = NEW_PERM2(self .n)
910+ p2 = ADDR_PERM2(res)
911+ for i in range (self .n):
912+ p2[i] = self .perm[i]
913+ else :
914+ # make a new (large) permutation
915+ res = NEW_PERM4(self .n)
916+ p4 = ADDR_PERM4(res)
917+ for i in range (self .n):
918+ p4[i] = self .perm[i]
903919 self ._libgap = make_GapElement_Permutation(libgap, res)
904920 return self ._libgap
905921
0 commit comments