diff options
Diffstat (limited to 'func.c')
-rw-r--r-- | func.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -49,35 +49,44 @@ void luaI_freefunc (TFunc *f) | |||
49 | luaI_free (f); | 49 | luaI_free (f); |
50 | } | 50 | } |
51 | 51 | ||
52 | |||
53 | void luaI_funcfree (TFunc *l) | ||
54 | { | ||
55 | while (l) { | ||
56 | TFunc *next = l->next; | ||
57 | luaI_freefunc(l); | ||
58 | l = next; | ||
59 | } | ||
60 | } | ||
61 | |||
52 | /* | 62 | /* |
53 | ** Garbage collection function. | 63 | ** Garbage collection function. |
54 | ** This function traverse the function list freeing unindexed functions | ||
55 | */ | 64 | */ |
56 | Long luaI_funccollector (void) | 65 | TFunc *luaI_funccollector (long *acum) |
57 | { | 66 | { |
58 | TFunc *curr = function_root; | 67 | TFunc *curr = function_root; |
59 | TFunc *prev = NULL; | 68 | TFunc *prev = NULL; |
60 | Long counter = 0; | 69 | TFunc *frees = NULL; |
61 | while (curr) | 70 | long counter = 0; |
62 | { | 71 | while (curr) { |
63 | TFunc *next = curr->next; | 72 | TFunc *next = curr->next; |
64 | if (!curr->marked) | 73 | if (!curr->marked) { |
65 | { | ||
66 | if (prev == NULL) | 74 | if (prev == NULL) |
67 | function_root = next; | 75 | function_root = next; |
68 | else | 76 | else |
69 | prev->next = next; | 77 | prev->next = next; |
70 | luaI_freefunc (curr); | 78 | curr->next = frees; |
79 | frees = curr; | ||
71 | ++counter; | 80 | ++counter; |
72 | } | 81 | } |
73 | else | 82 | else { |
74 | { | ||
75 | curr->marked = 0; | 83 | curr->marked = 0; |
76 | prev = curr; | 84 | prev = curr; |
77 | } | 85 | } |
78 | curr = next; | 86 | curr = next; |
79 | } | 87 | } |
80 | return counter; | 88 | *acum += counter; |
89 | return frees; | ||
81 | } | 90 | } |
82 | 91 | ||
83 | 92 | ||