From ecf7d966841a37ffc38684da08c2360df21b3a95 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 27 Jul 2023 15:39:35 +0200 Subject: [PATCH] gap: revise make_gap_list, make_gap_matrix --- src/sage/libs/gap/element.pyx | 49 +++++++++++++++++++----------- src/sage/libs/gap/gap_includes.pxd | 4 --- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/sage/libs/gap/element.pyx b/src/sage/libs/gap/element.pyx index 35067c59c0f..1dc53c81f67 100644 --- a/src/sage/libs/gap/element.pyx +++ b/src/sage/libs/gap/element.pyx @@ -47,16 +47,23 @@ cdef Obj make_gap_list(sage_list) except NULL: The list of the elements in ``a`` as a Gap ``Obj``. """ - cdef GapElement l = libgap.eval('[]') + cdef Obj l cdef GapElement elem - for x in sage_list: - if not isinstance(x, GapElement): - elem = libgap(x) - else: - elem = x + cdef int i + try: + GAP_Enter() + l = GAP_NewPlist(0) - AddList(l.value, elem.value) - return l.value + for i, x in enumerate(sage_list): + if not isinstance(x, GapElement): + elem = libgap(x) + else: + elem = x + + GAP_AssList(l, i + 1, elem.value) + return l + finally: + GAP_Leave() cdef Obj make_gap_matrix(sage_list, gap_ring) except NULL: @@ -77,22 +84,30 @@ cdef Obj make_gap_matrix(sage_list, gap_ring) except NULL: The list of the elements in ``sage_list`` as a Gap ``Obj``. """ - cdef GapElement l = libgap.eval('[]') + cdef Obj l cdef GapElement elem cdef GapElement one + cdef int i if gap_ring is not None: one = gap_ring.One() else: one = libgap(1) - for x in sage_list: - if not isinstance(x, GapElement): - elem = libgap(x) - elem = elem * one - else: - elem = x - AddList(l.value, elem.value) - return l.value + try: + GAP_Enter() + l = GAP_NewPlist(0) + + for i, x in enumerate(sage_list): + if not isinstance(x, GapElement): + elem = libgap(x) + elem = elem * one + else: + elem = x + + GAP_AssList(l, i + 1, elem.value) + return l + finally: + GAP_Leave() cdef char *capture_stdout(Obj func, Obj obj): diff --git a/src/sage/libs/gap/gap_includes.pxd b/src/sage/libs/gap/gap_includes.pxd index 32ee925001f..840b8a0042e 100644 --- a/src/sage/libs/gap/gap_includes.pxd +++ b/src/sage/libs/gap/gap_includes.pxd @@ -96,10 +96,6 @@ cdef extern from "gap/lists.h" nogil: Obj ELM_LIST(Obj lst, int pos) -cdef extern from "gap/listfunc.h" nogil: - void AddList(Obj list, Obj obj) - - cdef extern from "gap/objects.h" nogil: bint IS_MUTABLE_OBJ(Obj obj) Obj SHALLOW_COPY_OBJ(Obj obj)