tcc -run file.c : pass original exit code from file.c again

when there are no other errors then exit tcc with the exit cude
from tcc_run() (messed up in dd2e5f8b06)

Also in tccrun.c, use a more exotic random value to replace zero
with 'exit(0)' in user code (because lonhjmp(jb, c) needs c != 0)
This commit is contained in:
grischka 2024-12-13 09:51:32 +01:00
parent b776bfaa53
commit 8620a312b2
2 changed files with 14 additions and 7 deletions

15
tcc.c
View file

@ -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)

View file

@ -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);