From f9a4a145345d4455c6431a79e3ce9a1029eb3dcb Mon Sep 17 00:00:00 2001 From: borutr Date: Tue, 3 Sep 2002 18:30:10 +0000 Subject: [PATCH] introduced atexit() handler for teporay files removal in case of errors, assertions, ... git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2093 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 ++++- src/SDCCglue.c | 32 +++++++++++-------- src/SDCCglue.h | 5 +-- src/SDCCmain.c | 83 ++++++++++++++++++++------------------------------ src/pic/glue.c | 4 +-- 5 files changed, 62 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index da88c07f..f209193e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-09-03 Borut Razem + * sdcc/src/SDCCglue.c, sdcc/src/SDCCglue.h, sdcc/src/SDCCmain.c, + sdcc/src/pic/glue.c: + introduced atexit() handler for teporay files removal in case of + errors, assertions, ... + 2002-08-29 Borut Razem * sdcc/support/cpp2/auto-host_vc_in.h: re-definition of O_BINARY and other O_XXX as _O_BINARY and _O_XXX, so the problem @@ -11,7 +17,7 @@ ralloc.c(1442) : warning C4700: local variable 'clr' used without having been initialized 2002-08-28 Bernhard Held - * src/SDCCglue.c (printIvalArray): iterative calculation of array length + * src/SDCCglue.c (printIvalArray): iterative calculation of array length 2002-08-28 Jesus Calvino-Fraga and Borut Razem * sdcc/sdcc.dsw: added sdcpp, sdcppa, yacc, conf projects diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 4af59fc4..795b8a4a 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -60,7 +60,7 @@ DEFSETFUNC (closeTmpFiles) } /*-----------------------------------------------------------------*/ -/* rmTmpFiles - closes all tmp files created by the compiler */ +/* rmTmpFiles - unlinks all tmp files created by the compiler */ /* because of BRAIN DEAD MS/DOS & CYGNUS Libraries */ /*-----------------------------------------------------------------*/ DEFSETFUNC (rmTmpFiles) @@ -75,6 +75,21 @@ DEFSETFUNC (rmTmpFiles) return 0; } +/*-----------------------------------------------------------------*/ +/* rm_tmpfiles - close and remove temporary files and delete sets */ +/*-----------------------------------------------------------------*/ +void +rm_tmpfiles (void) +{ + /* close temporary files */ + applyToSet (tmpfileSet, closeTmpFiles); + /* remove temporary files */ + applyToSet (tmpfileNameSet, rmTmpFiles); + /* delete temorary file sets */ + deleteSet (&tmpfileSet); + deleteSet (&tmpfileNameSet); +} + /*-----------------------------------------------------------------*/ /* copyFile - copies source file to destination file */ /*-----------------------------------------------------------------*/ @@ -1165,7 +1180,7 @@ emitStaticSeg (memmap * map, FILE * out) /* emitMaps - emits the code for the data portion the code */ /*-----------------------------------------------------------------*/ void -emitMaps () +emitMaps (void) { inInitMode++; /* no special considerations for the following @@ -1414,7 +1429,7 @@ emitOverlay (FILE * afile) /* glue - the final glue that hold the whole thing together */ /*-----------------------------------------------------------------*/ void -glue () +glue (void) { FILE *vFile; FILE *asmFile; @@ -1665,18 +1680,9 @@ glue () port->genAssemblerEnd(asmFile); } fclose (asmFile); - applyToSet (tmpfileSet, closeTmpFiles); - applyToSet (tmpfileNameSet, rmTmpFiles); -} -#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER) -void -rm_tmpfiles (void) -{ - applyToSet (tmpfileSet, closeTmpFiles); - applyToSet (tmpfileNameSet, rmTmpFiles); + rm_tmpfiles (); } -#endif /** Creates a temporary file name a'la tmpnam which avoids the bugs in cygwin wrt c:\tmp. diff --git a/src/SDCCglue.h b/src/SDCCglue.h index a9832354..6b3a3b3c 100644 --- a/src/SDCCglue.h +++ b/src/SDCCglue.h @@ -27,7 +27,7 @@ #ifndef SDCCGLUE_H #define SDCCGLUE_H 1 -void glue (); +void glue (void); /* drdani Jan 30 2000 This is needed in gen.c of z80 port */ char *aopLiteral (value *, int); @@ -38,10 +38,7 @@ extern symbol *interrupts[]; extern set *publics; extern set *tmpfileSet; -#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER) void rm_tmpfiles (void); -#endif - int pointerTypeToGPByte (const int p_type, const char *iname, const char *oname); diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 506bfb08..a2e89e51 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1363,7 +1363,7 @@ preProcess (char **envp) /* Have to set cppoutfilename to something, even if just pre-processing. */ setMainValue ("cppoutfilename", preOutName ? preOutName : ""); - + if (options.verbose) printf ("sdcc: Calling preprocessor...\n"); @@ -1560,6 +1560,9 @@ main (int argc, char **argv, char **envp) exit (1); } + /* install atexit handler */ + atexit(rm_tmpfiles); + /* Before parsing the command line options, do a * search for the port and processor and initialize * them if they're found. (We can't gurantee that these @@ -1624,58 +1627,38 @@ main (int argc, char **argv, char **envp) yyparse (); - if (!fatalError) - { - if (TARGET_IS_PIC) { - /* TSD PIC port hack - if the PIC port option is enabled - and SDCC is used to generate PIC code, then we will - generate .asm files in gpasm's format instead of SDCC's - assembler's format - */ + if (fatalError) { + // @FIX: Dario Vecchio 03-05-2001 + if (preOutName) { + if (yyin && yyin != stdin) + fclose (yyin); + unlink (preOutName); + Safe_free (preOutName); + } + // EndFix + return 1; + } + + if (TARGET_IS_PIC) { + /* TSD PIC port hack - if the PIC port option is enabled + and SDCC is used to generate PIC code, then we will + generate .asm files in gpasm's format instead of SDCC's + assembler's format + */ #if !OPT_DISABLE_PIC - picglue (); + picglue (); #endif - } else { - glue (); - } - - if (fatalError) - { - // @FIX: Dario Vecchio 03-05-2001 - if (preOutName) - { - if (yyin && yyin != stdin) - fclose (yyin); - unlink (preOutName); - Safe_free (preOutName); - } - // EndFix - return 1; - } - if (!options.c1mode && !noAssemble) - { - if (options.verbose) - printf ("sdcc: Calling assembler...\n"); - assemble (envp); - } - } - else - { - // @FIX: Dario Vecchio 03-05-2001 - if (preOutName) - { - if (yyin && yyin != stdin) - fclose (yyin); - unlink (preOutName); - Safe_free (preOutName); - } - // EndFix - #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER) - rm_tmpfiles(); - #endif - return 1; - } + } + else { + glue (); + } + if (!options.c1mode && !noAssemble) + { + if (options.verbose) + printf ("sdcc: Calling assembler...\n"); + assemble (envp); + } } closeDumpFiles(); diff --git a/src/pic/glue.c b/src/pic/glue.c index 45896e1e..e0f73fb7 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -961,6 +961,6 @@ picglue () fprintf (asmFile,"\tend\n"); fclose (asmFile); - applyToSet(tmpfileSet,closeTmpFiles); - applyToSet(tmpfileNameSet, rmTmpFiles); + + rm_tmpfiles(); } -- 2.30.2