From c5345bf6ac2f3ba3169b6f436a5cb35cecf53954 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 22 Mar 1989 17:36:20 +0000 Subject: [PATCH] Changed semantics of CallAtEnd so that it calls installed procedures in reversed order --- lang/m2/libm2/Epilogue.def | 4 ++-- lang/m2/libm2/halt.c | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lang/m2/libm2/Epilogue.def b/lang/m2/libm2/Epilogue.def index ee87c4640..029c867f4 100644 --- a/lang/m2/libm2/Epilogue.def +++ b/lang/m2/libm2/Epilogue.def @@ -13,8 +13,8 @@ DEFINITION MODULE Epilogue; PROCEDURE CallAtEnd(p: PROC): BOOLEAN; (* Add procedure "p" to the list of procedures that must be executed when the program finishes. - When the program finishes, these procedures are executed in the order in - which they were added to the list. + When the program finishes, these procedures are executed in the REVERSE + order in which they were added to the list. This procedure returns FALSE when there are too many procedures to be called (the list has a fixed size). *) diff --git a/lang/m2/libm2/halt.c b/lang/m2/libm2/halt.c index 01eeef3f2..ca98a6969 100644 --- a/lang/m2/libm2/halt.c +++ b/lang/m2/libm2/halt.c @@ -8,7 +8,7 @@ Author: Ceriel J.H. Jacobs Version: $Header$ */ -#define MAXPROCS 16 +#define MAXPROCS 32 static int callindex = 0; static int (*proclist[MAXPROCS])(); @@ -17,7 +17,7 @@ _cleanup() { register int i; - for (i = 0; i < callindex; i++) { + for (i = callindex; --i >= 0;) { (*proclist[i])(); } callindex = 0; @@ -29,9 +29,7 @@ CallAtEnd(p) if (callindex >= MAXPROCS) { return 0; } - else { - proclist[callindex++] = p; - } + proclist[callindex++] = p; return 1; }