From 82ff7d5af733a678bc307fc1dac5676fb8fe2dd2 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 19 Sep 2015 20:01:31 -0700 Subject: [PATCH] Rename CPlugin::SetErrorState to EvictWithError. --- bridge/include/IScriptManager.h | 2 +- core/logic/PluginSys.cpp | 24 ++++++++++++------------ core/logic/PluginSys.h | 6 ++---- core/logic/smn_core.cpp | 8 ++++---- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/bridge/include/IScriptManager.h b/bridge/include/IScriptManager.h index 9df38cd0..2af39055 100644 --- a/bridge/include/IScriptManager.h +++ b/bridge/include/IScriptManager.h @@ -59,7 +59,7 @@ public: virtual AutoConfig *GetConfig(size_t i) = 0; virtual void AddLibrary(const char *name) = 0; virtual void AddConfig(bool create, const char *cfg, const char *folder) = 0; - virtual void SetErrorState(PluginStatus status, const char *fmt, ...) = 0; + virtual void EvictWithError(PluginStatus status, const char *fmt, ...) = 0; }; class IScriptManager diff --git a/core/logic/PluginSys.cpp b/core/logic/PluginSys.cpp index cb1daf32..98a3fdef 100644 --- a/core/logic/PluginSys.cpp +++ b/core/logic/PluginSys.cpp @@ -143,7 +143,7 @@ CPlugin *CPlugin::Create(const char *file) CPlugin *pPlugin = new CPlugin(file); if (!fp) { - pPlugin->SetErrorState(Plugin_BadLoad, "Unable to open file"); + pPlugin->EvictWithError(Plugin_BadLoad, "Unable to open file"); return pPlugin; } @@ -178,7 +178,7 @@ IPluginRuntime *CPlugin::GetRuntime() return m_pRuntime; } -void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...) +void CPlugin::EvictWithError(PluginStatus status, const char *error_fmt, ...) { if (m_status == Plugin_Running) { @@ -265,7 +265,7 @@ bool CPlugin::ReadInfo() } if (m_FileVersion > 5) { base->LocalToString(info->filevers, (char **)&pFileVers); - SetErrorState(Plugin_Failed, "Newer SourceMod required (%s or higher)", pFileVers); + EvictWithError(Plugin_Failed, "Newer SourceMod required (%s or higher)", pFileVers); return false; } } else { @@ -311,7 +311,7 @@ void CPlugin::Call_OnPluginStart() int err; if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE) { - SetErrorState(Plugin_Error, "Error detected in plugin startup (see error logs)"); + EvictWithError(Plugin_Error, "Error detected in plugin startup (see error logs)"); } } @@ -388,7 +388,7 @@ APLRes CPlugin::AskPluginLoad() pFunction->PushStringEx(m_errormsg, sizeof(m_errormsg), 0, SM_PARAM_COPYBACK); pFunction->PushCell(sizeof(m_errormsg)); if ((err = pFunction->Execute(&result)) != SP_ERROR_NONE) { - SetErrorState(Plugin_Failed, "unexpected error %d in AskPluginLoad callback", err); + EvictWithError(Plugin_Failed, "unexpected error %d in AskPluginLoad callback", err); return APLRes_Failure; } @@ -435,7 +435,7 @@ bool CPlugin::TryCompile() char loadmsg[255]; m_pRuntime = g_pSourcePawn2->LoadBinaryFromFile(fullpath, loadmsg, sizeof(loadmsg)); if (!m_pRuntime) { - SetErrorState(Plugin_BadLoad, "Unable to load plugin (%s)", loadmsg); + EvictWithError(Plugin_BadLoad, "Unable to load plugin (%s)", loadmsg); return false; } @@ -634,7 +634,7 @@ void CPlugin::DependencyDropped(CPlugin *pOwner) /* :IDEA: in the future, add native trapping? */ if (m_FakeNativesMissing || m_LibraryMissing) { - SetErrorState(Plugin_Error, "Depends on plugin: %s", pOwner->GetFilename()); + EvictWithError(Plugin_Error, "Depends on plugin: %s", pOwner->GetFilename()); } } @@ -990,7 +990,7 @@ void CPluginManager::LoadAll_SecondPass() if (!RunSecondPass(pPlugin, error, sizeof(error))) { g_Logger.LogError("[SM] Unable to load plugin \"%s\": %s", pPlugin->GetFilename(), error); - pPlugin->SetErrorState(Plugin_BadLoad, "%s", error); + pPlugin->EvictWithError(Plugin_BadLoad, "%s", error); } } } @@ -1208,9 +1208,9 @@ bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin) if (m_bBlockBadPlugins) { if (bulletinUrl[0] != '\0') { - pPlugin->SetErrorState(Plugin_BadLoad, "Known malware detected and blocked. See %s for more info", bulletinUrl); + pPlugin->EvictWithError(Plugin_BadLoad, "Known malware detected and blocked. See %s for more info", bulletinUrl); } else { - pPlugin->SetErrorState(Plugin_BadLoad, "Possible malware or illegal plugin detected and blocked"); + pPlugin->EvictWithError(Plugin_BadLoad, "Possible malware or illegal plugin detected and blocked"); } return false; } @@ -1322,7 +1322,7 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin) } } if (!found) { - pPlugin->SetErrorState(Plugin_Error, "Library not found: %s", lib); + pPlugin->EvictWithError(Plugin_Error, "Library not found: %s", lib); return false; } found->AddDependent(pPlugin); @@ -1345,7 +1345,7 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin) native->name[0] != '@' && !(native->flags & SP_NTVFLAG_OPTIONAL)) { - pPlugin->SetErrorState(Plugin_Error, "Native not found: %s", native->name); + pPlugin->EvictWithError(Plugin_Error, "Native not found: %s", native->name); return; } } diff --git a/core/logic/PluginSys.h b/core/logic/PluginSys.h index 1fb53af4..dee17925 100644 --- a/core/logic/PluginSys.h +++ b/core/logic/PluginSys.h @@ -131,10 +131,8 @@ public: } public: - /** - * Sets an error state on the plugin - */ - void SetErrorState(PluginStatus status, const char *error_fmt, ...); + // Evicts the plugin from memory and sets an error state. + void EvictWithError(PluginStatus status, const char *error_fmt, ...); /** * Initializes the plugin's identity information diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index 808ce405..8ba74ad7 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -390,7 +390,7 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params) if (params[0] == 1) { - pPlugin->SetErrorState(Plugin_Failed, "%s", str); + pPlugin->EvictWithError(Plugin_Failed, "%s", str); return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str); } @@ -402,10 +402,10 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params) DetectExceptions eh(pContext); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1); if (eh.HasException()) { - pPlugin->SetErrorState(Plugin_Failed, "%s", str); + pPlugin->EvictWithError(Plugin_Failed, "%s", str); return 0; } - pPlugin->SetErrorState(Plugin_Failed, "%s", buffer); + pPlugin->EvictWithError(Plugin_Failed, "%s", buffer); pContext->ReportFatalError("%s", buffer); return 0; } @@ -674,7 +674,7 @@ static cell_t RequireFeature(IPluginContext *pContext, const cell_t *params) g_pSM->Format(default_message, sizeof(default_message), "Feature \"%s\" not available", name); msg = default_message; } - pPlugin->SetErrorState(Plugin_Error, "%s", msg); + pPlugin->EvictWithError(Plugin_Error, "%s", msg); if (!eh.HasException()) pContext->ReportFatalError("%s", msg);