History

Fix some races

protect some more accesses to global data with the semaphore. (And for the testcase: don't just write into global data, use local copies; it's not important for speed here).

Michael Matz committed 6 years ago

Commit 2fb79a61 parent 65f74a42 files · +9 −3Browse files

Unified · Split

2 files
  1. libtcc.c +4 −0
  2. tests/libtcc_test_mt.c +5 −3
libtcc.c+4−0
@@ -749,7 +749,9 @@ LIBTCCAPI TCCState *tcc_new(void) · 748 unmodified lines
749 s = tcc_mallocz(sizeof(TCCState));749 s = tcc_mallocz(sizeof(TCCState));
750 if (!s)750 if (!s)
751 return NULL;751 return NULL;
752 WAIT_SEM();
752 ++nb_states;753 ++nb_states;
754 POST_SEM();
753 755
754#undef gnu_ext756#undef gnu_ext
755 757
@@ -958,8 +960,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 202 unmodified lines
958#endif960#endif
959 961
960 tcc_free(s1);962 tcc_free(s1);
963 WAIT_SEM();
961 if (0 == --nb_states)964 if (0 == --nb_states)
962 tcc_memcheck();965 tcc_memcheck();
966 POST_SEM();
963}967}
964 968
965LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)969LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
tests/libtcc_test_mt.c+5−3
@@ -105,13 +105,15 @@ void parse_args(TCCState *s) · 104 unmodified lines
105 else if (a[1] == 'L')105 else if (a[1] == 'L')
106 tcc_add_library_path(s, a+2);106 tcc_add_library_path(s, a+2);
107 else if (a[1] == 'D') {107 else if (a[1] == 'D') {
108 char *eq = strchr(a+2, '=');108 char *dup = strdup(a);
109 char *eq = strchr(dup+2, '=');
109 if (eq) {110 if (eq) {
110 *eq = 0;111 *eq = 0;
111 tcc_define_symbol(s, a+2, eq+1);112 tcc_define_symbol(s, dup+2, eq+1);
112 *eq = '=';113 *eq = '=';
113 } else114 } else
114 tcc_define_symbol(s, a+2, NULL);115 tcc_define_symbol(s, dup+2, NULL);
116 free(dup);
115 }117 }
116 }118 }
117 }119 }

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