array test_cs142 integer test_count208 array C_nextFree155 integer C_firstFree791 integer C_maxIndex156 array C_typeId602 array C_alive130 integer test_count208 = 0 integer C_firstFree791 = 0 integer C_maxIndex156 = 0 function initGlobals353() { } function main193() { initGlobals353(); init_test177(); } function config192() { } function init_test177() { local integer i990 local integer j129 test_count_208 = 0; i_990 = 0; loop { exitwhen (i_990 > 1000); if ((test_count_208 < 100) and (GetRandomReal147(0., 1.) <= 0.5)) { test_cs_142[test_count_208] = new_C864(); test_count_208 = (test_count_208 + 1); } else { }; if ((test_count_208 > 0) and (GetRandomReal147(0., 1.) <= 0.1)) { j_129 = GetRandomInt190(0, (test_count_208 - 1)); dispatch_C_destroyC221(test_cs_142[j_129]); test_count_208 = (test_count_208 - 1); test_cs_142[j_129] = test_cs_142[test_count_208]; } else { }; i_990 = (i_990 + 1); }; testSuccess175(); } IS_NATIVE function testFail345(string msg985) { } IS_NATIVE IS_EXTERN @extern function GetRandomReal147(real a499, real b172) returns real { } IS_NATIVE IS_EXTERN @extern function GetRandomInt190(integer a164, integer b807) returns integer { } IS_NATIVE function testSuccess175() { } function C_init516(integer this190) { } function new_C864() returns integer { local integer this197 this_197 = alloc_C143(); construct_C909(this_197); return this_197; } function construct_C909(integer this178) { C_init516(this_178); if (C_alive_130[this_178] == 1) { testFail345("already alive"); } else { }; C_alive_130[this_178] = 1; } function C_onDestroy125(integer this147) { C_alive_130[this_147] = 2; } function destroyC635(integer this188) { C_onDestroy125(this_188); dealloc_C148(this_188); } function alloc_C143() returns integer { local integer this120 if (C_firstFree_791 == 0) { if (C_maxIndex_156 < 32768) { C_maxIndex_156 = (C_maxIndex_156 + 1); this_120 = C_maxIndex_156; C_typeId_602[this_120] = 1; } else { error159("Out of memory: Could not create C."); this_120 = 0; }; } else { C_firstFree_791 = (C_firstFree_791 - 1); this_120 = C_nextFree_155[C_firstFree_791]; C_typeId_602[this_120] = 1; }; return this_120; } function error159(string msg476) { $debugPrint190((msg_476 + (" " + #getStackTrace()))); } function dealloc_C148(integer obj881) { if (C_typeId_602[obj_881] == 0) { error159("Double free: object of type C"); } else { C_nextFree_155[C_firstFree_791] = obj_881; C_firstFree_791 = (C_firstFree_791 + 1); C_typeId_602[obj_881] = 0; }; } function dispatch_C_destroyC221(integer this205) { if (C_typeId_602[this_205] == 0) { if (this_205 == 0) { error159("Nullpointer exception when calling C.C"); } else { error159("Called C.C on invalid object."); }; } else { }; destroyC635(this_205); }