Mercurial > repos > rhope
diff cbackend.rhope @ 119:72c648bca43b
Improved memory debug output and fixed memory leak in Array
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 18 Oct 2010 00:50:18 -0400 |
parents | 60906f8803ef |
children |
line wrap: on
line diff
--- a/cbackend.rhope Fri Oct 15 00:55:02 2010 -0400 +++ b/cbackend.rhope Mon Oct 18 00:50:18 2010 -0400 @@ -400,6 +400,11 @@ } } +Defined?@C Type Registry[reg,name:yep,nope] +{ + yep,nope <- [[reg]Definitions >>]Index[name] +} + Blueprint C Function { Name @@ -1457,6 +1462,13 @@ ]Append[")\n\n"] } +Init Type Names[text,typeid,name,reg:out] +{ + [reg]Defined?[name] + { out <- [text]Append[ [[[["\tregistered_types["]Append[typeid]]Append["]->name = "]]Append[Const Construct C[name, reg]]]Append[";\n"] ] } + { out <- text } +} + Text@C Program[program:out] { type defs <- [[program]Type Registry >>]Definitions >> @@ -1474,7 +1486,7 @@ #include \"worker.h\" #include \"bool.h\" #include <sys/time.h>\n\n" - out <- [[[[[[[[[[[[[[[[[headers + out <- [[[[[[[[[[[[[[[[[[headers ]Append[[program]Dispatch[all methods]] ]Append[[[program]Type Registry >>]Type Defs] ]Append[Fold["_Consts C Program", @@ -1590,13 +1602,18 @@ int main(int argc, char **argv) { blueprint * bp; - int numret; - int idx; + int numret,retval; + int idx,sidx; object * inout[3]; + int32_t *counts, string_type_id=0; + t_String ** live_strings; + char ** typenames; + t_Array * typename; register_builtin_types();\n\n"] ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]] + ]Append[Fold[["Init Type Names"]Set Input[3, [program]Type Registry >>], "", [[program]Type Registry >>]Lookup >>]] ]Append[" rhope(FUNC_List, inout, 0, 1); for (idx = 0; idx < argc; ++idx) @@ -1608,8 +1625,64 @@ ]Append[Fold["_Consts C Release", "", constants]] ]Append[ " + if (!numret) + retval = 0; + else if (numret < 0) + retval = numret; + else if (get_blueprint(inout[0])->type_id == TYPE_INT32) + { + retval = ((t_Int32 *)inout[0])->Num; + release_ref(inout[0]); + } else { + rhope(FUNC_If, inout, 1, 2); + if (inout[0]) + { + retval = 0; + release_ref(inout[0]); + } else { + retval = 1; + release_ref(inout[1]); + } + } + typenames = malloc(sizeof(char *)*max_registered_type); + for(idx = 0; idx < max_registered_type; ++idx) + { + if(registered_types[idx]) + { + typename = (t_Array *)( ((t_String *)registered_types[idx]->name)->payload.Buffer ); + typenames[idx] = malloc(typename->payload.Length+1); + memcpy(typenames[idx], typename+1, typename->payload.Length); + typenames[idx][typename->payload.Length] = 0; + if(!strcmp(typenames[idx], \"String\")) + string_type_id = idx; + release_ref(registered_types[idx]->name); + } else { + typenames[idx] = NULL; + } + } + print_mem_info(manager); - print_live_object_types(manager); + counts = malloc(sizeof(int32_t)*max_registered_type); + get_live_object_counts(manager, counts); + for(idx = 0; idx < max_registered_type; ++idx) + { + if(counts[idx]) + { + printf(\"%d objects of type %s (%d)\\n\", counts[idx], typenames[idx], idx); + if(idx == string_type_id) + { + live_strings = malloc(sizeof(t_String *)*counts[idx]); + find_live_objects_oftype(manager, string_type_id, (void **)live_strings); + for(sidx = 0; sidx < counts[idx]; ++sidx) + { + printf(\"\t%d: \", sidx); + fwrite(((t_Array *)live_strings[sidx]->payload.Buffer)+1, 1, ((t_Array *)live_strings[sidx]->payload.Buffer)->payload.Length, stdout); + puts(\"\"); + } + } + } + } + fflush(stdout); #ifdef ENABLE_PROFILING for (idx = 0; idx < END; ++idx) @@ -1618,17 +1691,7 @@ printf(\"Func: %d\tCount: %llu\tTime: %llu\tAvg: %f\tSelf: %llu\tAvg: %f\tNested Count: %llu\\n\", idx, profile_counts[idx], profile_totals[idx], ((double)profile_totals[idx])/((double)profile_counts[idx]), profile_selftotals[idx], ((double)profile_selftotals[idx])/((double)profile_counts[idx]), profile_nestedcounts[idx]); } #endif - if (!numret) - return 0; - if (numret < 0) - return numret; - if (get_blueprint(inout[0])->type_id == TYPE_INT32) - return ((t_Int32 *)inout[0])->Num; - - rhope(FUNC_If, inout, 1, 2); - if (inout[0]) - return 0; - return 1; + return retval; }\n\n"] }