Rank: Advanced Member
Groups: Registered
Joined: 8/16/2005(UTC) Posts: 288
Thanks: 14 times Was thanked: 13 time(s) in 11 post(s)
|
atai wrote:committed to SVN for Sqrat a fix that maintains strong references from the Script class. Using dumpstack() in SQVM of Squirrel shows the stack is no longer leaking after Script::Compile...() and Script::Run()
I hope people using Sqrat can test the latest version to make sure the leak is fixed.
the key change is in the file sqratScript.h, the key part of the current version also listed below Code: namespace Sqrat {
class Script : public Object { public: Script(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, false) { } ~Script() { if(!sq_isnull(obj)) { sq_release(vm, &obj); } } void CompileString(const string& script) { if(!sq_isnull(obj)) { sq_release(vm, &obj); } if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() * sizeof(SQChar)), _SC(""), true))) { throw Exception(LastErrorString(vm)); } sq_getstackobj(vm,-1,&obj); sq_addref(vm, &obj); sq_pop(vm, 1); } bool CompileString(const string& script, string& errMsg) { if(!sq_isnull(obj)) { sq_release(vm, &obj); } if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() * sizeof(SQChar)), _SC(""), true))) { errMsg = LastErrorString(vm); return false; } sq_getstackobj(vm,-1,&obj); sq_addref(vm, &obj); sq_pop(vm, 1); return true; }
void CompileFile(const string& path) { if(!sq_isnull(obj)) { sq_release(vm, &obj); } if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(), true))) { throw Exception(LastErrorString(vm)); } sq_getstackobj(vm,-1,&obj); sq_addref(vm, &obj); sq_pop(vm, 1); }
bool CompileFile(const string& path, string& errMsg) { if(!sq_isnull(obj)) { sq_release(vm, &obj); } if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(), true))) { errMsg = LastErrorString(vm); return false; } sq_getstackobj(vm,-1,&obj); sq_addref(vm, &obj); sq_pop(vm, 1); return true; }
void Run() { if(!sq_isnull(obj)) { SQRESULT result; sq_pushobject(vm, obj); sq_pushroottable(vm); result = sq_call(vm, 1, false, true); sq_pop(vm, 1); if(SQ_FAILED(result)) { throw Exception(LastErrorString(vm)); } } }
bool Run(string& errMsg) { if(!sq_isnull(obj)) { SQRESULT result; sq_pushobject(vm, obj); sq_pushroottable(vm); result = sq_call(vm, 1, false, true); sq_pop(vm, 1); if(SQ_FAILED(result)) { errMsg = LastErrorString(vm); return false; } } return true; }
void WriteCompiledFile(const string& path) { if(!sq_isnull(obj)) { sq_pushobject(vm, obj); sqstd_writeclosuretofile(vm, path.c_str()); //sq_pop(vm, 1); // needed? } } }; }
Please let me know if you see any issues
|