public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/modula-2] Remove temporary files atexit.
@ 2022-10-06 14:24 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2022-10-06 14:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:72db6dad8e370fe57334788db1f394aefc50932a

commit 72db6dad8e370fe57334788db1f394aefc50932a
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Thu Oct 6 15:24:31 2022 +0100

    Remove temporary files atexit.
    
    This fixes a bug in the bootstrap program mc which would
    leave temporary files in /tmp if it exited before reaching
    the end of the top level module.
    
    gcc/m2/ChangeLog:
    
            * mc-boot/Gdecl.c: Rebuilt.
            * mc-boot/GmcStream.c: Rebuilt.
            * mc-boot/GmcStream.h: Rebuilt.
            * mc-boot/Gtop.c: Rebuilt.
            * mc/mcStream.def (removeFiles): Exported.
            * mc/mcStream.mod (removeFiles): Added comment.
            * mc/top.mod (atexit): Imported.  (init) Install
            atexit handler to remove temporary files.
            (wrapRemoveFiles) New procedure function.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/mc-boot/Gdecl.c     |  1 +
 gcc/m2/mc-boot/GmcStream.c | 38 ++++++++++++++++++++------------------
 gcc/m2/mc-boot/GmcStream.h |  6 ++++++
 gcc/m2/mc-boot/Gtop.c      | 31 +++++++++++++++++++++++++++++++
 gcc/m2/mc/mcStream.def     |  7 +++++++
 gcc/m2/mc/mcStream.mod     |  6 ++++--
 gcc/m2/mc/top.mod          | 17 +++++++++++++++++
 7 files changed, 86 insertions(+), 20 deletions(-)

diff --git a/gcc/m2/mc-boot/Gdecl.c b/gcc/m2/mc-boot/Gdecl.c
index 47cdc9fa796..bbc3325f3b8 100644
--- a/gcc/m2/mc-boot/Gdecl.c
+++ b/gcc/m2/mc-boot/Gdecl.c
@@ -3356,6 +3356,7 @@ extern "C" void keyc_cp (void);
 extern "C" FIO_File mcStream_openFrag (unsigned int id);
 extern "C" void mcStream_setDest (FIO_File f);
 extern "C" FIO_File mcStream_combine (void);
+extern "C" void mcStream_removeFiles (void);
 extern "C" void StrIO_WriteLn (void);
 extern "C" void StrIO_ReadString (char *a, unsigned int _a_high);
 extern "C" void StrIO_WriteString (const char *a_, unsigned int _a_high);
diff --git a/gcc/m2/mc-boot/GmcStream.c b/gcc/m2/mc-boot/GmcStream.c
index 65a481d0f96..2ec838d5b2a 100644
--- a/gcc/m2/mc-boot/GmcStream.c
+++ b/gcc/m2/mc-boot/GmcStream.c
@@ -55,9 +55,9 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #   include "GSFIO.h"
 #   include "GM2RTS.h"
 
-#   define maxBuffer 4096
 typedef FIO_File *mcStream_ptrToFile;
 
+#   define maxBuffer 4096
 static alists_alist listOfFiles;
 static Indexing_Index frag;
 static FIO_File destFile;
@@ -86,22 +86,22 @@ extern "C" void mcStream_setDest (FIO_File f);
 extern "C" FIO_File mcStream_combine (void);
 
 /*
-   removeLater -
+   removeFiles - remove any fragment.
 */
 
-static DynamicStrings_String removeLater (DynamicStrings_String filename);
+extern "C" void mcStream_removeFiles (void);
 
 /*
-   removeNow - removes a single file, s.
+   removeLater -
 */
 
-static void removeNow (DynamicStrings_String s);
+static DynamicStrings_String removeLater (DynamicStrings_String filename);
 
 /*
-   removeFiles -
+   removeNow - removes a single file, s.
 */
 
-static void removeFiles (void);
+static void removeNow (DynamicStrings_String s);
 
 /*
    createTemporaryFile -
@@ -140,16 +140,6 @@ static void removeNow (DynamicStrings_String s)
 }
 
 
-/*
-   removeFiles -
-*/
-
-static void removeFiles (void)
-{
-  alists_foreachItemInListDo (listOfFiles, (alists_performOperation) {(alists_performOperation_t) removeNow});
-}
-
-
 /*
    createTemporaryFile -
 */
@@ -246,12 +236,24 @@ extern "C" FIO_File mcStream_combine (void)
       __builtin_unreachable ();
     }
   Indexing_ForeachIndiceInIndexDo (frag, (Indexing_IndexProcedure) {(Indexing_IndexProcedure_t) copy});
-  removeFiles ();
+  mcStream_removeFiles ();
   return destFile;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
