Changeset - r10990:c51128ad9005
[Not reviewed]
master
0 10 0
rubidium - 16 years ago 2009-02-03 22:42:42
rubidium@openttd.org
(svn r15330) -Fix [FS#2597]: leaking of Squirrel when using circular references (by enabling the GC).
10 files changed with 44 insertions and 17 deletions:
0 comments (0 inline, 0 general)
config.lib
Show inline comments
 
@@ -1243,7 +1243,6 @@ make_cflags_and_ldflags() {
 
		CFLAGS="$CFLAGS -D_SQ64"
 
	fi
 
	CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
 
	CFLAGS="$CFLAGS -DNO_GARBAGE_COLLECTOR"
 

	
 
	if [ -n "$png_config" ]; then
 
		CFLAGS="$CFLAGS -DWITH_PNG"
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -60,7 +60,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -167,7 +167,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
 
@@ -269,7 +269,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -377,7 +377,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
projects/openttd_vs80.vcproj.in
Show inline comments
 
@@ -60,7 +60,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -167,7 +167,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
 
@@ -269,7 +269,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -377,7 +377,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -61,7 +61,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -166,7 +166,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
 
@@ -267,7 +267,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -374,7 +374,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
projects/openttd_vs90.vcproj.in
Show inline comments
 
@@ -61,7 +61,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -166,7 +166,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
 
@@ -267,7 +267,7 @@
 
				FavorSizeOrSpeed="2"
 
				OmitFramePointers="true"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT"
 
				StringPooling="true"
 
				ExceptionHandling="1"
 
				RuntimeLibrary="0"
 
@@ -374,7 +374,7 @@
 
				AdditionalOptions="/MP"
 
				Optimization="0"
 
				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64"
 
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64"
 
				BasicRuntimeChecks="3"
 
				RuntimeLibrary="1"
 
				UsePrecompiledHeader="0"
src/ai/ai_core.cpp
Show inline comments
 
@@ -3,6 +3,7 @@
 
/** @file ai_core.cpp Implementation of AI. */
 

	
 
#include "../stdafx.h"
 
#include "../core/bitmath_func.hpp"
 
#include "../company_base.h"
 
#include "../company_func.h"
 
#include "../debug.h"
 
@@ -68,6 +69,13 @@
 
		}
 
	}
 

	
 
	/* Occasionally collect garbage; every 255 ticks do one company.
 
	 * Effectively collecting garbage once every two months per AI. */
 
	if ((AI::frame_counter & 255) == 0) {
 
		CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4);
 
		if (IsValidCompanyID(cid) && !IsHumanCompany(cid)) GetCompany(cid)->ai_instance->CollectGarbage();
 
	}
 

	
 
	_current_company = OWNER_NONE;
 
}
 

	
src/ai/ai_instance.cpp
Show inline comments
 
@@ -296,6 +296,11 @@ void AIInstance::GameLoop()
 
	}
 
}
 

	
 
void AIInstance::CollectGarbage()
 
{
 
	if (this->is_started && !this->is_dead) this->engine->CollectGarbage();
 
}
 

	
 
/* static */ void AIInstance::DoCommandReturn(AIInstance *instance)
 
{
 
	instance->engine->InsertResult(AIObject::GetLastCommandRes());
src/ai/ai_instance.hpp
Show inline comments
 
@@ -45,6 +45,11 @@ public:
 
	void GameLoop();
 

	
 
	/**
 
	 * Let the VM collect any garbage.
 
	 */
 
	void CollectGarbage();
 

	
 
	/**
 
	 * Get the storage of this AI.
 
	 */
 
	static class AIStorage *GetStorage();
src/script/squirrel.cpp
Show inline comments
 
@@ -175,6 +175,11 @@ bool Squirrel::Resume(int suspend)
 
	return this->vm->_suspended != 0;
 
}
 

	
 
void Squirrel::CollectGarbage()
 
{
 
	sq_collectgarbage(this->vm);
 
}
 

	
 
bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
 
{
 
	/* Store the stack-location for the return value. We need to
src/script/squirrel.hpp
Show inline comments
 
@@ -101,6 +101,11 @@ public:
 
	 */
 
	bool Resume(int suspend = -1);
 

	
 
	/**
 
	 * Tell the VM to do a garbage collection run.
 
	 */
 
	void CollectGarbage();
 

	
 
	void InsertResult(bool result);
 
	void InsertResult(int result);
 

	
0 comments (0 inline, 0 general)