comparison 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
comparison
equal deleted inserted replaced
118:b3f56e1d54a0 119:72c648bca43b
396 { 396 {
397 ,notfound <- [[reg]Definitions >>]Index[name] 397 ,notfound <- [[reg]Definitions >>]Index[name]
398 { 398 {
399 yep,nope <- If[[[[~]Fields >>]Length] = [1]] 399 yep,nope <- If[[[[~]Fields >>]Length] = [1]]
400 } 400 }
401 }
402
403 Defined?@C Type Registry[reg,name:yep,nope]
404 {
405 yep,nope <- [[reg]Definitions >>]Index[name]
401 } 406 }
402 407
403 Blueprint C Function 408 Blueprint C Function
404 { 409 {
405 Name 410 Name
1455 ]Append["EndMethod("] 1460 ]Append["EndMethod("]
1456 ]Append[Escape Rhope Name[method]] 1461 ]Append[Escape Rhope Name[method]]
1457 ]Append[")\n\n"] 1462 ]Append[")\n\n"]
1458 } 1463 }
1459 1464
1465 Init Type Names[text,typeid,name,reg:out]
1466 {
1467 [reg]Defined?[name]
1468 { out <- [text]Append[ [[[["\tregistered_types["]Append[typeid]]Append["]->name = "]]Append[Const Construct C[name, reg]]]Append[";\n"] ] }
1469 { out <- text }
1470 }
1471
1460 Text@C Program[program:out] 1472 Text@C Program[program:out]
1461 { 1473 {
1462 type defs <- [[program]Type Registry >>]Definitions >> 1474 type defs <- [[program]Type Registry >>]Definitions >>
1463 constants <- Fold["Combine Consts", Dictionary[], [program]Functions >>] 1475 constants <- Fold["Combine Consts", Dictionary[], [program]Functions >>]
1464 all methods <- Fold["Field to Types", Fold["Method to Types", Dictionary[], type defs], type defs] 1476 all methods <- Fold["Field to Types", Fold["Method to Types", Dictionary[], type defs], type defs]
1472 #include \"blueprint.h\" 1484 #include \"blueprint.h\"
1473 #include \"array.h\" 1485 #include \"array.h\"
1474 #include \"worker.h\" 1486 #include \"worker.h\"
1475 #include \"bool.h\" 1487 #include \"bool.h\"
1476 #include <sys/time.h>\n\n" 1488 #include <sys/time.h>\n\n"
1477 out <- [[[[[[[[[[[[[[[[[headers 1489 out <- [[[[[[[[[[[[[[[[[[headers
1478 ]Append[[program]Dispatch[all methods]] 1490 ]Append[[program]Dispatch[all methods]]
1479 ]Append[[[program]Type Registry >>]Type Defs] 1491 ]Append[[[program]Type Registry >>]Type Defs]
1480 ]Append[Fold["_Consts C Program", 1492 ]Append[Fold["_Consts C Program",
1481 Fold["_Defs C Program", "", [program]Functions >>], 1493 Fold["_Defs C Program", "", [program]Functions >>],
1482 constants]] 1494 constants]]
1588 #include \"worker.c\" 1600 #include \"worker.c\"
1589 1601
1590 int main(int argc, char **argv) 1602 int main(int argc, char **argv)
1591 { 1603 {
1592 blueprint * bp; 1604 blueprint * bp;
1593 int numret; 1605 int numret,retval;
1594 int idx; 1606 int idx,sidx;
1595 object * inout[3]; 1607 object * inout[3];
1608 int32_t *counts, string_type_id=0;
1609 t_String ** live_strings;
1610 char ** typenames;
1611 t_Array * typename;
1596 register_builtin_types();\n\n"] 1612 register_builtin_types();\n\n"]
1597 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] 1613 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
1598 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] 1614 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]]
1599 ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]] 1615 ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]]
1616 ]Append[Fold[["Init Type Names"]Set Input[3, [program]Type Registry >>], "", [[program]Type Registry >>]Lookup >>]]
1600 ]Append[" 1617 ]Append["
1601 rhope(FUNC_List, inout, 0, 1); 1618 rhope(FUNC_List, inout, 0, 1);
1602 for (idx = 0; idx < argc; ++idx) 1619 for (idx = 0; idx < argc; ++idx)
1603 { 1620 {
1604 inout[1] = make_String(argv[idx]); 1621 inout[1] = make_String(argv[idx]);
1606 } 1623 }
1607 numret = rhope(FUNC_Main, inout, 1, 1);"] 1624 numret = rhope(FUNC_Main, inout, 1, 1);"]
1608 ]Append[Fold["_Consts C Release", "", constants]] 1625 ]Append[Fold["_Consts C Release", "", constants]]
1609 ]Append[ 1626 ]Append[
1610 " 1627 "
1628 if (!numret)
1629 retval = 0;
1630 else if (numret < 0)
1631 retval = numret;
1632 else if (get_blueprint(inout[0])->type_id == TYPE_INT32)
1633 {
1634 retval = ((t_Int32 *)inout[0])->Num;
1635 release_ref(inout[0]);
1636 } else {
1637 rhope(FUNC_If, inout, 1, 2);
1638 if (inout[0])
1639 {
1640 retval = 0;
1641 release_ref(inout[0]);
1642 } else {
1643 retval = 1;
1644 release_ref(inout[1]);
1645 }
1646 }
1647 typenames = malloc(sizeof(char *)*max_registered_type);
1648 for(idx = 0; idx < max_registered_type; ++idx)
1649 {
1650 if(registered_types[idx])
1651 {
1652 typename = (t_Array *)( ((t_String *)registered_types[idx]->name)->payload.Buffer );
1653 typenames[idx] = malloc(typename->payload.Length+1);
1654 memcpy(typenames[idx], typename+1, typename->payload.Length);
1655 typenames[idx][typename->payload.Length] = 0;
1656 if(!strcmp(typenames[idx], \"String\"))
1657 string_type_id = idx;
1658 release_ref(registered_types[idx]->name);
1659 } else {
1660 typenames[idx] = NULL;
1661 }
1662 }
1663
1611 print_mem_info(manager); 1664 print_mem_info(manager);
1612 print_live_object_types(manager); 1665 counts = malloc(sizeof(int32_t)*max_registered_type);
1666 get_live_object_counts(manager, counts);
1667 for(idx = 0; idx < max_registered_type; ++idx)
1668 {
1669 if(counts[idx])
1670 {
1671 printf(\"%d objects of type %s (%d)\\n\", counts[idx], typenames[idx], idx);
1672 if(idx == string_type_id)
1673 {
1674 live_strings = malloc(sizeof(t_String *)*counts[idx]);
1675 find_live_objects_oftype(manager, string_type_id, (void **)live_strings);
1676 for(sidx = 0; sidx < counts[idx]; ++sidx)
1677 {
1678 printf(\"\t%d: \", sidx);
1679 fwrite(((t_Array *)live_strings[sidx]->payload.Buffer)+1, 1, ((t_Array *)live_strings[sidx]->payload.Buffer)->payload.Length, stdout);
1680 puts(\"\");
1681 }
1682 }
1683 }
1684 }
1685 fflush(stdout);
1613 1686
1614 #ifdef ENABLE_PROFILING 1687 #ifdef ENABLE_PROFILING
1615 for (idx = 0; idx < END; ++idx) 1688 for (idx = 0; idx < END; ++idx)
1616 { 1689 {
1617 if(profile_counts[idx]) 1690 if(profile_counts[idx])
1618 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]); 1691 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]);
1619 } 1692 }
1620 #endif 1693 #endif
1621 if (!numret) 1694 return retval;
1622 return 0;
1623 if (numret < 0)
1624 return numret;
1625 if (get_blueprint(inout[0])->type_id == TYPE_INT32)
1626 return ((t_Int32 *)inout[0])->Num;
1627
1628 rhope(FUNC_If, inout, 1, 2);
1629 if (inout[0])
1630 return 0;
1631 return 1;
1632 }\n\n"] 1695 }\n\n"]
1633 1696
1634 } 1697 }
1635 1698
1636 1699