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:
parent
1320d85742
commit
bbccb13566
3 changed files with 17 additions and 14 deletions
18
libtcc.c
18
libtcc.c
|
@ -502,6 +502,12 @@ PUB_FUNC void tcc_enter_state(TCCState *s1)
|
||||||
tcc_state = 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)
|
static void error1(int mode, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char buf[2048];
|
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' */
|
/* can happen only if called from tcc_malloc(): 'out of memory' */
|
||||||
goto no_file;
|
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 just was set by tcc_enter_state() */
|
||||||
tcc_state = NULL;
|
tcc_exit_state();
|
||||||
POST_SEM();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == ERROR_WARN) {
|
if (mode == ERROR_WARN) {
|
||||||
if (s1->warn_none)
|
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
|
Alternatively we could use thread local storage for those global
|
||||||
variables, which may or may not have advantages */
|
variables, which may or may not have advantages */
|
||||||
|
|
||||||
WAIT_SEM();
|
tcc_enter_state(s1);
|
||||||
tcc_state = s1;
|
|
||||||
|
|
||||||
if (setjmp(s1->error_jmp_buf) == 0) {
|
if (setjmp(s1->error_jmp_buf) == 0) {
|
||||||
int is_asm;
|
int is_asm;
|
||||||
|
@ -722,8 +725,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
|
||||||
preprocess_end(s1);
|
preprocess_end(s1);
|
||||||
tccelf_end_file(s1);
|
tccelf_end_file(s1);
|
||||||
|
|
||||||
tcc_state = NULL;
|
tcc_exit_state();
|
||||||
POST_SEM();
|
|
||||||
return s1->nb_errors != 0 ? -1 : 0;
|
return s1->nb_errors != 0 ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
tcc.h
7
tcc.h
|
@ -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);
|
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
|
#ifndef TCC_TARGET_PE
|
||||||
ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
|
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);
|
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)
|
#define total_bytes TCC_STATE_VAR(total_bytes)
|
||||||
|
|
||||||
PUB_FUNC void tcc_enter_state(TCCState *s1);
|
PUB_FUNC void tcc_enter_state(TCCState *s1);
|
||||||
|
PUB_FUNC void tcc_exit_state(void);
|
||||||
|
|
||||||
/********************************************************/
|
/********************************************************/
|
||||||
#endif /* _TCC_H */
|
#endif /* _TCC_H */
|
||||||
|
|
6
tccelf.c
6
tccelf.c
|
@ -855,12 +855,6 @@ ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc)
|
||||||
return &s1->sym_attrs[index];
|
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
|
/* 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 global and weak ones. Since TCC cannot sort it while generating
|
||||||
the code, we must do it after. All the relocation tables are also
|
the code, we must do it after. All the relocation tables are also
|
||||||
|
|
Loading…
Reference in a new issue