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

Make it possible to build GAP as a dynamic library #1205

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
090c88d
Add --enable-libgap switch to build system
markuspf Mar 12, 2017
5b6572f
libgap-only source files
vbraun Jan 18, 2016
e235cd1
Add libgap files to Makefile.rules
markuspf Mar 12, 2017
de41f91
Adapt Makefile.rules for building libgap
markuspf Mar 13, 2017
63970fc
Fix Makefile.rules
markuspf Mar 13, 2017
0d3c782
Some cleanup
markuspf Mar 13, 2017
452fc05
Rename LIBGAP to BUILD_LIBGAP
markuspf Mar 13, 2017
2a33824
Change include "foo.h" to <src/foo.h>
markuspf Mar 13, 2017
920cd46
Refactor libgap initialisation
markuspf Mar 13, 2017
eeec674
Allow installing libgap
markuspf Mar 14, 2017
a6a688f
Add small test program for libgap
markuspf Mar 14, 2017
5c688f5
Add some hacky test-libgap target
markuspf Mar 14, 2017
d51848d
Rename LibFuncBags to ExtraMarkFuncBags
markuspf Mar 14, 2017
bac8e83
Rename libgap to sage_interface
markuspf Mar 14, 2017
fd6954e
Fix a typo
markuspf Mar 14, 2017
e562f06
Callback when JUMP_TO_CATCH is executed
markuspf Mar 14, 2017
11cce5e
Adapt sage_interface.c to accommodate for changes
markuspf Mar 14, 2017
a0076c3
Fix an #ifdef bug
markuspf Mar 14, 2017
a0ac524
Fix test-libgap
markuspf Mar 15, 2017
cb8a7a8
Catch another signal handler disable
markuspf Mar 16, 2017
3e20453
Cleanup rebase mess
markuspf Mar 30, 2017
29712b0
Cleanup rebase mess
markuspf Mar 30, 2017
b145760
Add helper function for self-contained evaluation
markuspf May 9, 2017
7ff4fb1
More TLS->STATE fixes
markuspf May 10, 2017
6176b97
Eval string and return Obj
markuspf May 10, 2017
d56dc1d
Put some API stuff in
markuspf May 10, 2017
106fa37
More API work
markuspf May 10, 2017
69e6e78
More API
markuspf May 11, 2017
2b8df14
Set environment on libgap_initialize
markuspf May 11, 2017
609a492
Make some changes to libgap_eval_string
markuspf May 11, 2017
4eb2440
Export List functions
markuspf May 12, 2017
01021eb
Fix some issue that rebase caused
markuspf Sep 6, 2017
65fbb55
Ignore void value
markuspf Sep 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions GNUmakefile.in
Expand Up @@ -19,6 +19,9 @@ ABI_CFLAGS = @ABI_CFLAGS@
HPCGAP = @HPCGAP@
ADDGUARDS2 = @ADDGUARDS2@

# LibGAP specific
BUILD_LIBGAP = @BUILD_LIBGAP@

# compatibility mode
COMPAT_MODE = @COMPAT_MODE@
GAPARCH = @GAPARCH@
Expand Down
18 changes: 16 additions & 2 deletions Makefile.rules
Expand Up @@ -12,7 +12,9 @@
# Default rule: build gap
########################################################################
all: gap$(EXEEXT) gac
.PHONY: all
Copy link
Member

Choose a reason for hiding this comment

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

Why was this line removed?


libgap: libgap.la
.PHONY: libgap
Copy link
Member

Choose a reason for hiding this comment

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

This duplicates what is already there in the lines below.


libgap: libgap.la
.PHONY: libgap
Expand All @@ -21,7 +23,6 @@ libgap: libgap.la
default: all
.PHONY: default


########################################################################
# Source files
#
Expand Down Expand Up @@ -118,6 +119,9 @@ ifeq ($(HPCGAP),yes)
SOURCES += src/hpc/traverse.c
endif

ifeq ($(BUILD_LIBGAP),yes)
SOURCES += src/sage_interface.c
endif
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, perhaps distinguish between BUILD_LIBGAP and BUILD_SAGEINTERFACE ?


