diff --git a/tcc.c b/tcc.c index 51a8f816..e396a5d9 100644 --- a/tcc.c +++ b/tcc.c @@ -378,8 +378,9 @@ redo: first_file = f->name; ret = tcc_add_file(s, f->name); } - done = ret || ++n >= s->nb_files; - } while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r)); + } while (++n < s->nb_files + && 0 == ret + && (s->output_type != TCC_OUTPUT_OBJ || s->option_r)); if (s->do_bench) end_time = getclock_ms(); @@ -406,13 +407,17 @@ redo: done = 1; if (t) done = 0; /* run more tests with -dt -run */ - else if (ret) - ret = 1; - else if (n < s->nb_files) + else if (ret) { + if (s->nb_errors) + ret = 1; + /* else keep the original exit code from tcc_run() */ + } else if (n < s->nb_files) done = 0; /* compile more files with -c */ else if (s->do_bench) tcc_print_stats(s, end_time - start_time); + tcc_delete(s); + if (!done) goto redo; if (ppfp && ppfp != stdout) diff --git a/tccrun.c b/tccrun.c index 62b8b2ba..28c7379f 100644 --- a/tccrun.c +++ b/tccrun.c @@ -197,6 +197,8 @@ ST_FUNC void tcc_run_free(TCCState *s1) #endif } +#define RT_EXIT_ZERO 0xE0E00E0E /* passed from longjmp instead of '0' */ + /* launch the compiled program with the given arguments */ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) { @@ -238,7 +240,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) ret = tcc_setjmp(s1, main_jb, tcc_get_symbol(s1, top_sym)); if (0 == ret) ret = prog_main(argc, argv, envp); - else if (256 == ret) + else if (RT_EXIT_ZERO == ret) ret = 0; if (s1->dflag & 16 && ret) /* tcc -dt -run ... */ @@ -596,7 +598,7 @@ static void rt_exit(rt_frame *f, int code) rt_post_sem(); if (s && s->run_lj) { if (code == 0) - code = 256; + code = RT_EXIT_ZERO; ((void(*)(void*,int))s->run_lj)(s->run_jb, code); } exit(code);