Forráskód Böngészése

Discovered a side effect bug introduced by the modification to allow functions declared local to be called recursivelly.
This only happens when the same script is reloaded multiple time on the same vm.
I usually use this mode to develop server side apps with the webserver,
without reloading on the same vm on every request no memory leaks happen due to this code.

mingodad 12 éve
szülő
commit
c53a7a44c7
1 módosított fájl, 7 hozzáadás és 0 törlés
  1. 7 0
      SquiLu/squirrel/sqcompiler.cpp

+ 7 - 0
SquiLu/squirrel/sqcompiler.cpp

@@ -1176,6 +1176,7 @@ public:
 			varname = Expect(TK_IDENTIFIER);
 			CheckLocalNameScope(varname, _scope.nested);
 			Expect(_SC('('));
+#if 1 //doing this way works but prevents garbage collection when doing multiple reloads on the same vm
 			//the following is an attempt to allow local declared functions be called recursivelly
 			SQInteger old_pos = _fs->GetCurrentPos(); //save current instructions position
 			_fs->PushLocalVariable(varname, _scope.nested, _VAR_CLOSURE); //add function name to find it as outer var if needed
@@ -1187,7 +1188,13 @@ public:
 			    SQInstruction & inst = _fs->GetInstruction(i);
 			    _fs->SetIntructionParam(i, 0, inst._arg0 -1);
 			}
+			_fs->PopTarget();
+#else
+			CreateFunction(varname,false);
+			_fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, 0);
 			_fs->PopTarget();
+			_fs->PushLocalVariable(varname, _scope.nested, _VAR_CLOSURE);
+#endif
 			return;
 		}