+
+/*
+   removeFiles - remove any fragment.
+*/
+
+extern "C" void mcStream_removeFiles (void)
+{
+  alists_foreachItemInListDo (listOfFiles, (alists_performOperation) {(alists_performOperation_t) removeNow});
+  alists_killList (&listOfFiles);
+  listOfFiles = alists_initList ();
+}
+
 extern "C" void _M2_mcStream_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
 {
   listOfFiles = alists_initList ();
diff --git a/gcc/m2/mc-boot/GmcStream.h b/gcc/m2/mc-boot/GmcStream.h
index 6afda5414e5..45886c09466 100644
--- a/gcc/m2/mc-boot/GmcStream.h
+++ b/gcc/m2/mc-boot/GmcStream.h
@@ -65,6 +65,12 @@ EXTERN void mcStream_setDest (FIO_File f);
 */
 
 EXTERN FIO_File mcStream_combine (void);
+
+/*
+   removeFiles - remove any fragment.
+*/
+
+EXTERN void mcStream_removeFiles (void);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/Gtop.c b/gcc/m2/mc-boot/Gtop.c
index 85121b38e08..85511559e48 100644
--- a/gcc/m2/mc-boot/Gtop.c
+++ b/gcc/m2/mc-boot/Gtop.c
@@ -31,8 +31,16 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #   include "GmcOptions.h"
 #   include "GmcComp.h"
 #   include "GM2RTS.h"
+#   include "GmcStream.h"
+#   include "Glibc.h"
 
 
+/*
+   wrapRemoveFiles - call removeFiles and return 0.
+*/
+
+static int wrapRemoveFiles (void);
+
 /*
    init - translate the source file after handling all the
           program arguments.
@@ -40,6 +48,12 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 
 static void init (void);
 
+/*
+   wrapRemoveFiles - call removeFiles and return 0.
+*/
+
+static int wrapRemoveFiles (void);
+
 /*
    init - translate the source file after handling all the
           program arguments.
@@ -48,6 +62,19 @@ static void init (void);
 static void init (void);
 
 
+/*
+   wrapRemoveFiles - call removeFiles and return 0.
+*/
+
+static int wrapRemoveFiles (void)
+{
+  mcStream_removeFiles ();
+  return 0;
+  /* static analysis guarentees a RETURN statement will be used before here.  */
+  __builtin_unreachable ();
+}
+
+
 /*
    init - translate the source file after handling all the
           program arguments.
@@ -55,6 +82,10 @@ static void init (void);
 
 static void init (void)
 {
+  if ((libc_atexit ((libc_exitP_C) wrapRemoveFiles)) != 0)
+    {
+      libc_perror ((const char *) "atexit failed", 13);
+    }
   M2RTS_ExitOnHalt (1);
   mcComp_compile (mcOptions_handleOptions ());
 }
diff --git a/gcc/m2/mc/mcStream.def b/gcc/m2/mc/mcStream.def
index 80afe87be0c..701206238cc 100644
--- a/gcc/m2/mc/mcStream.def
+++ b/gcc/m2/mc/mcStream.def
@@ -49,4 +49,11 @@ PROCEDURE setDest (f: File) ;
 PROCEDURE combine () : File ;
 
 
+(*
+   removeFiles - remove any fragment.
+*)
+
+PROCEDURE removeFiles ;
+
+
 END mcStream.
diff --git a/gcc/m2/mc/mcStream.mod b/gcc/m2/mc/mcStream.mod
index 8f785d5d050..d752d642ce6 100644
--- a/gcc/m2/mc/mcStream.mod
+++ b/gcc/m2/mc/mcStream.mod
@@ -68,12 +68,14 @@ END removeNow ;
 
 
 (*
-   removeFiles -
+   removeFiles - remove any fragment.
 *)
 
 PROCEDURE removeFiles ;
 BEGIN
-   alists.foreachItemInListDo (listOfFiles, removeNow)
+   alists.foreachItemInListDo (listOfFiles, removeNow) ;
+   alists.killList (listOfFiles) ;
+   listOfFiles := alists.initList ()
 END removeFiles ;
 
 
diff --git a/gcc/m2/mc/top.mod b/gcc/m2/mc/top.mod
index b12b47ee16e..0dd638d604c 100644
--- a/gcc/m2/mc/top.mod
+++ b/gcc/m2/mc/top.mod
@@ -24,6 +24,19 @@ MODULE top ;
 FROM mcOptions IMPORT handleOptions ;
 FROM mcComp IMPORT compile ;
 FROM M2RTS IMPORT ExitOnHalt ;
+FROM mcStream IMPORT removeFiles ;
+FROM libc IMPORT atexit, perror ;
+
+
+(*
+   wrapRemoveFiles - call removeFiles and return 0.
+*)
+
+PROCEDURE wrapRemoveFiles () : INTEGER ;
+BEGIN
+   removeFiles ;
+   RETURN 0
+END wrapRemoveFiles ;
 
 
 (*
@@ -33,6 +46,10 @@ FROM M2RTS IMPORT ExitOnHalt ;
 
 PROCEDURE init ;
 BEGIN
+   IF atexit (wrapRemoveFiles) # 0
+   THEN
+      perror ("atexit failed")
+   END ;
    ExitOnHalt (1) ;
    compile (handleOptions ())
 END init ;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-06 14:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06 14:24 [gcc/devel/modula-2] Remove temporary files atexit Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).