Merge branch 'master' into jgrpp-nrt
# Conflicts: # src/fontcache.cpp # src/game/game_text.cpp # src/lang/korean.txt # src/os/macosx/crashlog_osx.cpp # src/os/windows/crashlog_win.cpp # src/station_cmd.cpp # src/viewport.cpp
This commit is contained in:
@@ -470,6 +470,8 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_TIMES_NAMES, "WID_FRW_TIMES_NAMES");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_TIMES_CURRENT, "WID_FRW_TIMES_CURRENT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_TIMES_AVERAGE, "WID_FRW_TIMES_AVERAGE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_ALLOCSIZE, "WID_FRW_ALLOCSIZE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_SEL_MEMORY, "WID_FRW_SEL_MEMORY");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_SCROLLBAR, "WID_FRW_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FGW_CAPTION, "WID_FGW_CAPTION");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FGW_GRAPH, "WID_FGW_GRAPH");
|
||||
|
@@ -40,7 +40,7 @@ static ScriptStorage *GetStorage()
|
||||
|
||||
/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = nullptr;
|
||||
|
||||
ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance *instance)
|
||||
ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance *instance) : alc_scope(instance->engine)
|
||||
{
|
||||
this->last_active = ScriptObject::ActiveInstance::active;
|
||||
ScriptObject::ActiveInstance::active = instance;
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "script_types.hpp"
|
||||
#include "../script_suspend.hpp"
|
||||
#include "../squirrel.hpp"
|
||||
|
||||
/**
|
||||
* The callback function for Mode-classes.
|
||||
@@ -48,6 +49,7 @@ protected:
|
||||
~ActiveInstance();
|
||||
private:
|
||||
ScriptInstance *last_active; ///< The active instance before we go instantiated.
|
||||
ScriptAllocatorScope alc_scope; ///< Keep the correct allocator for the script instance activated
|
||||
|
||||
static ScriptInstance *active; ///< The global current active instance.
|
||||
};
|
||||
|
@@ -1333,6 +1333,8 @@ public:
|
||||
WID_FRW_TIMES_NAMES = ::WID_FRW_TIMES_NAMES,
|
||||
WID_FRW_TIMES_CURRENT = ::WID_FRW_TIMES_CURRENT,
|
||||
WID_FRW_TIMES_AVERAGE = ::WID_FRW_TIMES_AVERAGE,
|
||||
WID_FRW_ALLOCSIZE = ::WID_FRW_ALLOCSIZE,
|
||||
WID_FRW_SEL_MEMORY = ::WID_FRW_SEL_MEMORY,
|
||||
WID_FRW_SCROLLBAR = ::WID_FRW_SCROLLBAR,
|
||||
};
|
||||
|
||||
|
@@ -95,7 +95,7 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na
|
||||
return;
|
||||
}
|
||||
ScriptObject::SetAllowDoCommand(true);
|
||||
} catch (Script_FatalError e) {
|
||||
} catch (Script_FatalError &e) {
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
@@ -153,6 +153,8 @@ void ScriptInstance::Died()
|
||||
DEBUG(script, 0, "The script died unexpectedly.");
|
||||
this->is_dead = true;
|
||||
|
||||
this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache
|
||||
|
||||
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance);
|
||||
delete this->engine;
|
||||
this->instance = nullptr;
|
||||
@@ -186,7 +188,7 @@ void ScriptInstance::GameLoop()
|
||||
}
|
||||
try {
|
||||
this->callback(this);
|
||||
} catch (Script_Suspend e) {
|
||||
} catch (Script_Suspend &e) {
|
||||
this->suspend = e.GetSuspendTime();
|
||||
this->callback = e.GetSuspendCallback();
|
||||
|
||||
@@ -216,10 +218,10 @@ void ScriptInstance::GameLoop()
|
||||
ScriptObject::SetAllowDoCommand(true);
|
||||
/* Start the script by calling Start() */
|
||||
if (!this->engine->CallMethod(*this->instance, "Start", _settings_game.script.script_max_opcode_till_suspend) || !this->engine->IsSuspended()) this->Died();
|
||||
} catch (Script_Suspend e) {
|
||||
} catch (Script_Suspend &e) {
|
||||
this->suspend = e.GetSuspendTime();
|
||||
this->callback = e.GetSuspendCallback();
|
||||
} catch (Script_FatalError e) {
|
||||
} catch (Script_FatalError &e) {
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
@@ -237,10 +239,10 @@ void ScriptInstance::GameLoop()
|
||||
/* Continue the VM */
|
||||
try {
|
||||
if (!this->engine->Resume(_settings_game.script.script_max_opcode_till_suspend)) this->Died();
|
||||
} catch (Script_Suspend e) {
|
||||
} catch (Script_Suspend &e) {
|
||||
this->suspend = e.GetSuspendTime();
|
||||
this->callback = e.GetSuspendCallback();
|
||||
} catch (Script_FatalError e) {
|
||||
} catch (Script_FatalError &e) {
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
@@ -494,7 +496,7 @@ void ScriptInstance::Save()
|
||||
this->engine->CrashOccurred();
|
||||
return;
|
||||
}
|
||||
} catch (Script_FatalError e) {
|
||||
} catch (Script_FatalError &e) {
|
||||
/* If we don't mark the script as dead here cleaning up the squirrel
|
||||
* stack could throw Script_FatalError again. */
|
||||
this->is_dead = true;
|
||||
@@ -698,3 +700,9 @@ void ScriptInstance::InsertEvent(class ScriptEvent *event)
|
||||
|
||||
ScriptEventController::InsertEvent(event);
|
||||
}
|
||||
|
||||
size_t ScriptInstance::GetAllocatedMemory() const
|
||||
{
|
||||
if (this->engine == nullptr) return this->last_allocated_memory;
|
||||
return this->engine->GetAllocatedMemory();
|
||||
}
|
||||
|
@@ -198,6 +198,8 @@ public:
|
||||
*/
|
||||
bool IsSleeping() { return this->suspend != 0; }
|
||||
|
||||
size_t GetAllocatedMemory() const;
|
||||
|
||||
protected:
|
||||
class Squirrel *engine; ///< A wrapper around the squirrel vm.
|
||||
const char *versionAPI; ///< Current API used by this script.
|
||||
@@ -241,6 +243,7 @@ private:
|
||||
int suspend; ///< The amount of ticks to suspend this script before it's allowed to continue.
|
||||
bool is_paused; ///< Is the script paused? (a paused script will not be executed until unpaused)
|
||||
Script_SuspendCallbackProc *callback; ///< Callback that should be called in the next tick the script runs.
|
||||
size_t last_allocated_memory; ///< Last known allocated memory value (for display for crashed scripts)
|
||||
|
||||
/**
|
||||
* Call the script Load function if it exists and data was loaded
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "../script/squirrel.hpp"
|
||||
#include "script_scanner.hpp"
|
||||
#include "script_info.hpp"
|
||||
#include "script_fatalerror.hpp"
|
||||
|
||||
#include "../network/network_content.h"
|
||||
#include "../3rdparty/md5/md5.h"
|
||||
@@ -52,8 +53,12 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const
|
||||
if (!FioCheckFileExists(filename, this->subdir) || !FioCheckFileExists(this->main_script, this->subdir)) return false;
|
||||
|
||||
this->ResetEngine();
|
||||
this->engine->LoadScript(filename);
|
||||
|
||||
try {
|
||||
this->engine->LoadScript(filename);
|
||||
} catch (Script_FatalError &e) {
|
||||
DEBUG(script, 0, "Fatal error '%s' when trying to load the script '%s'.", e.GetErrorMessage(), filename);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -10,17 +10,128 @@
|
||||
/** @file squirrel.cpp the implementation of the Squirrel class. It handles all Squirrel-stuff and gives a nice API back to work with. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <map>
|
||||
#include "../stdafx.h"
|
||||
#include "../debug.h"
|
||||
#include "squirrel_std.hpp"
|
||||
#include "../fileio_func.h"
|
||||
#include "../string_func.h"
|
||||
#include "script_fatalerror.hpp"
|
||||
#include "../settings_type.h"
|
||||
#include <sqstdaux.h>
|
||||
#include <../squirrel/sqpcheader.h>
|
||||
#include <../squirrel/sqvm.h>
|
||||
#include "../core/alloc_func.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/*
|
||||
* If changing the call paths into the scripting engine, define this symbol to enable full debugging of allocations.
|
||||
* This lets you track whether the allocator context is being switched correctly in all call paths.
|
||||
#define SCRIPT_DEBUG_ALLOCATIONS
|
||||
*/
|
||||
|
||||
struct ScriptAllocator {
|
||||
size_t allocated_size; ///< Sum of allocated data size
|
||||
size_t allocation_limit; ///< Maximum this allocator may use before allocations fail
|
||||
|
||||
static const size_t SAFE_LIMIT = 0x8000000; ///< 128 MiB, a safe choice for almost any situation
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
std::map<void *, size_t> allocations;
|
||||
#endif
|
||||
|
||||
void CheckLimit() const
|
||||
{
|
||||
if (this->allocated_size > this->allocation_limit) throw Script_FatalError("Maximum memory allocation exceeded");
|
||||
}
|
||||
|
||||
void *Malloc(SQUnsignedInteger size)
|
||||
{
|
||||
void *p = MallocT<char>(size);
|
||||
this->allocated_size += size;
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(p != nullptr);
|
||||
assert(this->allocations.find(p) == this->allocations.end());
|
||||
this->allocations[p] = size;
|
||||
#endif
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void *Realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size)
|
||||
{
|
||||
if (p == nullptr) {
|
||||
return this->Malloc(size);
|
||||
}
|
||||
if (size == 0) {
|
||||
this->Free(p, oldsize);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(this->allocations[p] == oldsize);
|
||||
this->allocations.erase(p);
|
||||
#endif
|
||||
|
||||
void *new_p = ReallocT<char>(static_cast<char *>(p), size);
|
||||
|
||||
this->allocated_size -= oldsize;
|
||||
this->allocated_size += size;
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(new_p != nullptr);
|
||||
assert(this->allocations.find(p) == this->allocations.end());
|
||||
this->allocations[new_p] = size;
|
||||
#endif
|
||||
|
||||
return new_p;
|
||||
}
|
||||
|
||||
void Free(void *p, SQUnsignedInteger size)
|
||||
{
|
||||
if (p == nullptr) return;
|
||||
free(p);
|
||||
this->allocated_size -= size;
|
||||
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(this->allocations.at(p) == size);
|
||||
this->allocations.erase(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
ScriptAllocator()
|
||||
{
|
||||
this->allocated_size = 0;
|
||||
this->allocation_limit = static_cast<size_t>(_settings_game.script.script_max_memory_megabytes) << 20;
|
||||
if (this->allocation_limit == 0) this->allocation_limit = SAFE_LIMIT; // in case the setting is somehow zero
|
||||
}
|
||||
|
||||
~ScriptAllocator()
|
||||
{
|
||||
#ifdef SCRIPT_DEBUG_ALLOCATIONS
|
||||
assert(this->allocations.size() == 0);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
ScriptAllocator *_squirrel_allocator = nullptr;
|
||||
|
||||
/* See 3rdparty/squirrel/squirrel/sqmem.cpp for the default allocator implementation, which this overrides */
|
||||
#ifndef SQUIRREL_DEFAULT_ALLOCATOR
|
||||
void *sq_vm_malloc(SQUnsignedInteger size) { return _squirrel_allocator->Malloc(size); }
|
||||
void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size) { return _squirrel_allocator->Realloc(p, oldsize, size); }
|
||||
void sq_vm_free(void *p, SQUnsignedInteger size) { _squirrel_allocator->Free(p, size); }
|
||||
#endif
|
||||
|
||||
size_t Squirrel::GetAllocatedMemory() const noexcept
|
||||
{
|
||||
assert(this->allocator != nullptr);
|
||||
return this->allocator->allocated_size;
|
||||
}
|
||||
|
||||
|
||||
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
|
||||
{
|
||||
SQChar buf[1024];
|
||||
@@ -115,6 +226,8 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
|
||||
|
||||
void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
|
||||
if (size != 0) {
|
||||
@@ -130,6 +243,8 @@ void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam,
|
||||
|
||||
void Squirrel::AddConst(const char *var_name, int value)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushstring(this->vm, var_name, -1);
|
||||
sq_pushinteger(this->vm, value);
|
||||
sq_newslot(this->vm, -3, SQTrue);
|
||||
@@ -137,6 +252,8 @@ void Squirrel::AddConst(const char *var_name, int value)
|
||||
|
||||
void Squirrel::AddConst(const char *var_name, bool value)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushstring(this->vm, var_name, -1);
|
||||
sq_pushbool(this->vm, value);
|
||||
sq_newslot(this->vm, -3, SQTrue);
|
||||
@@ -144,6 +261,8 @@ void Squirrel::AddConst(const char *var_name, bool value)
|
||||
|
||||
void Squirrel::AddClassBegin(const char *class_name)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushroottable(this->vm);
|
||||
sq_pushstring(this->vm, class_name, -1);
|
||||
sq_newclass(this->vm, SQFalse);
|
||||
@@ -151,6 +270,8 @@ void Squirrel::AddClassBegin(const char *class_name)
|
||||
|
||||
void Squirrel::AddClassBegin(const char *class_name, const char *parent_class)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushroottable(this->vm);
|
||||
sq_pushstring(this->vm, class_name, -1);
|
||||
sq_pushstring(this->vm, parent_class, -1);
|
||||
@@ -164,6 +285,8 @@ void Squirrel::AddClassBegin(const char *class_name, const char *parent_class)
|
||||
|
||||
void Squirrel::AddClassEnd()
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
@@ -171,6 +294,8 @@ void Squirrel::AddClassEnd()
|
||||
bool Squirrel::MethodExists(HSQOBJECT instance, const char *method_name)
|
||||
{
|
||||
assert(!this->crashed);
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
int top = sq_gettop(this->vm);
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(this->vm, instance);
|
||||
@@ -187,6 +312,8 @@ bool Squirrel::MethodExists(HSQOBJECT instance, const char *method_name)
|
||||
bool Squirrel::Resume(int suspend)
|
||||
{
|
||||
assert(!this->crashed);
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
/* Did we use more operations than we should have in the
|
||||
* previous tick? If so, subtract that from the current run. */
|
||||
if (this->overdrawn_ops > 0 && suspend > 0) {
|
||||
@@ -200,23 +327,29 @@ bool Squirrel::Resume(int suspend)
|
||||
|
||||
this->crashed = !sq_resumecatch(this->vm, suspend);
|
||||
this->overdrawn_ops = -this->vm->_ops_till_suspend;
|
||||
this->allocator->CheckLimit();
|
||||
return this->vm->_suspended != 0;
|
||||
}
|
||||
|
||||
void Squirrel::ResumeError()
|
||||
{
|
||||
assert(!this->crashed);
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
sq_resumeerror(this->vm);
|
||||
}
|
||||
|
||||
void Squirrel::CollectGarbage()
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
sq_collectgarbage(this->vm);
|
||||
}
|
||||
|
||||
bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
|
||||
{
|
||||
assert(!this->crashed);
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
this->allocator->CheckLimit();
|
||||
|
||||
/* Store the stack-location for the return value. We need to
|
||||
* restore this after saving or the stack will be corrupted
|
||||
* if we're in the middle of a DoCommand. */
|
||||
@@ -325,17 +458,20 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool
|
||||
|
||||
bool Squirrel::CreateClassInstance(const char *class_name, void *real_instance, HSQOBJECT *instance)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
return Squirrel::CreateClassInstanceVM(this->vm, class_name, real_instance, instance, nullptr);
|
||||
}
|
||||
|
||||
Squirrel::Squirrel(const char *APIName) :
|
||||
APIName(APIName)
|
||||
APIName(APIName), allocator(new ScriptAllocator())
|
||||
{
|
||||
this->Initialize();
|
||||
}
|
||||
|
||||
void Squirrel::Initialize()
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
this->global_pointer = nullptr;
|
||||
this->print_func = nullptr;
|
||||
this->crashed = false;
|
||||
@@ -432,6 +568,8 @@ static SQInteger _io_file_read(SQUserPointer file, SQUserPointer buf, SQInteger
|
||||
|
||||
SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printerror)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
FILE *file;
|
||||
size_t size;
|
||||
if (strncmp(this->GetAPIName(), "AI", 2) == 0) {
|
||||
@@ -517,6 +655,8 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
|
||||
|
||||
bool Squirrel::LoadScript(HSQUIRRELVM vm, const char *script, bool in_root)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
/* Make sure we are always in the root-table */
|
||||
if (in_root) sq_pushroottable(vm);
|
||||
|
||||
@@ -549,6 +689,8 @@ Squirrel::~Squirrel()
|
||||
|
||||
void Squirrel::Uninitialize()
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
/* Clean up the stuff */
|
||||
sq_pop(this->vm, 1);
|
||||
sq_close(this->vm);
|
||||
@@ -562,6 +704,8 @@ void Squirrel::Reset()
|
||||
|
||||
void Squirrel::InsertResult(bool result)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushbool(this->vm, result);
|
||||
if (this->IsSuspended()) { // Called before resuming a suspended script?
|
||||
vm->GetAt(vm->_stackbase + vm->_suspended_target) = vm->GetUp(-1);
|
||||
@@ -571,6 +715,8 @@ void Squirrel::InsertResult(bool result)
|
||||
|
||||
void Squirrel::InsertResult(int result)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushinteger(this->vm, result);
|
||||
if (this->IsSuspended()) { // Called before resuming a suspended script?
|
||||
vm->GetAt(vm->_stackbase + vm->_suspended_target) = vm->GetUp(-1);
|
||||
@@ -600,6 +746,7 @@ void Squirrel::CrashOccurred()
|
||||
|
||||
bool Squirrel::CanSuspend()
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
return sq_can_suspend(this->vm);
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,11 @@ enum ScriptType {
|
||||
ST_GS, ///< The script is for Game scripts.
|
||||
};
|
||||
|
||||
struct ScriptAllocator;
|
||||
|
||||
class Squirrel {
|
||||
friend class ScriptAllocatorScope;
|
||||
|
||||
private:
|
||||
typedef void (SQPrintFunc)(bool error_msg, const SQChar *message);
|
||||
|
||||
@@ -30,6 +34,7 @@ private:
|
||||
bool crashed; ///< True if the squirrel script made an error.
|
||||
int overdrawn_ops; ///< The amount of operations we have overdrawn.
|
||||
const char *APIName; ///< Name of the API used for this squirrel.
|
||||
std::unique_ptr<ScriptAllocator> allocator; ///< Allocator object used by this script.
|
||||
|
||||
/**
|
||||
* The internal RunError handler. It looks up the real error and calls RunError with it.
|
||||
@@ -272,6 +277,31 @@ public:
|
||||
* Completely reset the engine; start from scratch.
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* Get number of bytes allocated by this VM.
|
||||
*/
|
||||
size_t GetAllocatedMemory() const noexcept;
|
||||
};
|
||||
|
||||
|
||||
extern ScriptAllocator *_squirrel_allocator;
|
||||
|
||||
class ScriptAllocatorScope {
|
||||
ScriptAllocator *old_allocator;
|
||||
|
||||
public:
|
||||
ScriptAllocatorScope(const Squirrel *engine)
|
||||
{
|
||||
this->old_allocator = _squirrel_allocator;
|
||||
/* This may get called with a nullptr engine, in case of a crashed script */
|
||||
_squirrel_allocator = engine != nullptr ? engine->allocator.get() : nullptr;
|
||||
}
|
||||
|
||||
~ScriptAllocatorScope()
|
||||
{
|
||||
_squirrel_allocator = this->old_allocator;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* SQUIRREL_HPP */
|
||||
|
@@ -766,7 +766,7 @@ namespace SQConvert {
|
||||
try {
|
||||
/* Delegate it to a template that can handle this specific function */
|
||||
return HelperT<Tmethod>::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm);
|
||||
} catch (SQInteger e) {
|
||||
} catch (SQInteger &e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
@@ -827,7 +827,7 @@ namespace SQConvert {
|
||||
try {
|
||||
/* Delegate it to a template that can handle this specific function */
|
||||
return HelperT<Tmethod>::SQCall((Tcls *)nullptr, *(Tmethod *)ptr, vm);
|
||||
} catch (SQInteger e) {
|
||||
} catch (SQInteger &e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
@@ -881,7 +881,7 @@ namespace SQConvert {
|
||||
sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>);
|
||||
instance->AddRef();
|
||||
return 0;
|
||||
} catch (SQInteger e) {
|
||||
} catch (SQInteger &e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
@@ -903,7 +903,7 @@ namespace SQConvert {
|
||||
sq_setreleasehook(vm, -nparam, DefSQDestructorCallback<Tcls>);
|
||||
instance->AddRef();
|
||||
return 0;
|
||||
} catch (SQInteger e) {
|
||||
} catch (SQInteger &e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user