Skip to content

Commit

Permalink
tcc -run file.c : pass original exit code from file.c again
Browse files Browse the repository at this point in the history
when there are no other errors then exit tcc with the exit cude
from tcc_run() (messed up in dd2e5f8)

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)
  • Loading branch information
grischka committed Dec 13, 2024
1 parent b776bfa commit 8620a31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions tcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,9 @@ int main(int argc0, char **argv0)
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();
Expand All @@ -406,13 +407,17 @@ int main(int argc0, char **argv0)
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)
Expand Down
6 changes: 4 additions & 2 deletions tccrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ... */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8620a31

Please sign in to comment.