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:
parent
7bdef23304
commit
55377bdc08
33 changed files with 243 additions and 173 deletions
|
|
@ -83,11 +83,11 @@ void Swig_check_options(int check_input) {
|
|||
}
|
||||
if (error) {
|
||||
Printf(stderr, "Use 'swig -help' for available options.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
if (check_input && marked[numargs - 1]) {
|
||||
Printf(stderr, "Must specify an input file. Use -help for available options.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,5 +100,5 @@ void Swig_check_options(int check_input) {
|
|||
void Swig_arg_error(void) {
|
||||
Printf(stderr, "SWIG : Unable to parse command line options.\n");
|
||||
Printf(stderr, "Use 'swig -help' for available options.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1162,7 +1162,7 @@ int Swig_scopename_check(const String *s) {
|
|||
|
||||
String *Swig_string_command(String *s) {
|
||||
Swig_error("SWIG", Getline(s), "Command encoder no longer supported - use regex encoder instead.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1309,7 +1309,7 @@ static int split_regex_pattern_subst(String *s, String **pattern, String **subst
|
|||
|
||||
err_out:
|
||||
Swig_error("SWIG", Getline(s), "Invalid regex substitution: '%s'.\n", s);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1435,7 +1435,7 @@ String *Swig_string_regex(String *s) {
|
|||
pcre2_get_error_message (pcre_errornum, pcre_error, sizeof pcre_error);
|
||||
Swig_error("SWIG", Getline(s), "PCRE compilation failed: '%s' in '%s':%i.\n",
|
||||
pcre_error, Char(pattern), pcre_errorpos);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL);
|
||||
rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)input, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL);
|
||||
|
|
@ -1445,7 +1445,7 @@ String *Swig_string_regex(String *s) {
|
|||
} else if (rc != PCRE2_ERROR_NOMATCH) {
|
||||
Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" using \"%s\".\n",
|
||||
rc, Char(pattern), input);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1470,7 +1470,7 @@ String *Swig_pcre_version(void) {
|
|||
|
||||
String *Swig_string_regex(String *s) {
|
||||
Swig_error("SWIG", Getline(s), "PCRE regex support not enabled in this SWIG build.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1108,7 +1108,7 @@ static int name_regexmatch_value(Node *n, String *pattern, String *s) {
|
|||
Swig_error("SWIG", Getline(n),
|
||||
"Invalid regex \"%s\": compilation failed at %d: %s\n",
|
||||
Char(pattern), errpos, err);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pcre2_match_data *match_data = 0;
|
||||
|
|
@ -1124,7 +1124,7 @@ static int name_regexmatch_value(Node *n, String *pattern, String *s) {
|
|||
Swig_error("SWIG", Getline(n),
|
||||
"Matching \"%s\" against regex \"%s\" failed: %d\n",
|
||||
Char(s), Char(pattern), rc);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
@ -1137,7 +1137,7 @@ static int name_regexmatch_value(Node *n, String *pattern, String *s) {
|
|||
(void)s;
|
||||
Swig_error("SWIG", Getline(n),
|
||||
"PCRE regex matching is not available in this SWIG build.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -833,7 +833,7 @@ static int look(Scanner *s) {
|
|||
return SWIG_TOKEN_MODEQUAL;
|
||||
} else if (c == '}') {
|
||||
Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '%%}'\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
} else {
|
||||
retract(s, 1);
|
||||
return SWIG_TOKEN_PERCENT;
|
||||
|
|
|
|||
|
|
@ -439,8 +439,6 @@ extern int ParmList_is_compactdefargs(ParmList *p);
|
|||
extern void Language_replace_special_variables(String *method, String *tm, Parm *parm);
|
||||
extern void Swig_print(DOH *object, int count);
|
||||
extern void Swig_print_with_location(DOH *object, int count);
|
||||
extern void SWIG_exit(int exit_code);
|
||||
|
||||
|
||||
/* -- template init -- */
|
||||
extern void SwigType_template_init(void);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue