this moves the for_each_element macro to tcc.h and adds a tcc_exit_state (and uses it) pairing with tcc_enter_state.
Unified · Split
| @@ -502,6 +502,12 @@ PUB_FUNC void tcc_enter_state(TCCState *s1) · 501 unmodified lines | ||
| 502 | 502 | tcc_state = s1; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | +PUB_FUNC void tcc_exit_state(void) | |
| 506 | +{ | |
| 507 | + tcc_state = NULL; | |
| 508 | + POST_SEM(); | |
| 509 | +} | |
| 510 | + | |
| 505 | 511 | static void error1(int mode, const char *fmt, va_list ap) |
| 506 | 512 | { |
| 507 | 513 | char buf[2048]; |
| @@ -513,11 +519,9 @@ static void error1(int mode, const char *fmt, va_list ap) · 5 unmodified lines | ||
| 513 | 519 | /* can happen only if called from tcc_malloc(): 'out of memory' */ |
| 514 | 520 | goto no_file; |
| 515 | 521 | |
| 516 | − if (!s1->error_set_jmp_enabled) { | |
| 522 | + if (s1 && !s1->error_set_jmp_enabled) | |
| 517 | 523 | /* tcc_state just was set by tcc_enter_state() */ |
| 518 | − tcc_state = NULL; | |
| 519 | − POST_SEM(); | |
| 520 | − } | |
| 524 | + tcc_exit_state(); | |
| 521 | 525 | |
| 522 | 526 | if (mode == ERROR_WARN) { |
| 523 | 527 | if (s1->warn_none) |
| @@ -684,8 +688,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 160 unmodified lines | ||
| 684 | 688 | Alternatively we could use thread local storage for those global |
| 685 | 689 | variables, which may or may not have advantages */ |
| 686 | 690 | |
| 687 | − WAIT_SEM(); | |
| 688 | − tcc_state = s1; | |
| 691 | + tcc_enter_state(s1); | |
| 689 | 692 | |
| 690 | 693 | if (setjmp(s1->error_jmp_buf) == 0) { |
| 691 | 694 | int is_asm; |
| @@ -722,8 +725,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 30 unmodified lines | ||
| 722 | 725 | preprocess_end(s1); |
| 723 | 726 | tccelf_end_file(s1); |
| 724 | 727 | |
| 725 | − tcc_state = NULL; | |
| 726 | − POST_SEM(); | |
| 728 | + tcc_exit_state(); | |
| 727 | 729 | return s1->nb_errors != 0 ? -1 : 0; |
| 728 | 730 | } |
| 729 | 731 | |
| @@ -1544,6 +1544,12 @@ ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name); · 1543 unmodified lines | ||
| 1544 | 1544 | |
| 1545 | 1545 | ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, long offs); |
| 1546 | 1546 | |
| 1547 | +/* Browse each elem of type <type> in section <sec> starting at elem <startoff> | |
| 1548 | + using variable <elem> */ | |
| 1549 | +#define for_each_elem(sec, startoff, elem, type) \ | |
| 1550 | + for (elem = (type *) sec->data + startoff; \ | |
| 1551 | + elem < (type *) (sec->data + sec->data_offset); elem++) | |
| 1552 | + | |
| 1547 | 1553 | #ifndef TCC_TARGET_PE |
| 1548 | 1554 | ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level); |
| 1549 | 1555 | ST_FUNC int tcc_load_ldscript(TCCState *s1, int fd); |
| @@ -1789,6 +1795,7 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename) · 239 unmodified lines | ||
| 1789 | 1795 | #define total_bytes TCC_STATE_VAR(total_bytes) |
| 1790 | 1796 | |
| 1791 | 1797 | PUB_FUNC void tcc_enter_state(TCCState *s1); |
| 1798 | +PUB_FUNC void tcc_exit_state(void); | |
| 1792 | 1799 | |
| 1793 | 1800 | /********************************************************/ |
| 1794 | 1801 | #endif /* _TCC_H */ |
| @@ -855,12 +855,6 @@ ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc) · 854 unmodified lines | ||
| 855 | 855 | return &s1->sym_attrs[index]; |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | −/* Browse each elem of type <type> in section <sec> starting at elem <startoff> | |
| 859 | − using variable <elem> */ | |
| 860 | −#define for_each_elem(sec, startoff, elem, type) \ | |
| 861 | − for (elem = (type *) sec->data + startoff; \ | |
| 862 | − elem < (type *) (sec->data + sec->data_offset); elem++) | |
| 863 | − | |
| 864 | 858 | /* In an ELF file symbol table, the local symbols must appear below |
| 865 | 859 | the global and weak ones. Since TCC cannot sort it while generating |
| 866 | 860 | the code, we must do it after. All the relocation tables are also |