From 1ba31278f8bee43b6aa7e7053030a894c0f55285 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Fri, 30 Nov 2018 09:53:31 +0000 Subject: [PATCH] allow signal handling by the GAP kernel to be disabled for embedding in other applications --- src/gap.c | 7 ++++--- src/gap.h | 4 ++-- src/libgap-api.c | 5 +++-- src/libgap-api.h | 3 ++- src/system.c | 7 +++++-- src/system.h | 10 +++++----- tst/testlibgap/basic.c | 2 +- tst/testlibgap/wscreate.c | 2 +- tst/testlibgap/wsload.c | 2 +- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/gap.c b/src/gap.c index 505fe9e986..4cf59986cf 100644 --- a/src/gap.c +++ b/src/gap.c @@ -436,7 +436,7 @@ int realmain( int argc, char * argv[] ) SetupGAPLocation(argc, argv); /* initialize everything and read init.g which runs the GAP session */ - InitializeGap( &argc, argv ); + InitializeGap( &argc, argv, 1 ); if (!STATE(UserHasQUIT)) { /* maybe the user QUIT from the initial read of init.g somehow*/ /* maybe compile in which case init.g got skipped */ @@ -1698,10 +1698,11 @@ static Obj POST_RESTORE; void InitializeGap ( int * pargc, - char * argv [] ) + char * argv [], + UInt handleSignals ) { /* initialize the basic system and gasman */ - InitSystem( *pargc, argv ); + InitSystem( *pargc, argv, handleSignals ); /* Initialise memory -- have to do this here to make sure we are at top of C stack */ InitBags(SyStorMin, diff --git a/src/gap.h b/src/gap.h index 2793fdfa7d..06097b7ed0 100644 --- a/src/gap.h +++ b/src/gap.h @@ -129,9 +129,9 @@ enum { /**************************************************************************** ** -*F InitializeGap( , ) . . . . . . . . . . . . . . . . init GAP +*F InitializeGap( , , ) . . . . . . . init GAP */ -void InitializeGap(int * pargc, char * argv[]); +void InitializeGap(int * pargc, char * argv[], UInt handleSignals); /**************************************************************************** diff --git a/src/libgap-api.c b/src/libgap-api.c index 891c631022..91d6c19e9c 100644 --- a/src/libgap-api.c +++ b/src/libgap-api.c @@ -36,9 +36,10 @@ void GAP_Initialize(int argc, char ** argv, GAP_CallbackFunc markBagsCallback, - GAP_CallbackFunc errorCallback) + GAP_CallbackFunc errorCallback, + int handleSignals) { - InitializeGap(&argc, argv); + InitializeGap(&argc, argv, handleSignals); SetExtraMarkFuncBags(markBagsCallback); STATE(JumpToCatchCallback) = errorCallback; diff --git a/src/libgap-api.h b/src/libgap-api.h index fa5d0d922c..1e94701f90 100644 --- a/src/libgap-api.h +++ b/src/libgap-api.h @@ -154,7 +154,8 @@ typedef void (*GAP_CallbackFunc)(void); void GAP_Initialize(int argc, char ** argv, GAP_CallbackFunc markBagsCallback, - GAP_CallbackFunc errorCallback); + GAP_CallbackFunc errorCallback, + int handleSignals); //// diff --git a/src/system.c b/src/system.c index 783fb3f1de..2cefe89827 100644 --- a/src/system.c +++ b/src/system.c @@ -1041,7 +1041,8 @@ UInt SyOriginalArgc; void InitSystem ( Int argc, - Char * argv [] ) + Char * argv [], + UInt handleSignals ) { Char * *ptrlist; UInt i; /* loop variable */ @@ -1098,7 +1099,9 @@ void InitSystem ( rl_initialize (); #endif - SyInstallAnswerIntr(); + if (handleSignals) { + SyInstallAnswerIntr(); + } #if defined(SYS_DEFAULT_PATHS) SySetGapRootPath( SYS_DEFAULT_PATHS ); diff --git a/src/system.h b/src/system.h index 3ddb192015..05a77cd1db 100644 --- a/src/system.h +++ b/src/system.h @@ -510,16 +510,16 @@ Int RegisterSyLongjmpObserver(voidfunc); /**************************************************************************** ** -*F InitSystem( , ) . . . . . . . . . initialize system package +*F InitSystem( , , ) . initialize system package ** ** 'InitSystem' is called very early during the initialization from 'main'. ** It is passed the command line array , to look for options. ** ** For UNIX it initializes the default files 'stdin', 'stdout' and 'stderr', -** installs the handler 'syAnswerIntr' to answer the user interrupts -** '-C', scans the command line for options, sets up the GAP root paths, -** locates the '.gaprc' file (if any), and more. +** and if handleSignals is non-zero installs the handler 'syAnswerIntr' to +** answer the user interrupts '-C', scans the command line for options, +** sets up the GAP root paths, locates the '.gaprc' file (if any), and more. */ -void InitSystem(Int argc, Char * argv[]); +void InitSystem(Int argc, Char * argv[], UInt handleSignals); #endif // GAP_SYSTEM_H diff --git a/tst/testlibgap/basic.c b/tst/testlibgap/basic.c index 4f96a7cbc5..04ddcf43e9 100644 --- a/tst/testlibgap/basic.c +++ b/tst/testlibgap/basic.c @@ -5,7 +5,7 @@ int main(int argc, char ** argv) { printf("# Initializing GAP...\n"); - GAP_Initialize(argc, argv, 0, 0); + GAP_Initialize(argc, argv, 0, 0, 1); test_eval("1+2+3;"); test_eval("g:=FreeGroup(2);"); test_eval("a:=g.1;"); diff --git a/tst/testlibgap/wscreate.c b/tst/testlibgap/wscreate.c index 601bb341d8..9001f9cfd5 100644 --- a/tst/testlibgap/wscreate.c +++ b/tst/testlibgap/wscreate.c @@ -5,7 +5,7 @@ #include "common.h" int main(int argc, char ** argv) { - GAP_Initialize(argc, argv, 0, 0); + GAP_Initialize(argc, argv, 0, 0, 1); test_eval("g:=FreeGroup(2);"); test_eval("a:=g.1;"); test_eval("b:=g.2;"); diff --git a/tst/testlibgap/wsload.c b/tst/testlibgap/wsload.c index 319c4f6772..994ff50062 100644 --- a/tst/testlibgap/wsload.c +++ b/tst/testlibgap/wsload.c @@ -12,7 +12,7 @@ int main(int argc, char ** argv) args[argc] = lpar; args[argc+1] = wsname; args[argc+2] = NULL; - GAP_Initialize(argc+2, args, 0, 0); + GAP_Initialize(argc+2, args, 0, 0, 1); printf("# looking at saved stuff...\n"); test_eval("g;"); test_eval("a;");