comparison src/lru_cache.sml @ 2296:5104e480b3e3

Fix a few C memory bugs
author Adam Chlipala <adam@chlipala.net>
date Thu, 19 Nov 2015 10:31:47 -0500
parents 78820fa8f5a7
children 6d56080f495c
comparison
equal deleted inserted replaced
2295:e6c5bb62fef8 2296:5104e480b3e3
109 string (" uw_Sqlcache_Value *v = uw_Sqlcache_check(ctx, cache" ^ i ^ ", ks);"), 109 string (" uw_Sqlcache_Value *v = uw_Sqlcache_check(ctx, cache" ^ i ^ ", ks);"),
110 newline, 110 newline,
111 (* If the output is null, it means we had too much recursion, so it's a miss. *) 111 (* If the output is null, it means we had too much recursion, so it's a miss. *)
112 string " if (v && v->output != NULL) {", 112 string " if (v && v->output != NULL) {",
113 newline, 113 newline,
114 (* string (" puts(\"SQLCACHE: hit " ^ i ^ ".\");"), *) 114 (*string (" puts(\"SQLCACHE: hit " ^ i ^ ".\");"),
115 (* newline, *) 115 newline,*)
116 string " uw_write(ctx, v->output);", 116 string " uw_write(ctx, v->output);",
117 newline, 117 newline,
118 string " return v->result;", 118 string " return v->result;",
119 newline, 119 newline,
120 string " } else {", 120 string " } else {",
121 newline, 121 newline,
122 (* string (" puts(\"SQLCACHE: miss " ^ i ^ ".\");"), *) 122 (*string (" puts(\"SQLCACHE: miss " ^ i ^ ".\");"),
123 (* newline, *) 123 newline,*)
124 string " uw_recordingStart(ctx);", 124 string " uw_recordingStart(ctx);",
125 newline, 125 newline,
126 string " return NULL;", 126 string " return NULL;",
127 newline, 127 newline,
128 string " }", 128 string " }",
134 string ("static uw_unit uw_Sqlcache_store" ^ i), 134 string ("static uw_unit uw_Sqlcache_store" ^ i),
135 string ("(uw_context ctx, uw_Basis_string s" ^ typedArgs ^ ") {"), 135 string ("(uw_context ctx, uw_Basis_string s" ^ typedArgs ^ ") {"),
136 newline, 136 newline,
137 string (" char *ks[] = {" ^ revArgs ^ "};"), 137 string (" char *ks[] = {" ^ revArgs ^ "};"),
138 newline, 138 newline,
139 string (" uw_Sqlcache_Value *v = malloc(sizeof(uw_Sqlcache_Value));"), 139 string (" uw_Sqlcache_Value *v = calloc(1, sizeof(uw_Sqlcache_Value));"),
140 newline, 140 newline,
141 string " v->result = strdup(s);", 141 string " v->result = strdup(s);",
142 newline, 142 newline,
143 string " v->output = uw_recordingRead(ctx);", 143 string " v->output = uw_recordingRead(ctx);",
144 newline, 144 newline,
145 (* string (" puts(\"SQLCACHE: stored " ^ i ^ ".\");"), *) 145 string " v->timeValid = 0;",
146 (* newline, *) 146 newline,
147 (*string (" puts(\"SQLCACHE: stored " ^ i ^ ".\");"),
148 newline,*)
147 string (" uw_Sqlcache_store(ctx, cache" ^ i ^ ", ks, v);"), 149 string (" uw_Sqlcache_store(ctx, cache" ^ i ^ ", ks, v);"),
148 newline, 150 newline,
149 string " return uw_unit_v;", 151 string " return uw_unit_v;",
150 newline, 152 newline,
151 string "}", 153 string "}",