Fix warnings in memory_leak_test

This commit is contained in:
Jason Turner
2011-03-14 12:07:08 -06:00
parent e3feb05e05
commit ac0688a8d7

View File

@@ -11,49 +11,49 @@ using namespace chaiscript;
std::string get_next_command() { std::string get_next_command() {
#ifdef READLINE_AVAILABLE #ifdef READLINE_AVAILABLE
char *input_raw; char *input_raw;
input_raw = readline("eval> "); input_raw = readline("eval> ");
add_history(input_raw); add_history(input_raw);
return std::string(input_raw); return std::string(input_raw);
#else #else
std::string retval; std::string retval;
std::cout << "eval> "; std::cout << "eval> ";
std::getline(std::cin, retval); std::getline(std::cin, retval);
return retval; return retval;
#endif #endif
} }
void fuction(void) void fuction(void)
{ {
// do nothing // do nothing
} }
class test class test
{ {
ChaiScript chai; ChaiScript chai;
ChaiScript::State backupState; ChaiScript::State backupState;
public: public:
test() test()
{ {
backupState = chai.get_state(); backupState = chai.get_state();
} }
~test(){} ~test(){}
void ResetState() void ResetState()
{ {
chai.set_state(backupState); chai.set_state(backupState);
chai.add(fun(&fuction),"Whatever()"); chai.add(fun(&fuction),"Whatever()");
} }
void RunFile(std::string sFile)
{ void RunFile(std::string sFile)
chaiscript::Boxed_Value val; {
try { try {
chaiscript::Boxed_Value val = chai.eval_file(sFile); chaiscript::Boxed_Value val = chai.eval_file(sFile);
} }
catch (std::exception &e) { catch (std::exception &e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }
} }
}; };
@@ -61,28 +61,28 @@ public:
int main(int /*argc*/, char * /*argv*/[]) { int main(int /*argc*/, char * /*argv*/[]) {
test myChai; test myChai;
std::string command = ""; std::string command = "";
// //
// this loop increases memoryusage, if RunFile is not called (just hittin enter) // this loop increases memoryusage, if RunFile is not called (just hittin enter)
// as soon RunFile gets called, memory will be freed. // as soon RunFile gets called, memory will be freed.
// //
// scenario1 - RunFile gets called every Loop: memoryusage does not change // scenario1 - RunFile gets called every Loop: memoryusage does not change
// scenario2 - RunFile gets never called (just hitting enter): memoryusage increases every loop // scenario2 - RunFile gets never called (just hitting enter): memoryusage increases every loop
// scenario3 - RunFile gets in changing intervals: memoryusage goes up and down, but never as // scenario3 - RunFile gets in changing intervals: memoryusage goes up and down, but never as
// low as in case 1 scenario3 : // low as in case 1 scenario3 :
while(command != "quit") while(command != "quit")
{ {
for(int i = 1; i < 200; i++) for(int i = 1; i < 200; i++)
myChai.ResetState(); myChai.ResetState();
if(command == "runfile") if(command == "runfile")
myChai.RunFile("Test.chai"); myChai.RunFile("Test.chai");
command = get_next_command(); command = get_next_command();
} }
} }