Skip to content

Commit

Permalink
use EXIT\_FAILURE for fatal error conditions (fixes issue #13 by poll…
Browse files Browse the repository at this point in the history
…uks)
  • Loading branch information
gooofy committed Dec 30, 2021
1 parent ccd4f8c commit e637abc
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Improvements:
Bug Fixes:

* examples: tetris code cleanup, use custom fonts
* use EXIT\_FAILURE for fatal error conditions (fixes issue #13 by polluks)

## 0.8.1

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/aqb.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static void check_amigaos_env(void)
if ( ((struct Library *)DOSBase)->lib_Version < 37)
{
U_request (NULL, NULL, "OK", "DOS library V%d is too old, need at least V37", ((struct Library *)DOSBase)->lib_Version);
exit(1);
exit(EXIT_FAILURE);
}

struct Process *aqbProc;
Expand Down
36 changes: 18 additions & 18 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!sourcef)
{
LOG_printf (LOG_ERROR, "failed to read %s: %s\n\n", sourcefn, strerror(errno));
CO_exit(2);
CO_exit(EXIT_FAILURE);
}

frags = FE_sourceProgram(sourcef, sourcefn, /*is_main=*/!symfn, module_name);
Expand All @@ -110,7 +110,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (EM_anyErrors)
{
LOG_printf (LOG_ERROR, "\n\nfrontend processing failed - exiting.\n");
CO_exit(3);
CO_exit(EXIT_FAILURE);
}

LOG_printf (OPT_get(OPTION_VERBOSE) ? LOG_INFO : LOG_DEBUG, "\n\nsemantics worked.\n");
Expand All @@ -129,7 +129,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
else
{
LOG_printf (LOG_ERROR, "\n** ERROR: failed to write symbol file %s .\n", symfn);
CO_exit(4);
CO_exit(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!RA_regAlloc(frame, body) || EM_anyErrors)
{
LOG_printf (LOG_ERROR, "\n\nregister allocation failed - exiting.\n");
CO_exit(5);
CO_exit(EXIT_FAILURE);
}

CG_procEntryExitAS(frag);
Expand All @@ -185,7 +185,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!out)
{
LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_gas_fn);
CO_exit(6);
CO_exit(EXIT_FAILURE);
}
CG_writeASMFile (out, frags, AS_dialect_gas);
fclose(out);
Expand All @@ -197,7 +197,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!out)
{
LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_asmpro_fn);
CO_exit(7);
CO_exit(EXIT_FAILURE);
}
CG_writeASMFile (out, frags, AS_dialect_ASMPro);
fclose(out);
Expand All @@ -209,7 +209,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!out)
{
LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_vasm_fn);
CO_exit(8);
CO_exit(EXIT_FAILURE);
}
CG_writeASMFile (out, frags, AS_dialect_vasm);
fclose(out);
Expand Down Expand Up @@ -245,21 +245,21 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
U_memstat();

if (!AS_assembleCode (obj, body, expt, frame))
CO_exit(9);
CO_exit(EXIT_FAILURE);

