* 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
This commit is contained in:
False.Genesis 2007-10-30 19:35:56 +00:00
parent 924b8404c4
commit 0aed2ee895
5 changed files with 41 additions and 5 deletions

View File

@ -44,7 +44,7 @@ add,counter 1
#script=hook_example_cleanup #script=hook_example_cleanup
//---------------------------------- //----------------------------------
unloaddef hook_example_new 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 #script=dummy
#onload #onload
hook_example_hooker hook_example_hooker
#/onload #/onload

View File

@ -11,7 +11,6 @@
using namespace DefScriptTools; using namespace DefScriptTools;
#define SN_ONLOAD "?onload?" #define SN_ONLOAD "?onload?"
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
enum DefScriptBlockType enum DefScriptBlockType
{ {
@ -316,7 +315,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
DeleteScript(SN_ONLOAD); DeleteScript(SN_ONLOAD);
curScript=Script[sn]; 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); curScript->AddLine("#" + line);
} }

View File

@ -35,4 +35,6 @@ enum VariableType
typedef long double ldbl; typedef long double ldbl;
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
#endif #endif

View File

@ -45,7 +45,16 @@ DefReturnResult DefScriptPackage::func_lpopfront(CmdSet& Set)
// delete a list and all its elements // delete a list and all its elements
DefReturnResult DefScriptPackage::func_ldelete(CmdSet& Set) 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; return true;
} }

View File

@ -14,6 +14,8 @@ public:
T *GetNoCreate(std::string); T *GetNoCreate(std::string);
void Assign(std::string,T*); void Assign(std::string,T*);
void Unlink(std::string); void Unlink(std::string);
void UnlinkByPtr(T*);
std::string GetNameByPtr(T*);
private: private:
T *_Create(std::string); T *_Create(std::string);
@ -93,5 +95,29 @@ template<class T> void TypeStorage<T>::Unlink(std::string s)
_storage.erase(s); _storage.erase(s);
} }
// removes the pointer from the storage without deleting it, if name is unknown
template<class T> void TypeStorage<T>::UnlinkByPtr(T *ptr)
{
for(std::map<std::string,T*>::iterator it = _storage.begin(); it != _storage.end();)
{
if(it->second == ptr)
{
Unlink(it->first);
return;
}
}
}
template<class T> std::string TypeStorage<T>::GetNameByPtr(T *ptr)
{
for(std::map<std::string,T*>::iterator it = _storage.begin(); it != _storage.end();)
{
if(it->second == ptr)
{
return it->first;
}
}
return "";
}
#endif #endif