for_each_element for all; add tcc_exit_state

this moves the for_each_element macro to tcc.h and adds a
tcc_exit_state (and uses it) pairing with tcc_enter_state.
This commit is contained in:
Michael Matz 2020-05-17 04:18:26 +02:00
parent 1320d85742
commit bbccb13566
3 changed files with 17 additions and 14 deletions

View File

@ -502,6 +502,12 @@ PUB_FUNC void tcc_enter_state(TCCState *s1)
tcc_state = s1;
}
PUB_FUNC void tcc_exit_state(void)
{
tcc_state = NULL;
POST_SEM();
}
static void error1(int mode, const char *fmt, va_list ap)
{
char buf[2048];
@ -513,11 +519,9 @@ static void error1(int mode, const char *fmt, va_list ap)
/* can happen only if called from tcc_malloc(): 'out of memory' */
goto no_file;
if (!s1->error_set_jmp_enabled) {
if (s1 && !s1->error_set_jmp_enabled)
/* tcc_state just was set by tcc_enter_state() */
tcc_state = NULL;
POST_SEM();
}
tcc_exit_state();
if (mode == ERROR_WARN) {
if (s1->warn_none)
@ -684,8 +688,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
Alternatively we could use thread local storage for those global
variables, which may or may not have advantages */
WAIT_SEM();
tcc_state = s1;
tcc_enter_state(s1);
if (setjmp(s1->error_jmp_buf) == 0) {
int is_asm;
@ -722,8 +725,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
preprocess_end(s1);
tccelf_end_file(s1);
tcc_state = NULL;
POST_SEM();
tcc_exit_state();
return s1->nb_errors != 0 ? -1 : 0;
}

7
tcc.h
View File

@ -1544,6 +1544,12 @@ ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, long offs);
/* Browse each elem of type <type> in section <sec> starting at elem <startoff>
using variable <elem> */
#define for_each_elem(sec, startoff, elem, type) \
for (elem = (type *) sec->data + startoff; \
elem < (type *) (sec->data + sec->data_offset); elem++)
#ifndef TCC_TARGET_PE
ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
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)
#define total_bytes TCC_STATE_VAR(total_bytes)
PUB_FUNC void tcc_enter_state(TCCState *s1);
PUB_FUNC void tcc_exit_state(void);
/********************************************************/
#endif /* _TCC_H */

View File

@ -855,12 +855,6 @@ ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc)
return &s1->sym_attrs[index];
}
/* Browse each elem of type <type> in section <sec> starting at elem <startoff>
using variable <elem> */
#define for_each_elem(sec, startoff, elem, type) \
for (elem = (type *) sec->data + startoff; \
elem < (type *) (sec->data + sec->data_offset); elem++)
/* In an ELF file symbol table, the local symbols must appear below
the global and weak ones. Since TCC cannot sort it while generating
the code, we must do it after. All the relocation tables are also