#LIBRARIES = poppler-glib MagickWand libexif taglib_c libmagic libavcodec libavformat sqlite3 uuid fuse3 libbsd-overlay
-LIBRARIES = uuid libedit
+LIBRARIES = libedit
CFLAGS:= -g -Wall `pkg-config $(LIBRARIES) --cflags`
LDFLAGS:= -g -Wall `pkg-config $(LIBRARIES) --libs`
Sexpr* append_to_dict(Sexpr* dict, Sexpr* key, Sexpr* value) {
// assumes dict well-formed, returns new dict
// puts new things on the front of the dict, makes it so looking up gets the newest stuff first
- Sexpr* new = cons(key, clone(value));
+ Sexpr* new = cons(clone(key), clone(value));
// not yet sure if the above 'clone' is needed, or where the call should take place
Sexpr* head = cons(new, car(dict));
dict->value.c->car = head;
// returns nil if not found, returns (result) if it is
Sexpr* node = car(dict);
while(node->type != NIL) {
- if(equal(key, car(car(node)))->type == T) {
+ Sexpr* eq = equal(key, car(car(node)));
+ if(eq->type == T) {
Sexpr* value = clone(cdr(car(node)));
+ sexpr_free(eq);
return cons(value, from_nil());
}
+ sexpr_free(eq);
node = cdr(node);
}
return from_nil();
void test_dict() {
printf("testing dict\n");
+ printf("now with memory leak fixing\n");
Sexpr* d = init_dict();
- d = append_to_dict(d, from_sym("hello"), from_sym("world"));
- d = append_to_dict(d, from_sym("asdf"), from_uint(544));
+ Sexpr* k = from_sym("hello");
+ Sexpr* v = from_sym("world");
+ d = append_to_dict(d, k, v);
+ sexpr_free(k);
+ sexpr_free(v);
+ k = from_sym("asdf");
+ v = from_uint(544);
+ d = append_to_dict(d, k, v);
+ sexpr_free(k);
+ sexpr_free(v);
printf("lookup hello: %s\n", sprint_sexpr(lookup(d, from_sym("hello"))));
printf("lookup asdf: %s\n", sprint_sexpr(lookup(d, from_sym("asdf"))));
+ sexpr_free(d);
+
+
}
void mem_parser() {
sexpr_free(r);
printf("%s\n", out);
free(out);
-
-
-
Sexpr* c = cons_parse(b);
sexpr_free(b);
out = sprint_sexpr(c);
sexpr_free(c);
printf("%s\n", out);
free(out);
+
+ a = from_uint(545);
+ b = from_uint(545);
+ Sexpr* e = equal(a,b);
+ sexpr_free(a);
+ sexpr_free(b);
+ sexpr_free(e);
+ a = from_sym("hi");
+ b = from_sym("hi");
+ e = equal(a,b);
+ sexpr_free(a);
+ sexpr_free(b);
+ sexpr_free(e);
+}
+
+void memtest_dict() {
+ printf("memtest dict\n");
+ Sexpr* d = init_dict();
+
+ Sexpr* k = from_sym("hello");
+ Sexpr* v = from_sym("world");
+ d = append_to_dict(d, k, v);
+ sexpr_free(k);
+ sexpr_free(v);
+ k = from_sym("asdf");
+ v = from_uint(454);
+ d = append_to_dict(d, k, v);
+ sexpr_free(k);
+ sexpr_free(v);
+ k = from_sym("hello");
+ v = lookup(d, k);
+ char* out = sprint_sexpr(v);
+ printf("lookup hello: %s\n", out);
+ free(out);
+ sexpr_free(k);
+ sexpr_free(v);
+ k = from_sym("asdf");
+ v = lookup(d, k);
+ out = sprint_sexpr(v);
+ printf("lookup hello: %s\n", out);
+ free(out);
+ sexpr_free(k);
+ sexpr_free(v);
+
+ sexpr_free(d);
}
void run_tests(){
- mem_testing();
- mem_parser();
+ //mem_testing();
+ //mem_parser();
+ memtest_dict();
//mem_hammer();
//test_basics();
//test2();