########################################################################
# Preprocessor flags
Expand Down Expand Up @@ -1022,3 +1026,13 @@ doc/make_doc: $(srcdir)/doc/make_doc.in config.status

gac: $(srcdir)/cnf/gac.in config.status
$(SHELL) ./config.status $@

# TODO: This needs to be done more elegantly
Copy link
Member

Choose a reason for hiding this comment

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

You probably plan to clean this up before the PR is merged. But if not, then this comment needs to be expanded, to explain what "this" is and what the TODO is.

obj/libgap-test-0001.lo: $(top_srcdir)/tst/testlibgap/0001.c
$(QUIET_CC)$(COMPILE) $(DEPFLAGS) $(GAP_CFLAGS) $(CC_EXTRA_FLAGS) $(GAP_CPPFLAGS) -c $< -o $@

test-libgap: libgap.la obj/libgap-test-0001.lo
$(QUIET_LINK)$(LINK) obj/libgap-test-0001.lo libgap.la -o test-libgap
./test-libgap -l $(top_srcdir) -m 32m -q -T > 0001.out
diff $(top_srcdir)/tst/testlibgap/0001.expect 0001.out

17 changes: 17 additions & 0 deletions configure.ac
Expand Up @@ -193,6 +193,23 @@ AS_IF([test "x$enable_hpcgap" = xyes],
AC_DEFINE([MAX_GC_THREADS], [4], [maximum number of GC threads])
])

dnl
dnl User setting: LibGAP mode (off by default)
dnl
dnl If on, build an LibGAP instead of standard GAP executable.
dnl
dnl TODO: Will there ever be an HPC-GAP libgap?
dnl
AC_ARG_ENABLE([libgap],
[AS_HELP_STRING([--enable-libgap], [enable LibGAP])],
[AC_DEFINE([LIBGAP], [1], [define if building LibGAP])],
[enable_libgap=no]
)
AC_MSG_CHECKING([whether to enable LibGAP])
AC_MSG_RESULT([$enable_libgap])

AC_SUBST([BUILD_LIBGAP], [$enable_libgap])

dnl
dnl User setting: Debug mode (off by default)
dnl
Expand Down
19 changes: 18 additions & 1 deletion src/gap.c
Expand Up @@ -114,6 +114,10 @@

#include <src/gaputils.h>

#if defined(LIBGAP)
#include <src/sage_interface.h>
#endif