break;
}
case CG_stringFrag:
AS_assembleDataAlign2 (obj);
if (!AS_assembleString (obj, frag->u.stringg.label, frag->u.stringg.str, frag->u.stringg.msize))
CO_exit(10);
CO_exit(EXIT_FAILURE);
break;
case CG_dataFrag:
if (!frag->u.data.size)
break;
AS_assembleDataAlign2 (obj);
if (!AS_assembleDataLabel (obj, frag->u.data.label, frag->u.data.expt, frag->u.data.ty))
CO_exit(11);
CO_exit(EXIT_FAILURE);
if (frag->u.data.init)
{
for (CG_dataFragNode n=frag->u.data.init; n; n=n->next)
Expand All @@ -268,7 +268,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
{
case CG_labelNode:
if (!AS_assembleDataLabel (obj, n->u.label, /*expt=*/FALSE, /*ty=*/NULL))
CO_exit(12);
CO_exit(EXIT_FAILURE);
break;
case CG_constNode:
{
Expand Down Expand Up @@ -331,14 +331,14 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (EM_anyErrors)
{
LOG_printf (LOG_ERROR, "\n\nassembler failed - exiting.\n");
CO_exit(13);
CO_exit(EXIT_FAILURE);
}

if (objfn)
LI_segmentWriteObjectFile (obj, objfn);

if (!binfn)
CO_exit(0);
CO_exit(EXIT_FAILURE);

/*
* machine code generation (link phase)
Expand All @@ -352,12 +352,12 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!fObj)
{
LOG_printf (LOG_ERROR, "*** ERROR: failed to open startup.o\n\n");
CO_exit(14);
CO_exit(EXIT_FAILURE);
}
if (!LI_segmentListReadObjectFile (UP_link, sl, "startup.o", fObj))
{
fclose(fObj);
CO_exit(15);
CO_exit(EXIT_FAILURE);
}
fclose(fObj);

Expand All @@ -375,20 +375,20 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
if (!fObj)
{
LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s\n\n", mod_fn);
CO_exit(16);
CO_exit(EXIT_FAILURE);
}
if (!LI_segmentListReadObjectFile (UP_link, sl, S_name(n->m->name), fObj))
{
fclose(fObj);
CO_exit(17);
CO_exit(EXIT_FAILURE);
}
fclose(fObj);
}

if (!LI_link (UP_link, sl))
{
LOG_printf (LOG_ERROR, "*** ERROR: failed to link.\n\n");
CO_exit(18);
CO_exit(EXIT_FAILURE);
}

LI_segmentListWriteLoadFile (sl, binfn);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/dis68k.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ void DEBUG_disasm(IDE_instance ed, unsigned long int start, unsigned long int en
} break;

default : printf("opnum out of range in switch (=%i)\n", opnum);
exit(1);
exit(EXIT_FAILURE);
}
}
if (decoded) opnum = 88;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static void env_fail (string msg)
modf = NULL;
}

exit(126);
exit(EXIT_FAILURE);
}

static void fwrite_double(FILE *f, double d)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ static bool _ide_save (IDE_instance ed, bool save_as)
if (!sourcef)
{
fprintf(stderr, "failed to write %s: %s\n\n", ed->sourcefn, strerror(errno));
exit(2);
exit(EXIT_FAILURE);
}

static char *indent_str = " ";
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void link_fail (string msg)
g_fObjFile = NULL;
}

CO_exit(127);
CO_exit(EXIT_FAILURE);
}

#if LOG_LEVEL == LOG_DEBUG
Expand Down Expand Up @@ -1265,7 +1265,7 @@ void LI_segmentWriteObjectFile (AS_object obj, string objfn)
if (!g_fObjFile)
{
LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s for writing.\n\n", objfn);
exit(128);
CO_exit(EXIT_FAILURE);
}
write_hunk_unit (objfn, g_fObjFile);

Expand Down Expand Up @@ -1299,7 +1299,7 @@ void LI_segmentListWriteLoadFile (LI_segmentList sl, string loadfn)
if (!g_fLoadFile)
{
LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s for writing.\n\n", loadfn);
exit(128);
CO_exit(EXIT_FAILURE);
}
write_hunk_header (sl, g_fLoadFile);

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void OPT_init(void)
if (snprintf (g_pref_fn, PATH_MAX, "%s/prefs.ini", aqb_home)<0)
{
fprintf (stderr, "prefs.ini path too long\n");
exit(42);
exit(EXIT_FAILURE);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ui_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static uint16_t UI_getch (void)
char c, seq[5];
while ((nread = read(STDIN_FILENO,&c,1)) == 0);
if (nread == -1)
exit(1);
exit(EXIT_FAILURE);

while(1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void *checked_malloc (size_t len)
if (!p)
{
LOG_printf(LOG_ERROR, "\nran out of memory!\n");
exit(1);
exit(EXIT_FAILURE);
}
// fprintf(stderr, "checked_malloc len=%zu -> p=%p\n", len, p);
return p;
Expand Down
6 changes: 3 additions & 3 deletions src/tools/reactiontest/ratest.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ int main(void)
cleanexit("failed to open intuition.library\n");
DPRINTF ("intuition.library opened\n");

if (! (WindowBase = OpenLibrary((STRPTR)"window.class", 47)) )
if (! (WindowBase = OpenLibrary((STRPTR)"window.class", 37)) )
cleanexit("failed to open window.class\n");
DPRINTF ("window.class opened\n");

if (! (LayoutBase = OpenLibrary((STRPTR)"gadgets/layout.gadget", 47)) )
if (! (LayoutBase = OpenLibrary((STRPTR)"gadgets/layout.gadget", 37)) )
cleanexit("failed to open gadgets/layout.gadget\n");
DPRINTF ("gadgets/layout.gadget opened\n");

if (! (ButtonBase = OpenLibrary((STRPTR)"gadgets/button.gadget", 47)) )
if (! (ButtonBase = OpenLibrary((STRPTR)"gadgets/button.gadget", 0)) )
cleanexit("failed to open gadgets/button.gadget\n");
DPRINTF ("gadgets/button.gadget opened\n");

Expand Down

1 comment on commit e637abc

@polluks
Copy link
Contributor

@polluks polluks commented on e637abc Jan 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gooofy Of course the compiler can use different return codes like EXIT_FAILURE+x.

Please sign in to comment.