History

Fix scope limit for cleanup attribute

old implementation use only a global static array for storing ScopeTracker which have the advantage to be fast, but you can't use cleanup in a function that have move than SCOPE_TCK_STORE_SIZE scopes. I don't want to use only dynarray_* as it would slow down tcc for every functions, so I keep both stores.

matthias committed 7 years ago

Commit 26f0cf01 parent ff38d901 file · +16 −11Browse files

Unified · Split

tccgen.c+16−11
@@ -40,10 +40,13 @@ ST_DATA Sym *global_label_stack; · 39 unmodified lines
4040 ST_DATA Sym *local_label_stack;
4141
4242 static int local_scope;
43−#define SCOPE_TCK_STORE_SIZE 1024
43+#define SCOPE_TCK_STORE_SIZE 512
4444 ST_DATA ScopeTacker *scope_tracker;
4545 static ScopeTacker scope_tck_store[SCOPE_TCK_STORE_SIZE];
46−static int scope_tck_idx;
46+static int scope_tck_store_len;
47+
48+static ScopeTacker **scope_tck_2nd_store;
49+static int scope_tck_2nd_store_len;
4750
4851 static int in_sizeof;
4952 static int section_sym;
@@ -141,15 +144,15 @@ static void incr_local_scope(void) · 91 unmodified lines
141144 ScopeTacker *tmp = scope_tracker;
142145
143146 ++local_scope;
144− /* if we have more scopes that SCOPE_TCK_STORE_SIZE */
145− /* cleanup will not work at all, but it should be a very rare case */
146− /* and I don't want to add too much complexiy for handeling case */
147− /* that should not happen */
148− if (scope_tck_idx < SCOPE_TCK_STORE_SIZE) {
149− scope_tracker = &scope_tck_store[scope_tck_idx];
150− scope_tracker->prev = tmp;
151− ++scope_tck_idx;
147+ if (scope_tck_store_len >= SCOPE_TCK_STORE_SIZE) {
148+ scope_tracker = tcc_malloc(sizeof(ScopeTacker));
149+ dynarray_add(&scope_tck_2nd_store,
150+ &scope_tck_2nd_store_len, scope_tracker);
151+ } else {
152+ scope_tracker = &scope_tck_store[scope_tck_store_len];
153+ ++scope_tck_store_len;
152154 }
155+ scope_tracker->prev = tmp;
153156 }
154157
155158 static void decr_local_scope(void)
@@ -175,7 +178,9 @@ static void reset_local_scope(void) · 19 unmodified lines
175178 }
176179 scope_tracker = NULL;
177180 local_scope = 0;
178− scope_tck_idx = 0;
181+ scope_tck_store_len = 0;
182+ if (scope_tck_2nd_store_len)
183+ dynarray_reset(&scope_tck_2nd_store, &scope_tck_2nd_store_len);
179184 }
180185
181186 int is_scope_a_parent_of(ScopeTacker *parent, ScopeTacker *child)

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