Permalink
Browse files

Destroy functions

  • Loading branch information...
Josep M. Bach
Josep M. Bach committed Mar 3, 2013
1 parent 1b9b4d6 commit a025a088c53b23d2b83e5b90180a2e7212cdc369
Showing with 20 additions and 6 deletions.
  1. +17 −1 src/terror/input_reader.c
  2. +1 −0 src/terror/primitives.c
  3. +1 −1 src/terror/vm.c
  4. +0 −2 tests/gc_tests.c
  5. +1 −2 tests/vm_tests.c
View
@@ -57,7 +57,7 @@ parse_string(STATE, bstring buf, BytecodeFile *file)
bstring strData = bmidstr(*line, 1, (*line)->mlen);
// TODO: This causes a leak in the string literals because they are
// never freed on destruction.
- DArray_push(literals, String_new(state, bdata(bstrcpy(strData))));
+ DArray_push(literals, String_new(state, bdata(strData)));
bdestroy(strData);
} else {
DArray_push(literals, Number_new(state, atof(bdata(*line))));
@@ -111,6 +111,22 @@ BytecodeFile_destroy(BytecodeFile *file)
if(file->filename) bdestroy(file->filename);
if(file->compiled_filename) bdestroy(file->compiled_filename);
+ /* DArray *names = file->function_names; */
+ /* int count = DArray_count(names); */
+ /* void *destroyed[count]; */
+
+ /* for(int i=0; i < DArray_count(names); i++) { */
+ /* bstring name = (bstring)DArray_at(names, i); */
+ /* Function *fn = (Function*)Hashmap_get(file->functions, name); */
+ /* int already_destroyed = 0; */
+ /* for(int j=0; j < count; j++) { */
+ /* if (destroyed[i] == (void*)fn) { */
+ /* already_destroyed = 1; */
+ /* break; */
+ /* } */
+ /* } */
+ /* if(!already_destroyed) Function_destroy(fn); */
+ /* } */
Hashmap_traverse(file->functions, Hashmap_Function_destroy);
Hashmap_destroy(file->functions);
View
@@ -143,6 +143,7 @@ Primitive_require(STATE, void *a, void *_, void *__)
if(bstrcmp(fn_name, main_name) == 0) {
main = fn;
} else {
+ debug("Hashmap_set %s", bdata(fn_name));
Hashmap_set(state->functions, fn_name, fn);
}
bdestroy(main_name);
View
@@ -230,7 +230,7 @@ VALUE VM_run(STATE)
VALUE name = LITERAL(op1);
int argcount = op2;
- DArray *locals = DArray_create(sizeof(VALUE), argcount);
+ DArray *locals = DArray_create(sizeof(VALUE), argcount+1);
while(argcount--) {
DArray_push(locals, Stack_pop(STACK));
}
View
@@ -21,8 +21,6 @@ VALUE NilObject;
State_bootstrap(state); \
#define TEARDOWN() \
- Hashmap_traverse(fns, Hashmap_Function_destroy); \
- Hashmap_destroy(fns); \
State_destroy(state); \
return NULL; \
View
@@ -31,8 +31,7 @@ VALUE NilObject;
Runtime_init(state); \
#define TEARDOWN() \
- Hashmap_traverse(fns, Hashmap_Function_destroy); \
- Hashmap_destroy(fns); \
+ Function_destroy(fn); \
State_destroy(state); \
return NULL; \

0 comments on commit a025a08

Please sign in to comment.