diff --git a/modules/irc/Module.cpp b/modules/irc/Module.cpp index 3543fc18..9770fd54 100644 --- a/modules/irc/Module.cpp +++ b/modules/irc/Module.cpp @@ -81,15 +81,22 @@ void OnSquirrelLoad() void OnSquirrelTerminate() { OutputMessage("Terminating: %s", SQIRC_NAME); - // Terminate all session and release script resources - Session::Terminate(); // Release null objects just in case NullObject().Release(); NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); + // Terminate all sessions, if any + Session::Terminate(); } /* ------------------------------------------------------------------------------------------------ @@ -130,6 +137,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/modules/irc/Session.hpp b/modules/irc/Session.hpp index 6de54bd6..a67dcbce 100644 --- a/modules/irc/Session.hpp +++ b/modules/irc/Session.hpp @@ -26,8 +26,8 @@ public: static void Process(); /* -------------------------------------------------------------------------------------------- - * Terminate all sessions and release their resources. - */ + * Terminate all sessions and release their resources. + */ static void Terminate(); protected: diff --git a/modules/json/Module.cpp b/modules/json/Module.cpp index 43692823..996bb653 100644 --- a/modules/json/Module.cpp +++ b/modules/json/Module.cpp @@ -80,6 +80,13 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); } @@ -122,6 +129,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/modules/mg/Module.cpp b/modules/mg/Module.cpp index b4a58513..0b3ea262 100644 --- a/modules/mg/Module.cpp +++ b/modules/mg/Module.cpp @@ -82,9 +82,15 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); - // Release script resources... } /* ------------------------------------------------------------------------------------------------ @@ -125,6 +131,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/modules/mmdb/Module.cpp b/modules/mmdb/Module.cpp index 30e0e243..7565a479 100644 --- a/modules/mmdb/Module.cpp +++ b/modules/mmdb/Module.cpp @@ -80,6 +80,13 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); } @@ -122,6 +129,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/modules/mysql/Module.cpp b/modules/mysql/Module.cpp index 4d522722..9ce2f7bf 100644 --- a/modules/mysql/Module.cpp +++ b/modules/mysql/Module.cpp @@ -1,12 +1,5 @@ // ------------------------------------------------------------------------------------------------ #include "Common.hpp" -#include "Account.hpp" -#include "Column.hpp" -#include "Connection.hpp" -#include "ResultSet.hpp" -#include "Savepoint.hpp" -#include "Statement.hpp" -#include "Transaction.hpp" // ------------------------------------------------------------------------------------------------ #include @@ -87,9 +80,15 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); - // Release script resources... } /* ------------------------------------------------------------------------------------------------ @@ -130,6 +129,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; @@ -165,154 +167,15 @@ void UnbindCallbacks() _Clbk->OnPluginCommand = nullptr; } +// ------------------------------------------------------------------------------------------------ +extern void Register_Account(Table & sqlns); + // ------------------------------------------------------------------------------------------------ void RegisterAPI(HSQUIRRELVM vm) { Table sqlns(vm); - sqlns.Bind(_SC("Account"), Class< Account >(vm, _SC("SqMySQLAccount")) - // Constructors - .Ctor< const Account & >() - .Ctor< CSStr, CSStr >() - .Ctor< CSStr, CSStr, CSStr >() - .Ctor< CSStr, CSStr, CSStr, CSStr >() - .Ctor< CSStr, CSStr, CSStr, CSStr, SQInteger >() - .Ctor< CSStr, CSStr, CSStr, CSStr, SQInteger, CSStr >() - // Core Meta-methods - .Func(_SC("_cmp"), &Account::Cmp) - .SquirrelFunc(_SC("_typename"), &Account::Typename) - .Func(_SC("_tostring"), &Account::ToString) - // Properties - .Prop(_SC("Port"), &Account::GetPortNum, &Account::SetPortNum) - .Prop(_SC("Host"), &Account::GetHost, &Account::SetHost) - .Prop(_SC("User"), &Account::GetUser, &Account::SetUser) - .Prop(_SC("Pass"), &Account::GetPass, &Account::SetPass) - .Prop(_SC("Socket"), &Account::GetSocket, &Account::SetSocket) - .Prop(_SC("Flags"), &Account::GetFlags, &Account::SetFlags) - .Prop(_SC("SSL_Key"), &Account::GetSSL_Key, &Account::SetSSL_Key) - .Prop(_SC("SSL_Cert"), &Account::GetSSL_Cert, &Account::SetSSL_Cert) - .Prop(_SC("SSL_CA"), &Account::GetSSL_CA, &Account::SetSSL_CA) - .Prop(_SC("SSL_CA_Path"), &Account::GetSSL_CA_Path, &Account::SetSSL_CA_Path) - .Prop(_SC("SSL_Cipher"), &Account::GetSSL_Cipher, &Account::SetSSL_Cipher) - .Prop(_SC("AutoCommit"), &Account::GetAutoCommit, &Account::SetAutoCommit) - .Prop(_SC("Options"), &Account::GetOptionsTable) - .Prop(_SC("OptionsCount"), &Account::OptionsCount) - .Prop(_SC("OptionsEmpty"), &Account::OptionsEmpty) - // Member Methods - .Func(_SC("EnableFlags"), &Account::EnableFlags) - .Func(_SC("DisableFlags"), &Account::DisableFlags) - .Func(_SC("SetSSL"), &Account::SetSSL) - .Func(_SC("GetOption"), &Account::GetOption) - .Func(_SC("SetOption"), &Account::SetOption) - .Func(_SC("RemoveOption"), &Account::RemoveOption) - .Func(_SC("OptionsClear"), &Account::OptionsClear) - .Func(_SC("Connect"), &Account::Connect) - ); - - sqlns.Bind(_SC("Connection"), Class< Connection >(vm, _SC("SqMySQLConnection")) - // Constructors - .Ctor() - .Ctor< const Account & >() - // Core Meta-methods - .Func(_SC("_cmp"), &Connection::Cmp) - .SquirrelFunc(_SC("_typename"), &Connection::Typename) - .Func(_SC("_tostring"), &Connection::ToString) - // Properties - .Prop(_SC("IsValid"), &Connection::IsValid) - .Prop(_SC("Connected"), &Connection::Connected) - .Prop(_SC("ErrNo"), &Connection::GetErrNo) - .Prop(_SC("ErrStr"), &Connection::GetErrStr) - .Prop(_SC("LastErrNo"), &Connection::GetLastErrNo) - .Prop(_SC("LastErrStr"), &Connection::GetLastErrStr) - .Prop(_SC("Port"), &Connection::GetPortNum) - .Prop(_SC("Host"), &Connection::GetHost) - .Prop(_SC("User"), &Connection::GetUser) - .Prop(_SC("Pass"), &Connection::GetPass) - .Prop(_SC("Name"), &Connection::GetName, &Connection::SetName) - .Prop(_SC("Socket"), &Connection::GetSocket) - .Prop(_SC("Flags"), &Connection::GetFlags) - .Prop(_SC("SSL_Key"), &Connection::GetSSL_Key) - .Prop(_SC("SSL_Cert"), &Connection::GetSSL_Cert) - .Prop(_SC("SSL_CA"), &Connection::GetSSL_CA) - .Prop(_SC("SSL_CA_Path"), &Connection::GetSSL_CA_Path) - .Prop(_SC("SSL_Cipher"), &Connection::GetSSL_Cipher) - .Prop(_SC("Charset"), &Connection::GetCharset, &Connection::SetCharset) - .Prop(_SC("AutoCommit"), &Connection::GetAutoCommit, &Connection::SetAutoCommit) - .Prop(_SC("InTransaction"), &Connection::GetInTransaction) - // Member Methods - .Func(_SC("Disconnect"), &Connection::Disconnect) - .Func(_SC("SelectDb"), &Connection::SetName) - .Func(_SC("Execute"), &Connection::Execute) - .Func(_SC("Insert"), &Connection::Insert) - .Func(_SC("Query"), &Connection::Query) - .Func(_SC("Statement"), &Connection::GetStatement) - .Func(_SC("Transaction"), &Connection::GetTransaction) - ); - - sqlns.Bind(_SC("Statement"), Class< Statement >(vm, _SC("SqMySQLStatement")) - // Constructors - .Ctor() - // Core Meta-methods - .Func(_SC("_cmp"), &Statement::Cmp) - .SquirrelFunc(_SC("_typename"), &Statement::Typename) - .Func(_SC("_tostring"), &Statement::ToString) - // Properties - .Prop(_SC("IsValid"), &Statement::IsValid) - .Prop(_SC("Connection"), &Statement::GetConnection, &Statement::SetConnection) - // Member Methods - .Func(_SC("Execute"), &Statement::Execute) - .Func(_SC("Insert"), &Statement::Insert) - .Func(_SC("Query"), &Statement::Query) - .Func(_SC("SetInt8"), &Statement::SetInt8) - .Func(_SC("SetUint8"), &Statement::SetUint8) - .Func(_SC("SetInt16"), &Statement::SetInt16) - .Func(_SC("SetUint16"), &Statement::SetUint16) - .Func(_SC("SetInt32"), &Statement::SetInt32) - .Func(_SC("SetUint32"), &Statement::SetUint32) - .Func(_SC("SetInt64"), &Statement::SetInt64) - .Func(_SC("SetUint64"), &Statement::SetUint64) - .Func(_SC("SetSLongInt"), &Statement::SetSLongInt) - .Func(_SC("SetULongInt"), &Statement::SetULongInt) - .Func(_SC("SetInteger"), &Statement::SetInteger) - .Func(_SC("SetFloat32"), &Statement::SetFloat32) - .Func(_SC("SetFloat64"), &Statement::SetFloat64) - .Func(_SC("SetFloat"), &Statement::SetFloat) - .Func(_SC("SetBoolean"), &Statement::SetBoolean) - .Func(_SC("SetDate"), &Statement::SetDate) - .Func(_SC("SetTime"), &Statement::SetTime) - .Func(_SC("SetDatetime"), &Statement::SetDatetime) - .Func(_SC("SetString"), &Statement::SetString) - .Func(_SC("SetEnum"), &Statement::SetEnum) - .Func(_SC("SetSet"), &Statement::SetSet) - .Func(_SC("SetBlob"), &Statement::SetBlob) - .Func(_SC("SetData"), &Statement::SetData) - .Func(_SC("SetBuffer"), &Statement::SetData) - .Func(_SC("SetNull"), &Statement::SetNull) - ); - - sqlns.Bind(_SC("ResultSet"), Class< ResultSet >(vm, _SC("SqMySQLResultSet")) - // Constructors - .Ctor() - // Core Meta-methods - .Func(_SC("_cmp"), &ResultSet::Cmp) - .SquirrelFunc(_SC("_typename"), &ResultSet::Typename) - .Func(_SC("_tostring"), &ResultSet::ToString) - // Properties - .Prop(_SC("IsValid"), &ResultSet::IsValid) - // Member Methods - .Func(_SC("SetInt8"), &ResultSet::GetInt8) - .Func(_SC("SetUint8"), &ResultSet::GetUint8) - .Func(_SC("SetInt16"), &ResultSet::GetInt16) - .Func(_SC("SetUint16"), &ResultSet::GetUint16) - .Func(_SC("SetInt32"), &ResultSet::GetInt32) - .Func(_SC("SetUint32"), &ResultSet::GetUint32) - .Func(_SC("SetInt64"), &ResultSet::GetInt64) - .Func(_SC("SetUint64"), &ResultSet::GetUint64) - .Func(_SC("SetFloat32"), &ResultSet::GetFloat32) - .Func(_SC("SetFloat64"), &ResultSet::GetFloat64) - .Func(_SC("SetBool"), &ResultSet::GetBoolean) - .Func(_SC("SetBoolean"), &ResultSet::GetBoolean) - ); + Register_Account(sqlns); RootTable(vm).Bind(_SC("SqMySQL"), sqlns); } diff --git a/modules/sample/Module.cpp b/modules/sample/Module.cpp index 5767ef04..bedc4cf7 100644 --- a/modules/sample/Module.cpp +++ b/modules/sample/Module.cpp @@ -80,9 +80,16 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); + // Release script resources... +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); - // Release script resources... } /* ------------------------------------------------------------------------------------------------ @@ -123,6 +130,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/modules/sqlite/Module.cpp b/modules/sqlite/Module.cpp index c66581fc..73a4d4ad 100644 --- a/modules/sqlite/Module.cpp +++ b/modules/sqlite/Module.cpp @@ -80,6 +80,13 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); } @@ -122,6 +129,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/modules/xml/Module.cpp b/modules/xml/Module.cpp index 53b13b99..3b772851 100644 --- a/modules/xml/Module.cpp +++ b/modules/xml/Module.cpp @@ -85,6 +85,13 @@ void OnSquirrelTerminate() NullTable().Release(); NullArray().Release(); NullFunction().ReleaseGently(); +} + +/* ------------------------------------------------------------------------------------------------ + * The virtual machined was closed and all memory associated with it was released. +*/ +void OnSquirrelReleased() +{ // Release the current virtual machine, if any DefaultVM::Set(nullptr); } @@ -127,6 +134,9 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message) case SQMOD_TERMINATE_CMD: OnSquirrelTerminate(); break; + case SQMOD_RELEASED_CMD: + OnSquirrelReleased(); + break; default: break; } return 1; diff --git a/shared/SqMod.h b/shared/SqMod.h index b2ebc3a4..5a0590ae 100644 --- a/shared/SqMod.h +++ b/shared/SqMod.h @@ -58,6 +58,7 @@ extern "C" { #define SQMOD_INITIALIZE_CMD 0xDABBAD00 #define SQMOD_LOAD_CMD 0xDEADBABE #define SQMOD_TERMINATE_CMD 0xDEADC0DE + #define SQMOD_RELEASED_CMD 0xDEADBEAF #define SQMOD_API_VER 1 //primitive functions diff --git a/source/Core.cpp b/source/Core.cpp index 2e1289c8..02b882e8 100644 --- a/source/Core.cpp +++ b/source/Core.cpp @@ -406,7 +406,6 @@ void Core::Terminate() { if (m_VM) { - LogDbg("Signaling outside plug-ins to release their resources"); // Tell modules to do their monkey business _Func->SendPluginCommand(0xDEADC0DE, ""); @@ -444,6 +443,10 @@ void Core::Terminate() m_VM = nullptr; // Attempt to close the VM sq_close(sq_vm); + + LogDbg("Signaling outside plug-ins to release the virtual machine"); + // Tell modules to do their monkey business + _Func->SendPluginCommand(0xDEADBEAF, ""); } }