-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow registering global handlers for GAP_TRY/GAP_CATCH.
- Loading branch information
Showing
6 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Small program to test libgap linkability and basic working | ||
*/ | ||
#include "trycatch.h" | ||
#include "common.h" | ||
|
||
static int level = 0; | ||
|
||
static void handle_trycatch(TryCatchMode mode) | ||
{ | ||
switch (mode) { | ||
case TryEnter: | ||
level++; | ||
if (level == 1) | ||
printf("Entering GAP_TRY section\n"); | ||
break; | ||
case TryLeave: | ||
if (level == 1) | ||
printf("Leaving GAP_TRY section\n"); | ||
level--; | ||
break; | ||
case TryCatch: | ||
if (level == 1) | ||
printf("Caught error in GAP_TRY section\n"); | ||
level--; | ||
break; | ||
} | ||
} | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
printf("# Initializing GAP...\n"); | ||
GAP_Initialize(argc, argv, 0, 0, 1); | ||
RegisterTryCatchHandler(handle_trycatch); | ||
test_eval("OnBreak := false;;"); | ||
// Necessary to redirect error printing to stdout. | ||
test_eval("MakeReadWriteGVar(\"ERROR_OUTPUT\");"); | ||
test_eval("ERROR_OUTPUT := MakeImmutable(\"*stdout*\");;"); | ||
test_eval("Display(CALL_WITH_CATCH(function() return 314; end, []));;"); | ||
test_eval("Display(CALL_WITH_CATCH(function() return [][1]; end, []));;"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Initializing GAP... | ||
gap> OnBreak := false;; | ||
|
||
gap> MakeReadWriteGVar("ERROR_OUTPUT"); | ||
|
||
gap> ERROR_OUTPUT := MakeImmutable("*stdout*");; | ||
|
||
gap> Display(CALL_WITH_CATCH(function() return 314; end, []));; | ||
Entering GAP_TRY section | ||
Leaving GAP_TRY section | ||
[ true, 314 ] | ||
|
||
gap> Display(CALL_WITH_CATCH(function() return [][1]; end, []));; | ||
Entering GAP_TRY section | ||
Error, List Element: <list>[1] must have an assigned value | ||
Caught error in GAP_TRY section | ||
[ false, 0 ] | ||
|