History

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.

Michael Matz committed 6 years ago

Commit bbccb131 parent 1320d853 files · +17 −14Browse files

Unified · Split

3 files
  1. libtcc.c +10 −8
  2. tcc.h +7 −0
  3. tccelf.c +0 −6
libtcc.c+10−8
@@ -502,6 +502,12 @@ PUB_FUNC void tcc_enter_state(TCCState *s1) · 501 unmodified lines
502502 tcc_state = s1;
503503 }
504504
505+PUB_FUNC void tcc_exit_state(void)
506+{
507+ tcc_state = NULL;
508+ POST_SEM();
509+}
510+
505511 static void error1(int mode, const char *fmt, va_list ap)
506512 {
507513 char buf[2048];
@@ -513,11 +519,9 @@ static void error1(int mode, const char *fmt, va_list ap) · 5 unmodified lines
513519 /* can happen only if called from tcc_malloc(): 'out of memory' */
514520 goto no_file;
515521
516− if (!s1->error_set_jmp_enabled) {
522+ if (s1 && !s1->error_set_jmp_enabled)
517523 /* tcc_state just was set by tcc_enter_state() */
518− tcc_state = NULL;
519− POST_SEM();
520− }
524+ tcc_exit_state();
521525
522526 if (mode == ERROR_WARN) {
523527 if (s1->warn_none)
@@ -684,8 +688,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 160 unmodified lines
684688 Alternatively we could use thread local storage for those global
685689 variables, which may or may not have advantages */
686690
687− WAIT_SEM();
688− tcc_state = s1;
691+ tcc_enter_state(s1);
689692
690693 if (setjmp(s1->error_jmp_buf) == 0) {
691694 int is_asm;
@@ -722,8 +725,7 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 30 unmodified lines
722725 preprocess_end(s1);
723726 tccelf_end_file(s1);
724727
725− tcc_state = NULL;
726− POST_SEM();
728+ tcc_exit_state();
727729 return s1->nb_errors != 0 ? -1 : 0;
728730 }
729731
tcc.h+7−0
@@ -1544,6 +1544,12 @@ ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name); · 1543 unmodified lines
15441544
15451545 ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, long offs);
15461546
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+
15471553 #ifndef TCC_TARGET_PE
15481554 ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
15491555 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
17891795 #define total_bytes TCC_STATE_VAR(total_bytes)
17901796
17911797 PUB_FUNC void tcc_enter_state(TCCState *s1);
1798+PUB_FUNC void tcc_exit_state(void);
17921799
17931800 /********************************************************/
17941801 #endif /* _TCC_H */
tccelf.c+0−6
@@ -855,12 +855,6 @@ ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc) · 854 unmodified lines
855855 return &s1->sym_attrs[index];
856856 }
857857
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−
864858 /* In an ELF file symbol table, the local symbols must appear below
865859 the global and weak ones. Since TCC cannot sort it while generating
866860 the code, we must do it after. All the relocation tables are also

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t