Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #22 #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions gappy/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ MakeImmutable(\$GAPPY_ERROUT);


# TODO: Change autoload=True by default
cdef initialize(gap_root=None, gaprc=None, workspace=None, workspace_valid=False, autoload=False):
cdef initialize(gap_root=None, gap_memory=None, gaprc=None, workspace=None, workspace_valid=False, autoload=False):
"""
Initialize the GAP library, if it hasn't already been initialized.

Expand All @@ -225,7 +225,7 @@ cdef initialize(gap_root=None, gaprc=None, workspace=None, workspace_valid=False
_gap_root = gap_root.encode(_FS_ENCODING, 'surrogateescape')
argv[2] = _gap_root

memory_pool = get_gap_memory_pool_size().encode('ascii')
memory_pool = get_gap_memory_pool_size().encode('ascii') if gap_memory is None else (str(gap_memory)+'m').encode('ascii')
argv[3] = '-o'
argv[4] = memory_pool
argv[5] = '-s'
Expand Down Expand Up @@ -294,6 +294,7 @@ cdef initialize(gap_root=None, gaprc=None, workspace=None, workspace_valid=False
# Return a dict of the final initialization args (after handling defaults)
return {
'gap_root': gap_root,
'gap_memory': memory_pool,
'gaprc': gaprc,
'workspace': workspace,
'autoload': autoload
Expand Down Expand Up @@ -539,6 +540,9 @@ cdef class Gap:
interpreter. This should be the path containing the ``lib/`` and
``pkg/`` directories for the standard GAP libraries. Equivalent to
the ``-l`` command-line argument to ``gap``.
gap_memory : 'int'
GAP's memory in megabytes. Equivalent to the ``o`` command-line
argument to ``gap``.
gaprc : `str` or `pathlib.Path`
A GAP "runtime config" file containing GAP commands to run immediately
upon GAP interpreter startup. Equivalent to passing a GAP file to
Expand Down Expand Up @@ -603,6 +607,7 @@ cdef class Gap:

self._init_kwargs.update(initialize(
gap_root=self._init_kwargs['gap_root'],
gap_memory=self._init_kwargs['gap_memory'],
gaprc=self._init_kwargs['gaprc'],
workspace=self._init_kwargs['workspace'],
workspace_valid=self._init_kwargs['workspace_valid'],
Expand All @@ -611,7 +616,7 @@ cdef class Gap:
_gap_instance = self
return True

def __init__(self, gap_root=None, gaprc=None, workspace=None, workspace_valid=False,
def __init__(self, gap_root=None, gap_memory=None, gaprc=None, workspace=None, workspace_valid=False,
autoinit=False, autoload=False):
if _gap_is_initialized:
raise RuntimeError(
Expand All @@ -620,6 +625,7 @@ cdef class Gap:

self._init_kwargs.update({
'gap_root': gap_root,
'gap_memory': gap_memory,
'gaprc': gaprc,
'workspace': workspace,
'workspace_valid': workspace_valid,
Expand Down Expand Up @@ -837,6 +843,13 @@ cdef class Gap:

return self._init_kwargs.get('gap_root')

@property
def gap_memory(self):
"""
GAP's memory in megabytes.
"""
return self._init_kwargs.get('gap_memory')

@property
def gaprc(self):
"""
Expand Down
17 changes: 13 additions & 4 deletions gappy/gap_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,29 @@ cdef extern from "gap/gasman.h" nogil:
"""
#define GAP_CollectBags(full) CollectBags(0, full)
"""
void GAP_MarkBag "MarkBag" (Obj bag)
void GAP_MarkBag(Obj bag)
UInt GAP_CollectBags(UInt full)


cdef extern from "gap/io.h" nogil:
UInt OpenOutputStream(Obj stream)
UInt CloseOutput()
"""
TypOutputFile output = {0};
inline UInt GAP_OpenOutputStream(Obj stream) {
return OpenOutputStream(&output, stream);
}
inline UInt GAP_CloseOutput( ) {
return CloseOutput(&output);
}
"""
UInt GAP_OpenOutputStream(Obj stream)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a string? Is this a Cython trick I forgot?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry which string?

UInt GAP_CloseOutput()


# TODO: Replace this with a GAP_MakeStringWithLen from the public API;
# see https://github.com/gap-system/gap/issues/4211
cdef extern from "gap/stringobj.h" nogil:
"""
static inline Obj GAP_MakeStringWithLen(char *s, size_t len) {
inline Obj GAP_MakeStringWithLen(const char *s, size_t len) {
Obj ret;
C_NEW_STRING(ret, len, s);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions gappy/gapobj.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ cdef void capture_stdout(Obj func, Obj obj, Obj out):
args[0] = out
args[1] = GAP_True
stream = GAP_CallFuncArray(output_text_string, 2, args)
stream_ok = OpenOutputStream(stream)
stream_ok = GAP_OpenOutputStream(stream)
sig_off()

if not stream_ok:
Expand All @@ -111,7 +111,7 @@ cdef void capture_stdout(Obj func, Obj obj, Obj out):
args[0] = obj
sig_on()
GAP_CallFuncArray(func, 1, args)
CloseOutput()
GAP_CloseOutput()
sig_off()
finally:
sig_GAP_Leave()
Expand Down