From 8293cc2216625d0e30209342335b6d09ead5217b Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 21 Dec 2009 22:50:06 +0000 Subject: [PATCH] Esc: Fixed crash on script error, Core: ValueMap - added String key variants, CtrlLib: ArrayCtrl - fixed issue with repeated SetCtrl for the same cell git-svn-id: svn://ultimatepp.org/upp/trunk@1829 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Value.h | 6 ++++-- uppsrc/CtrlLib/ArrayCtrl.cpp | 18 ++++++++++++------ uppsrc/CtrlLib/ArrayCtrl.h | 1 + uppsrc/Esc/Esc.cpp | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/uppsrc/Core/Value.h b/uppsrc/Core/Value.h index f78f9c4f6..affd43c93 100644 --- a/uppsrc/Core/Value.h +++ b/uppsrc/Core/Value.h @@ -694,8 +694,9 @@ public: void Clear(); void Add(const Value& key, const Value& value); - void Add(const char *s, const Value& value) { Add(Value(s), value); } - void Add(Id id, const Value& value) { Add(Value(id.ToString()), value); } + void Add(const String& s, const Value& value) { Add(Value(s), value); } + void Add(const char *s, const Value& value) { Add(Value(s), value); } + void Add(Id id, const Value& value) { Add(Value(id.ToString()), value); } const Index& GetKeys() const { return data->key; } ValueArray GetValues() const { return data->value; } @@ -703,6 +704,7 @@ public: operator ValueArray() const { return GetValues(); } Value operator[](const Value& k) const; + Value operator[](const String& s) const { return operator[](Value(s)); } Value operator[](const char *s) const { return operator[](Value(s)); } Value operator[](const Id& k) const { return operator[](Value(k.ToString())); } diff --git a/uppsrc/CtrlLib/ArrayCtrl.cpp b/uppsrc/CtrlLib/ArrayCtrl.cpp index c66e6c5dd..82b78268f 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.cpp +++ b/uppsrc/CtrlLib/ArrayCtrl.cpp @@ -164,8 +164,19 @@ void ArrayCtrl::CellCtrl::LeftDown(Point, dword) ctrl->SetFocus(); } +void ArrayCtrl::CellInfo::Free() +{ + if(ptr.GetBit()) { + CellCtrl *cc = (CellCtrl *)ptr.GetPtr(); + if(cc->owned) + delete cc->ctrl; + delete cc; + } +} + void ArrayCtrl::CellInfo::Set(Ctrl *ctrl, bool owned, bool value) { + Free(); CellCtrl *cc = new CellCtrl; cc->ctrl = ctrl; cc->Add(*ctrl); @@ -183,12 +194,7 @@ ArrayCtrl::CellInfo::CellInfo(pick_ CellInfo& s) ArrayCtrl::CellInfo::~CellInfo() { - if(ptr.GetBit()) { - CellCtrl *cc = (CellCtrl *)ptr.GetPtr(); - if(cc->owned) - delete cc->ctrl; - delete cc; - } + Free(); } Ctrl& ArrayCtrl::SetCtrl(int i, int j, Ctrl *newctrl, bool owned, bool value) diff --git a/uppsrc/CtrlLib/ArrayCtrl.h b/uppsrc/CtrlLib/ArrayCtrl.h index c82d27468..71fd9b944 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.h +++ b/uppsrc/CtrlLib/ArrayCtrl.h @@ -137,6 +137,7 @@ private: struct CellInfo : Moveable { BitAndPtr ptr; + void Free(); void Set(Ctrl *ctrl, bool owned, bool value); bool IsCtrl() const { return ptr.GetBit(); } CellCtrl& GetCtrl() const { ASSERT(IsCtrl()); return *(CellCtrl *)ptr.GetPtr(); } diff --git a/uppsrc/Esc/Esc.cpp b/uppsrc/Esc/Esc.cpp index d9fdba214..5f5bb91d1 100644 --- a/uppsrc/Esc/Esc.cpp +++ b/uppsrc/Esc/Esc.cpp @@ -39,7 +39,7 @@ EscValue Esc::Get(const SRVal& val) else if(v.IsArray()) { int count = v.GetCount(); - if(ss.IsArray()) { + if(ss.IsArray() && ss.GetArray().GetCount() >= 2) { EscValue v1 = ss.ArrayGet(0); EscValue v2 = ss.ArrayGet(1); int i = v1.IsInt() ? v1.GetInt() : 0; @@ -112,7 +112,7 @@ void Esc::Assign(EscValue& val, const Vector& sbs, int si, const EscVa else { int count = val.GetCount(); if(ss.IsArray()) { - if(!src.IsArray()) + if(!src.IsArray() || ss.GetArray().GetCount() < 2) ThrowError("only array can be assigned to the slice"); EscValue v1 = ss.ArrayGet(0); EscValue v2 = ss.ArrayGet(1);