Skip to content

Commit

Permalink
Make CloseInput() work in HPC-GAP for spawned threads without stdin.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehrends committed Oct 30, 2019
1 parent 286560c commit 92c3aa3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,16 @@ UInt OpenInputStream(Obj stream, UInt echo)
UInt CloseInput ( void )
{
/* refuse to close the initial input file */
#ifdef HPCGAP
// In HPC-GAP, only for the main thread.
if (TLS(threadID) != 0) {
if (IO()->InputStackPointer <= 0)
return 0;
} else
#else
if (IO()->InputStackPointer <= 1)
return 0;
#endif

/* close the input file */
if (!IO()->Input->isstream) {
Expand All @@ -626,6 +634,12 @@ UInt CloseInput ( void )

/* revert to last file */
const int sp = --IO()->InputStackPointer;
#ifdef HPCGAP
if (sp == 0) {
IO()->Input = NULL;
return 1;
}
#endif
IO()->Input = IO()->InputStack[sp - 1];
STATE(In) = IO()->Input->ptr;
STATE(Scanner).Symbol = IO()->Input->symbol;
Expand Down

0 comments on commit 92c3aa3

Please sign in to comment.