Skip to content

Commit

Permalink
kernel: don't call CloseInput in READ_AS_FUNC
Browse files Browse the repository at this point in the history
... to ensure that all CloseInput() calls are in the same function
as the corresponding OpenInput/OpenInputStream invocation.
  • Loading branch information
fingolfin committed Aug 11, 2020
1 parent 5a1a86b commit 3c9e451
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ int realmain( int argc, char * argv[] )
return 1;
}
func = READ_AS_FUNC();
if (!CloseInput()) {
return 2;
}
crc = SyGAPCRC(SyCompileInput);
type = CompileFunc(
MakeImmString(SyCompileOutput),
Expand Down
14 changes: 6 additions & 8 deletions src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,11 @@ Obj READ_AS_FUNC ( void )
ClearError();
Obj evalResult;
UInt type = ReadEvalFile(&evalResult);
ClearError();

/* get the function */
Obj func = (type == 0) ? evalResult : Fail;

/* close the input file again, and return 'true' */
if ( ! CloseInput() ) {
ErrorQuit("Panic: READ_AS_FUNC cannot close input", 0, 0);
}
ClearError();

/* return the function */
return func;
}
Expand Down Expand Up @@ -952,8 +947,11 @@ static Obj FuncREAD_AS_FUNC(Obj self, Obj input)
if (!OpenInputFileOrStream(SELF_NAME, input))
return False;

/* read the function */
return READ_AS_FUNC();
Obj func = READ_AS_FUNC();
if (!CloseInput()) {
ErrorQuit("Panic: READ_AS_FUNC cannot close input", 0, 0);
}
return func;
}


Expand Down
3 changes: 2 additions & 1 deletion src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
**
*F READ_AS_FUNC() . . . . . . . . . . . . . read current input as function
**
** Read the current input as function and close the input stream.
** Read the current input as function. The caller is responsible for opening
** and closing the input.
*/
Obj READ_AS_FUNC(void);

Expand Down

0 comments on commit 3c9e451

Please sign in to comment.