https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108261
--- Comment #26 from Iain Sandoe <iains at gcc dot gnu.org> --- (In reply to Gaius Mulley from comment #25) > Created attachment 54516 [details] > Proposed fix version 6 > > Version 6 (more coroutine tests) and RTint.mod with more descriptive > variable names. This does not solve the timeout issues on Darwin (mentioned here because we were wondering if the issue was related to init ordering). ----- Here's a patch that seems to prevent the hangs (but at the expense of a lot of diagnostic output - it seems modula-2 is somehow calling the OS select with some bad input) .. I cannot reproduce this calling it from C. >From 92cc7b7c19735ea32e0800b369a2e49f85047e27 Mon Sep 17 00:00:00 2001 From: Iain Sandoe <i...@sandoe.co.uk> Date: Thu, 23 Feb 2023 09:54:01 +0000 Subject: [PATCH] modula-2 : Some TLC for select fail case diagnostics --- gcc/m2/gm2-libs/RTint.mod | 52 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/gcc/m2/gm2-libs/RTint.mod b/gcc/m2/gm2-libs/RTint.mod index d8ca8dd5694..796430a55df 100644 --- a/gcc/m2/gm2-libs/RTint.mod +++ b/gcc/m2/gm2-libs/RTint.mod @@ -669,6 +669,7 @@ PROCEDURE Listen (untilInterrupt: BOOLEAN; VAR found: BOOLEAN ; r : INTEGER ; + zero, after, b4, t : Timeval ; @@ -742,6 +743,7 @@ BEGIN ELSE GetTime (t, s, m) ; Assert (m<Microseconds) ; + zero := InitTime (0, 0) ; b4 := InitTime (0, 0) ; after := InitTime (0, 0) ; r := GetTimeOfDay (b4) ; @@ -762,23 +764,35 @@ BEGIN IF r=-1 THEN perror ("select") ; - r := select (maxFd+1, i, o, NIL, NIL) ; - IF r=-1 + r := select (maxFd+1, i, o, NIL, zero) ; + IF r#-1 THEN - perror ("select timeout argument is faulty") - END ; - r := select (maxFd+1, i, NIL, NIL, t) ; - IF r=-1 - THEN - perror ("select output fd argument is faulty") - END ; - r := select (maxFd+1, NIL, o, NIL, t) ; - IF r=-1 - THEN - perror ("select input fd argument is faulty") + perror ("select timeout argument was faulty") ELSE - perror ("select maxFD+1 argument is faulty") - END + r := select (maxFd+1, i, NIL, NIL, t) ; + IF r#-1 + THEN + perror ("select output fd argument was faulty") + ELSE + r := select (maxFd+1, NIL, o, NIL, t) ; + IF r#-1 + THEN + perror ("select input fd argument was faulty") + ELSE + IF maxFd=-1 + THEN + r := select (0, NIL, NIL, NIL, t) ; + IF r=-1 + THEN + perror ("select does not accept nfds == 0 ") ; + r := 0 + END + ELSE + perror ("select maxFD+1 argument was faulty") ; + END + END + END + END END UNTIL r#-1 END ; @@ -791,11 +805,15 @@ BEGIN END ; IF after#NIL THEN - t := KillTime (after) + after := KillTime (after) END ; IF b4#NIL THEN - t := KillTime (b4) + b4 := KillTime (b4) + END ; + IF zero#NIL + THEN + zero := KillTime (zero) END ; IF i#NIL THEN -- 2.24.3 (Apple Git-128)