array test_cs481 integer test_count993 array C_nextFree762 integer C_firstFree782 integer C_maxIndex798 array C_typeId572 array C_alive166 integer test_count993 = 0 integer C_firstFree782 = 0 integer C_maxIndex798 = 0 function initGlobals197() { } function main156() { initGlobals197(); init_test182(); } function config218() { } function init_test182() { local integer i129 local integer j831 test_count_993 = 0; i_129 = 0; loop { exitwhen (i_129 > 1000); if ((test_count_993 < 100) and (GetRandomReal205(0., 1.) <= 0.5)) { test_cs_481[test_count_993] = new_C651(); test_count_993 = (test_count_993 + 1); } else { }; if ((test_count_993 > 0) and (GetRandomReal205(0., 1.) <= 0.1)) { j_831 = GetRandomInt140(0, (test_count_993 - 1)); dispatch_C_destroyC803(test_cs_481[j_831]); test_count_993 = (test_count_993 - 1); test_cs_481[j_831] = test_cs_481[test_count_993]; } else { }; i_129 = (i_129 + 1); }; testSuccess187(); } IS_NATIVE function testFail763(string msg213) { } IS_NATIVE IS_EXTERN @extern function GetRandomReal205(real a174, real b725) returns real { } IS_NATIVE IS_EXTERN @extern function GetRandomInt140(integer a174, integer b116) returns integer { } IS_NATIVE function testSuccess187() { } function C_init870(integer this193) { } function new_C651() returns integer { local integer this894 this_894 = alloc_C458(); construct_C179(this_894); return this_894; } function construct_C179(integer this727) { C_init870(this_727); if (C_alive_166[this_727] == 1) { testFail763("already alive"); } else { }; C_alive_166[this_727] = 1; } function C_onDestroy514(integer this205) { C_alive_166[this_205] = 2; } function destroyC206(integer this130) { C_onDestroy514(this_130); dealloc_C159(this_130); } function alloc_C458() returns integer { local integer this479 if (C_firstFree_782 == 0) { if (C_maxIndex_798 < 32768) { C_maxIndex_798 = (C_maxIndex_798 + 1); this_479 = C_maxIndex_798; C_typeId_572[this_479] = 1; } else { error149("Out of memory: Could not create C."); this_479 = 0; }; } else { C_firstFree_782 = (C_firstFree_782 - 1); this_479 = C_nextFree_762[C_firstFree_782]; C_typeId_572[this_479] = 1; }; return this_479; } function error149(string msg624) { $debugPrint399((msg_624 + (" " + #getStackTrace()))); } function dealloc_C159(integer obj538) { if (C_typeId_572[obj_538] == 0) { error149("Double free: object of type C"); } else { C_nextFree_762[C_firstFree_782] = obj_538; C_firstFree_782 = (C_firstFree_782 + 1); C_typeId_572[obj_538] = 0; }; } function dispatch_C_destroyC803(integer this227) { if (C_typeId_572[this_227] == 0) { if (this_227 == 0) { error149("Nullpointer exception when calling C.C"); } else { error149("Called C.C on invalid object."); }; } else { }; destroyC206(this_227); }