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
40ST_DATA Sym *local_label_stack;40ST_DATA Sym *local_label_stack;
41 41
42static int local_scope;42static int local_scope;
43#define SCOPE_TCK_STORE_SIZE 102443#define SCOPE_TCK_STORE_SIZE 512
44ST_DATA ScopeTacker *scope_tracker;44ST_DATA ScopeTacker *scope_tracker;
45static ScopeTacker scope_tck_store[SCOPE_TCK_STORE_SIZE];45static ScopeTacker scope_tck_store[SCOPE_TCK_STORE_SIZE];
46static int scope_tck_idx;46static int scope_tck_store_len;
47
48static ScopeTacker **scope_tck_2nd_store;
49static int scope_tck_2nd_store_len;
47 50
48static int in_sizeof;51static int in_sizeof;
49static int section_sym;52static int section_sym;
@@ -141,15 +144,15 @@ static void incr_local_scope(void) · 91 unmodified lines
141 ScopeTacker *tmp = scope_tracker;144 ScopeTacker *tmp = scope_tracker;
142 145
143 ++local_scope;146 ++local_scope;
144 /* if we have more scopes that SCOPE_TCK_STORE_SIZE */147 if (scope_tck_store_len >= SCOPE_TCK_STORE_SIZE) {
145 /* cleanup will not work at all, but it should be a very rare case */148 scope_tracker = tcc_malloc(sizeof(ScopeTacker));
146 /* and I don't want to add too much complexiy for handeling case */149 dynarray_add(&scope_tck_2nd_store,
147 /* that should not happen */150 &scope_tck_2nd_store_len, scope_tracker);
148 if (scope_tck_idx < SCOPE_TCK_STORE_SIZE) {151 } else {
149 scope_tracker = &scope_tck_store[scope_tck_idx];152 scope_tracker = &scope_tck_store[scope_tck_store_len];
150 scope_tracker->prev = tmp;153 ++scope_tck_store_len;
151 ++scope_tck_idx;
152 }154 }
155 scope_tracker->prev = tmp;
153}156}
154 157
155static void decr_local_scope(void)158static void decr_local_scope(void)
@@ -175,7 +178,9 @@ static void reset_local_scope(void) · 19 unmodified lines
175 }178 }
176 scope_tracker = NULL;179 scope_tracker = NULL;
177 local_scope = 0;180 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);
179}184}
180 185
181int is_scope_a_parent_of(ScopeTacker *parent, ScopeTacker *child)186int 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