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
|
|
@ -537,21 +537,21 @@ void JAVASCRIPT::main(int argc, char *argv[]) {
|
|||
if (strcmp(argv[i], "-v8") == 0) {
|
||||
if (engine != -1) {
|
||||
Printf(stderr, ERR_MSG_ONLY_ONE_ENGINE_PLEASE);
|
||||
SWIG_exit(-1);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
Swig_mark_arg(i);
|
||||
engine = JSEmitter::V8;
|
||||
} else if (strcmp(argv[i], "-jsc") == 0) {
|
||||
if (engine != -1) {
|
||||
Printf(stderr, ERR_MSG_ONLY_ONE_ENGINE_PLEASE);
|
||||
SWIG_exit(-1);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
Swig_mark_arg(i);
|
||||
engine = JSEmitter::JavascriptCore;
|
||||
} else if (strcmp(argv[i], "-node") == 0) {
|
||||
if (engine != -1) {
|
||||
Printf(stderr, ERR_MSG_ONLY_ONE_ENGINE_PLEASE);
|
||||
SWIG_exit(-1);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
Swig_mark_arg(i);
|
||||
engine = JSEmitter::NodeJS;
|
||||
|
|
@ -595,7 +595,7 @@ void JAVASCRIPT::main(int argc, char *argv[]) {
|
|||
default:
|
||||
{
|
||||
Printf(stderr, "SWIG Javascript: Unknown engine. Please specify one of '-jsc', '-v8' or '-node'.\n");
|
||||
SWIG_exit(-1);
|
||||
Exit(EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -666,7 +666,7 @@ Template JSEmitter::getTemplate(const String *name) {
|
|||
|
||||
if (!templ) {
|
||||
Printf(stderr, "Could not find template %s\n.", name);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Template t(templ, name);
|
||||
|
|
@ -1576,7 +1576,7 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
|||
break;
|
||||
default:
|
||||
Printf(stderr, "Illegal MarshallingMode.");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
tm = emitInputTypemap(n, p, wrapper, arg);
|
||||
Delete(arg);
|
||||
|
|
@ -1599,7 +1599,7 @@ int JSCEmitter::initialize(Node *n) {
|
|||
f_wrap_cpp = NewFile(outfile, "w", SWIG_output_files());
|
||||
if (!f_wrap_cpp) {
|
||||
FileErrorDisplay(outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Initialization of members */
|
||||
|
|
@ -1920,7 +1920,7 @@ int V8Emitter::initialize(Node *n) {
|
|||
f_wrap_cpp = NewFile(outfile, "w", SWIG_output_files());
|
||||
if (!f_wrap_cpp) {
|
||||
FileErrorDisplay(outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
f_runtime = NewString("");
|
||||
|
|
@ -2214,7 +2214,7 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
break;
|
||||
default:
|
||||
Printf(stderr, "Illegal MarshallingMode.");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tm = emitInputTypemap(n, p, wrapper, arg);
|
||||
|
|
@ -2370,7 +2370,7 @@ Template::Template(const String *code_) {
|
|||
|
||||
if (!code_) {
|
||||
Printf(stdout, "Template code was null. Illegal input for template.");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
code = NewString(code_);
|
||||
templateName = NewString("");
|
||||
|
|
@ -2380,7 +2380,7 @@ Template::Template(const String *code_, const String *templateName_) {
|
|||
|
||||
if (!code_) {
|
||||
Printf(stdout, "Template code was null. Illegal input for template.");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
code = NewString(code_);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue