Merge branch 'jgrpp' into jgrpp-beta
# Conflicts: # src/settings.cpp # src/settings_gui.cpp # src/settings_internal.h # src/table/company_settings.ini # src/table/currency_settings.ini # src/table/gameopt_settings.ini # src/table/misc_settings.ini # src/table/settings.h.preamble # src/table/settings.ini # src/table/win32_settings.ini # src/table/window_settings.ini
This commit is contained in:
@@ -76,7 +76,7 @@ public:
|
||||
SQInteger Peek(HSQUIRRELVM vm);
|
||||
SQInteger Exists(HSQUIRRELVM vm);
|
||||
SQInteger Clear(HSQUIRRELVM vm);
|
||||
#endif
|
||||
#endif /* DOXYGEN_API */
|
||||
|
||||
/**
|
||||
* Check if the queue is empty.
|
||||
|
@@ -88,7 +88,7 @@ public:
|
||||
* @param ... Optional arguments for this string.
|
||||
*/
|
||||
ScriptText(StringID string, ...);
|
||||
#endif
|
||||
#endif /* DOXYGEN_API */
|
||||
~ScriptText();
|
||||
|
||||
#ifndef DOXYGEN_API
|
||||
|
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "../script_priorityqueue.hpp"
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptPriorityQueue to be used as Squirrel parameter */
|
||||
template <> inline ScriptPriorityQueue *GetParam(ForceType<ScriptPriorityQueue *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptPriorityQueue *)instance; }
|
||||
template <> inline ScriptPriorityQueue &GetParam(ForceType<ScriptPriorityQueue &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptPriorityQueue *)instance; }
|
||||
template <> inline const ScriptPriorityQueue *GetParam(ForceType<const ScriptPriorityQueue *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptPriorityQueue *)instance; }
|
||||
template <> inline const ScriptPriorityQueue &GetParam(ForceType<const ScriptPriorityQueue &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptPriorityQueue *)instance; }
|
||||
template <> inline int Return<ScriptPriorityQueue *>(HSQUIRRELVM vm, ScriptPriorityQueue *res) { if (res == nullptr) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "PriorityQueue", res, nullptr, DefSQDestructorCallback<ScriptPriorityQueue>, true); return 1; }
|
||||
} // namespace SQConvert
|
@@ -278,9 +278,12 @@ void ScriptInstance::GameLoop()
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptInstance::CollectGarbage() const
|
||||
void ScriptInstance::CollectGarbage()
|
||||
{
|
||||
if (this->is_started && !this->IsDead()) this->engine->CollectGarbage();
|
||||
if (this->is_started && !this->IsDead()) {
|
||||
ScriptObject::ActiveInstance active(this);
|
||||
this->engine->CollectGarbage();
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void ScriptInstance::DoCommandReturn(ScriptInstance *instance)
|
||||
|
@@ -68,7 +68,7 @@ public:
|
||||
/**
|
||||
* Let the VM collect any garbage.
|
||||
*/
|
||||
void CollectGarbage() const;
|
||||
void CollectGarbage();
|
||||
|
||||
/**
|
||||
* Get the storage of this script.
|
||||
|
@@ -67,16 +67,18 @@ struct ScriptAllocator {
|
||||
* @param requested_size The requested size that was requested to be allocated.
|
||||
* @param p The pointer to the allocated object, or null if allocation failed.
|
||||
*/
|
||||
void CheckAllocation(size_t requested_size, const void *p)
|
||||
void CheckAllocation(size_t requested_size, void *p)
|
||||
{
|
||||
if (this->allocated_size > this->allocation_limit && !this->error_thrown) {
|
||||
if (this->allocated_size + requested_size > this->allocation_limit && !this->error_thrown) {
|
||||
/* Do not allow allocating more than the allocation limit, except when an error is
|
||||
* already as then the allocation is for throwing that error in Squirrel, the
|
||||
* associated stack trace information and while cleaning up the AI. */
|
||||
this->error_thrown = true;
|
||||
char buff[128];
|
||||
seprintf(buff, lastof(buff), "Maximum memory allocation exceeded by " PRINTF_SIZE " bytes when allocating " PRINTF_SIZE " bytes",
|
||||
this->allocated_size - this->allocation_limit, requested_size);
|
||||
this->allocated_size + requested_size - this->allocation_limit, requested_size);
|
||||
/* Don't leak the rejected allocation. */
|
||||
free(p);
|
||||
throw Script_FatalError(buff);
|
||||
}
|
||||
|
||||
@@ -100,10 +102,11 @@ struct ScriptAllocator {
|
||||
void *Malloc(SQUnsignedInteger size)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
this->allocated_size += size;
|
||||
|
||||
this->CheckAllocation(size, p);
|
||||
|
||||
this->allocated_size += size;
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(p != nullptr);
|
||||
assert(this->allocations.find(p) == this->allocations.end());
|
||||
@@ -127,14 +130,21 @@ struct ScriptAllocator {
|
||||
assert(this->allocations[p] == oldsize);
|
||||
this->allocations.erase(p);
|
||||
#endif
|
||||
/* Can't use realloc directly because memory limit check.
|
||||
* If memory exception is thrown, the old pointer is expected
|
||||
* to be valid for engine cleanup.
|
||||
*/
|
||||
void *new_p = malloc(size);
|
||||
|
||||
void *new_p = realloc(p, size);
|
||||
this->CheckAllocation(size - oldsize, new_p);
|
||||
|
||||
/* Memory limit test passed, we can copy data and free old pointer. */
|
||||
memcpy(new_p, p, std::min(oldsize, size));
|
||||
free(p);
|
||||
|
||||
this->allocated_size -= oldsize;
|
||||
this->allocated_size += size;
|
||||
|
||||
this->CheckAllocation(size, p);
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(new_p != nullptr);
|
||||
assert(this->allocations.find(p) == this->allocations.end());
|
||||
@@ -765,6 +775,11 @@ void Squirrel::Uninitialize()
|
||||
/* Clean up the stuff */
|
||||
sq_pop(this->vm, 1);
|
||||
sq_close(this->vm);
|
||||
|
||||
assert(this->allocator->allocated_size == 0);
|
||||
|
||||
/* Reset memory allocation errors. */
|
||||
this->allocator->error_thrown = false;
|
||||
}
|
||||
|
||||
void Squirrel::Reset()
|
||||
|
Reference in New Issue
Block a user