diff --git a/src/io.c b/src/io.c index 898737a93b..6003de4e72 100644 --- a/src/io.c +++ b/src/io.c @@ -983,7 +983,14 @@ static Int GetLine2(TypInputFile * input) if (input->sline == 0 || (IS_STRING_REP(input->sline) && GET_LEN_STRING(input->sline) <= input->spos)) { - input->sline = CALL_1ARGS( ReadLineFunc, input->stream ); + // If we are in the process of quitting, we cannot call + // GAP functions, so we just return EOF. + if (STATE(UserHasQuit) || STATE(UserHasQUIT)) { + input->sline = Fail; + } + else { + input->sline = CALL_1ARGS(ReadLineFunc, input->stream); + } input->spos = 0; } if ( input->sline == Fail || ! IS_STRING(input->sline) ) { diff --git a/tst/testspecial/error-in-InputTextString.g b/tst/testspecial/error-in-InputTextString.g new file mode 100644 index 0000000000..52aec32242 --- /dev/null +++ b/tst/testspecial/error-in-InputTextString.g @@ -0,0 +1,2 @@ +READ_NORECOVERY(InputTextString("Print(1 + [()]);")); +quit; diff --git a/tst/testspecial/error-in-InputTextString.g.out b/tst/testspecial/error-in-InputTextString.g.out new file mode 100644 index 0000000000..4fff2f88a2 --- /dev/null +++ b/tst/testspecial/error-in-InputTextString.g.out @@ -0,0 +1,9 @@ +gap> READ_NORECOVERY(InputTextString("Print(1 + [()]);")); +Error, no method found! For debugging hints type ?Recovery from NoMethodFound +Error, no 1st choice method found for `+' on 2 arguments at GAPROOT/lib/methsel2.g:LINE called from +( ) + called from read-eval loop at stream:1 +type 'quit;' to quit to outer loop +brk> quit; +fail +gap> QUIT; diff --git a/tst/testspecial/exit-in-InputTextString.g b/tst/testspecial/exit-in-InputTextString.g new file mode 100644 index 0000000000..a9d8389ad8 --- /dev/null +++ b/tst/testspecial/exit-in-InputTextString.g @@ -0,0 +1 @@ +READ_NORECOVERY(InputTextString("Print(QuitGap(0));")); diff --git a/tst/testspecial/exit-in-InputTextString.g.out b/tst/testspecial/exit-in-InputTextString.g.out new file mode 100644 index 0000000000..29118d3b64 --- /dev/null +++ b/tst/testspecial/exit-in-InputTextString.g.out @@ -0,0 +1 @@ +gap> READ_NORECOVERY(InputTextString("Print(QuitGap(0));"));