Add DOH Exit() and SetExitHandler()

Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
This commit is contained in:
Olly Betts 2022-03-06 12:33:54 +13:00
commit 55377bdc08
33 changed files with 243 additions and 173 deletions

View file

@ -1782,7 +1782,7 @@ declaration : swig_directive { $$ = $1; }
} else {
Swig_error(cparse_file, cparse_line, "Syntax error in input(1).\n");
}
SWIG_exit(EXIT_FAILURE);
Exit(EXIT_FAILURE);
}
/* Out of class constructor/destructor declarations */
| c_constructor_decl {
@ -2015,7 +2015,7 @@ constant_directive : CONSTANT identifier EQUAL definetype SEMI {
}
| CONSTANT error END {
Swig_error(cparse_file,cparse_line,"Missing semicolon (';') after %%constant.\n");
SWIG_exit(EXIT_FAILURE);
Exit(EXIT_FAILURE);
}
;
@ -3372,7 +3372,7 @@ c_decl_tail : SEMI {
} else {
Swig_error(cparse_file, cparse_line, "Syntax error - possibly a missing semicolon (';').\n");
}
SWIG_exit(EXIT_FAILURE);
Exit(EXIT_FAILURE);
}
;
@ -3666,7 +3666,7 @@ c_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end {
}
if (err) {
Swig_error(cparse_file,cparse_line,"Syntax error in input(2).\n");
SWIG_exit(EXIT_FAILURE);
Exit(EXIT_FAILURE);
}
}
;
@ -4661,7 +4661,7 @@ cpp_members : cpp_member cpp_members {
int start_line = cparse_line;
skip_decl();
Swig_error(cparse_file,start_line,"Syntax error in input(3).\n");
SWIG_exit(EXIT_FAILURE);
Exit(EXIT_FAILURE);
} cpp_members {
$$ = $3;
}