/****************************************************************************
**
*V Last . . . . . . . . . . . . . . . . . . . . . . global variable 'last'
Expand Down Expand Up @@ -209,6 +213,8 @@ static Int NrImportedFuncs;

static char **sysenviron;

TJumpToCatchFunc JumpToCatchFunc = 0;

/*
TL: Obj ShellContext = 0;
TL: Obj BaseShellContext = 0;
Expand Down Expand Up @@ -1148,6 +1154,15 @@ Obj FuncJUMP_TO_CATCH( Obj self, Obj payload)
{
STATE(ThrownObject) = payload;
syLongjmp(&(STATE(ReadJmpError)), 1);
#if defined(LIBGAP)
libgap_call_error_handler();
#endif
STATE(ThrownObject) = payload;
if(JumpToCatchFunc != 0) {
(*JumpToCatchFunc)();
}
STATE(ThrownObject) = payload;
syLongjmp(STATE(ReadJmpError), 1);
return 0;
}

Expand Down Expand Up @@ -3210,7 +3225,7 @@ void InitializeGap (

/* Initialise memory -- have to do this here to make sure we are at top of C stack */
InitBags( SyAllocBags, SyStorMin,
0, (Bag*)(((UInt)pargc/SyStackAlign)*SyStackAlign), SyStackAlign,
0, (Bag*)(((UInt)pargc/SyStackAlign)*SyStackAlign), SyStackAlign, 0,
SyAbortBags );
#if !defined(BOEHM_GC)
InitMsgsFuncBags( SyMsgsBags );
Expand All @@ -3230,6 +3245,8 @@ void InitializeGap (
NrImportedGVars = 0;
NrImportedFuncs = 0;

JumpToCatchFunc = 0;

sysenviron = environ;

/* get info structures for the build in modules */
Expand Down
5 changes: 5 additions & 0 deletions src/gap.h
Expand Up @@ -201,6 +201,11 @@ extern void ErrorReturnVoid (
Int arg2,
const Char * msg2 );

typedef void (* TJumpToCatchFunc)();
extern TJumpToCatchFunc JumpToCatchFunc;
static inline void SetJumpToCatchFunc(TJumpToCatchFunc func)
{ JumpToCatchFunc = func; };
Copy link
Member

Choose a reason for hiding this comment

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

That an odd code formatting style...

Also, why does this setter even exist, if JumpToCatchFunc is a global anyway?


/* TL: extern Obj ErrorLVars;
TL: extern Obj ErrorLVars0;
*/
Expand Down
11 changes: 10 additions & 1 deletion src/gasman.c
Expand Up @@ -967,6 +967,8 @@ TNumAllocFuncBags AllocFuncBags;

TNumStackFuncBags StackFuncBags;

TExtraMarkFuncBags ExtraMarkFuncBags;

Bag * StackBottomBags;

UInt StackAlignBags;
Expand All @@ -979,7 +981,8 @@ void InitBags (
TNumStackFuncBags stack_func,
Bag * stack_bottom,
UInt stack_align,
TNumAbortFuncBags abort_func )
UInt dirty,
TNumAbortFuncBags abort_func)
{
Bag * p; /* loop variable */
UInt i; /* loop variable */
Expand All @@ -990,6 +993,7 @@ void InitBags (
/* install the allocator and the abort function */
AllocFuncBags = alloc_func;
AbortFuncBags = abort_func;
ExtraMarkFuncBags = 0;

/* install the stack marking function and values */
StackFuncBags = stack_func;
Expand Down Expand Up @@ -1687,6 +1691,11 @@ UInt CollectBags (
for ( i = 0; i < GlobalBags.nr; i++ )
MarkBag( *GlobalBags.addr[i] );

/* allow users of libgap to mark their choice of bags */
/* TODO: This can probably be solved a lot more cleanly */
if ( ExtraMarkFuncBags ) {
(*ExtraMarkFuncBags)();
}

/* mark from the stack */
if ( StackFuncBags ) {
Expand Down
12 changes: 12 additions & 0 deletions src/gasman.h
Expand Up @@ -1153,6 +1153,7 @@ typedef Bag * (* TNumAllocFuncBags) (
UInt need );

typedef void (* TNumStackFuncBags) ( void );
typedef void (* TExtraMarkFuncBags) (void);

typedef void (* TNumAbortFuncBags) (
const Char * msg );
Expand All @@ -1163,6 +1164,7 @@ extern void InitBags (
TNumStackFuncBags stack_func,
Bag * stack_bottom,
UInt stack_align,
UInt dirty,
TNumAbortFuncBags abort_func );

/****************************************************************************
Expand Down Expand Up @@ -1190,4 +1192,14 @@ extern void CallbackForAllBags(
void *AllocateMemoryBlock(UInt size);
#endif

/*
* If not 0 this function will be called in
* CollectBags to allow users of libgap to mark bags
*/
extern TExtraMarkFuncBags ExtraMarkFuncBags;

static void SetExtraMarkFuncBags(TExtraMarkFuncBags func)
{ ExtraMarkFuncBags = func; }
Copy link
Member

Choose a reason for hiding this comment

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

Same as above: Odd non-GAPish code formatting; and what's the point of a setter if wee don't hide the global variable anyway?



#endif // GAP_GASMAN_H
4 changes: 2 additions & 2 deletions src/iostream.c
Expand Up @@ -683,8 +683,8 @@ static Int InitKernel(StructInitInfo * module)

/* init filters and functions */
InitHdlrFuncsFromTable(GVarFuncs);

#if !defined(HPCGAP)
#if !defined(HPCGAP) && !defined(LIBGAP)
/* Set up the trap to detect future dying children */
signal(SIGCHLD, ChildStatusChanged);
#endif
Expand Down