From 0aed2ee895447edd2803ab6a58410a16b163820d Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Tue, 30 Oct 2007 19:35:56 +0000 Subject: [PATCH] * fixed possible crash when script list was deleted and after that the script got executed * fixed wrong check for #mark and #tip at script loading * misc stuff --- bin/scripts/example_scriptHook.def | 4 +-- src/Client/DefScript/DefScript.cpp | 3 +-- src/Client/DefScript/DefScriptDefines.h | 2 ++ .../DefScript/DefScriptListFunctions.cpp | 11 +++++++- src/Client/DefScript/TypeStorage.h | 26 +++++++++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/bin/scripts/example_scriptHook.def b/bin/scripts/example_scriptHook.def index 8d1dd12..2a395fe 100644 --- a/bin/scripts/example_scriptHook.def +++ b/bin/scripts/example_scriptHook.def @@ -44,7 +44,7 @@ add,counter 1 #script=hook_example_cleanup //---------------------------------- unloaddef hook_example_new -// other possible way: lclear DEFSCRIPT::SCRIPT::hook_example_new +// other possible, but wrong way: delete DEFSCRIPT::SCRIPT::hook_example_new @@ -53,4 +53,4 @@ unloaddef hook_example_new #script=dummy #onload hook_example_hooker -#/onload \ No newline at end of file +#/onload diff --git a/src/Client/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index c01e91f..55d3794 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -11,7 +11,6 @@ using namespace DefScriptTools; #define SN_ONLOAD "?onload?" -#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::" enum DefScriptBlockType { @@ -316,7 +315,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){ DeleteScript(SN_ONLOAD); curScript=Script[sn]; } - else if(strcmp(line.c_str(),"tag")==0 || strcmp(line.c_str(),"mark")==0) + else if(strncmp(line.c_str(),"tag",3)==0 || strncmp(line.c_str(),"mark",4)==0) { curScript->AddLine("#" + line); } diff --git a/src/Client/DefScript/DefScriptDefines.h b/src/Client/DefScript/DefScriptDefines.h index a354398..ae0ad2e 100644 --- a/src/Client/DefScript/DefScriptDefines.h +++ b/src/Client/DefScript/DefScriptDefines.h @@ -35,4 +35,6 @@ enum VariableType typedef long double ldbl; +#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::" + #endif \ No newline at end of file diff --git a/src/Client/DefScript/DefScriptListFunctions.cpp b/src/Client/DefScript/DefScriptListFunctions.cpp index fd5ab6c..758df8b 100644 --- a/src/Client/DefScript/DefScriptListFunctions.cpp +++ b/src/Client/DefScript/DefScriptListFunctions.cpp @@ -45,7 +45,16 @@ DefReturnResult DefScriptPackage::func_lpopfront(CmdSet& Set) // delete a list and all its elements DefReturnResult DefScriptPackage::func_ldelete(CmdSet& Set) { - lists.Delete(_NormalizeVarName(Set.defaultarg,Set.myname)); + std::string lname = _NormalizeVarName(Set.defaultarg,Set.myname); + if(strncmp(lname.c_str(), SCRIPT_NAMESPACE,strlen(SCRIPT_NAMESPACE))==0) + { + printf("DefScript: WARNING: ldelete used on a script list, clearing instead! (called by '%s', list '%s')\n",Set.myname.c_str(), lname.c_str()); + DefList *l = lists.GetNoCreate(lname); + if(l) + l->clear(); + return true; + } + lists.Delete(lname); return true; } diff --git a/src/Client/DefScript/TypeStorage.h b/src/Client/DefScript/TypeStorage.h index 8c93575..6fecf51 100644 --- a/src/Client/DefScript/TypeStorage.h +++ b/src/Client/DefScript/TypeStorage.h @@ -14,6 +14,8 @@ public: T *GetNoCreate(std::string); void Assign(std::string,T*); void Unlink(std::string); + void UnlinkByPtr(T*); + std::string GetNameByPtr(T*); private: T *_Create(std::string); @@ -93,5 +95,29 @@ template void TypeStorage::Unlink(std::string s) _storage.erase(s); } +// removes the pointer from the storage without deleting it, if name is unknown +template void TypeStorage::UnlinkByPtr(T *ptr) +{ + for(std::map::iterator it = _storage.begin(); it != _storage.end();) + { + if(it->second == ptr) + { + Unlink(it->first); + return; + } + } +} + +template std::string TypeStorage::GetNameByPtr(T *ptr) +{ + for(std::map::iterator it = _storage.begin(); it != _storage.end();) + { + if(it->second == ptr) + { + return it->first; + } + } + return ""; +} #endif