AMTL updates and changes to adapt for them to fix menu crashes (bug 5921, r=psychonic).
authorDavid Anderson <dvander@alliedmods.net>
Sat Nov 30 10:51:28 2013 -0500 (2013-11-30)
changeset 41753ae24e84c028
parent 4174 4df64445250d
child 4176 74365c2b1d7b
AMTL updates and changes to adapt for them to fix menu crashes (bug 5921, r=psychonic).

AMTL:
Removes isVoid from AString.
Fixes support inserting to Vector at length.
core/MenuStyle_Base.cpp
core/MenuStyle_Base.h
core/logic/HandleSys.cpp
core/logic/HandleSys.h
public/amtl/am-string.h
public/amtl/am-utility.h
public/amtl/am-vector.h
     1.1 --- a/core/MenuStyle_Base.cpp	Thu Nov 21 19:26:10 2013 -0500
     1.2 +++ b/core/MenuStyle_Base.cpp	Sat Nov 30 10:51:28 2013 -0500
     1.3 @@ -636,10 +636,10 @@
     1.4  
     1.5  	item.info = info;
     1.6  	if (draw.display)
     1.7 -		item.display = draw.display;
     1.8 +		item.display = new ke::AString(draw.display);
     1.9  	item.style = draw.style;
    1.10  
    1.11 -	m_items.append(item);
    1.12 +	m_items.append(ke::Move(item));
    1.13  	return true;
    1.14  }
    1.15  
    1.16 @@ -657,10 +657,10 @@
    1.17  	CItem item;
    1.18  	item.info = info;
    1.19  	if (draw.display)
    1.20 -		item.display = draw.display;
    1.21 +		item.display = new ke::AString(draw.display);
    1.22  	item.style = draw.style;
    1.23  
    1.24 -	m_items.insert(position, item);
    1.25 +	m_items.insert(position, ke::Move(item));
    1.26  	return true;
    1.27  }
    1.28  
    1.29 @@ -685,7 +685,7 @@
    1.30  
    1.31  	if (draw)
    1.32  	{
    1.33 -		draw->display = m_items[position].display.chars();
    1.34 +		draw->display = m_items[position].display->chars();
    1.35  		draw->style = m_items[position].style;
    1.36  	}
    1.37  
     2.1 --- a/core/MenuStyle_Base.h	Thu Nov 21 19:26:10 2013 -0500
     2.2 +++ b/core/MenuStyle_Base.h	Sat Nov 30 10:51:28 2013 -0500
     2.3 @@ -45,8 +45,6 @@
     2.4  public:
     2.5  	CItem()
     2.6  	{
     2.7 -		info.setVoid();
     2.8 -		display.setVoid();
     2.9  		style = 0;
    2.10  		access = 0;
    2.11  	}
    2.12 @@ -57,11 +55,24 @@
    2.13  		style = other->style;
    2.14  		access = other->access;
    2.15  	}
    2.16 +	CItem & operator =(ke::Moveable<CItem> other)
    2.17 +	{
    2.18 +		info = ke::Move(other->info);
    2.19 +		display = ke::Move(other->display);
    2.20 +		style = other->style;
    2.21 +		access = other->access;
    2.22 +		return *this;
    2.23 +	}
    2.24 +
    2.25  public:
    2.26  	ke::AString info;
    2.27 -	ke::AString display;
    2.28 +	ke::AutoPtr<ke::AString> display;
    2.29  	unsigned int style;
    2.30  	unsigned int access;
    2.31 +
    2.32 +private:
    2.33 +	CItem(const CItem &other) KE_DELETE;
    2.34 +	CItem &operator =(const CItem &other) KE_DELETE;
    2.35  };
    2.36  
    2.37  class CBaseMenuPlayer
     3.1 --- a/core/logic/HandleSys.cpp	Thu Nov 21 19:26:10 2013 -0500
     3.2 +++ b/core/logic/HandleSys.cpp	Sat Nov 30 10:51:28 2013 -0500
     3.3 @@ -204,10 +204,8 @@
     3.4  	pType->dispatch = dispatch;
     3.5  	if (name && name[0] != '\0')
     3.6  	{
     3.7 -		pType->name = name;
     3.8 +		pType->name = new ke::AString(name);
     3.9  		m_TypeLookup.insert(name, pType);
    3.10 -	} else {
    3.11 -		pType->name.setVoid();
    3.12  	}
    3.13  
    3.14  	pType->opened = 0;
    3.15 @@ -924,8 +922,8 @@
    3.16  	pType->dispatch = NULL;
    3.17  
    3.18  	/* Remove it from the type cache. */
    3.19 -	if (!pType->name.isVoid())
    3.20 -		m_TypeLookup.remove(pType->name.chars());
    3.21 +	if (pType->name)
    3.22 +		m_TypeLookup.remove(pType->name->chars());
    3.23  
    3.24  	return true;
    3.25  }
    3.26 @@ -1050,8 +1048,8 @@
    3.27  			continue; /* We may have gaps, it's fine. */
    3.28  		}
    3.29  
    3.30 -		if (!m_Types[i].name.isVoid())
    3.31 -			pTypeName = m_Types[i].name.chars();
    3.32 +		if (m_Types[i].name)
    3.33 +			pTypeName = m_Types[i].name->chars();
    3.34  		else
    3.35  			pTypeName = "ANON";
    3.36  
    3.37 @@ -1118,8 +1116,8 @@
    3.38  		unsigned int size = 0;
    3.39  		unsigned int parentIdx;
    3.40  		bool bresult;
    3.41 -		if (!pType->name.isVoid())
    3.42 -			type = pType->name.chars();
    3.43 +		if (pType->name)
    3.44 +			type = pType->name->chars();
    3.45  
    3.46  		if ((parentIdx = m_Handles[i].clone) != 0)
    3.47  		{
     4.1 --- a/core/logic/HandleSys.h	Thu Nov 21 19:26:10 2013 -0500
     4.2 +++ b/core/logic/HandleSys.h	Sat Nov 30 10:51:28 2013 -0500
     4.3 @@ -103,11 +103,11 @@
     4.4  	TypeAccess typeSec;
     4.5  	HandleAccess hndlSec;
     4.6  	unsigned int opened;
     4.7 -	ke::AString name;
     4.8 +	ke::AutoPtr<ke::AString> name;
     4.9  
    4.10  	static inline bool matches(const char *key, const QHandleType *type)
    4.11  	{
    4.12 -		return type->name.compare(key) == 0;
    4.13 +		return type->name && type->name->compare(key) == 0;
    4.14  	}
    4.15  };
    4.16  
     5.1 --- a/public/amtl/am-string.h	Thu Nov 21 19:26:10 2013 -0500
     5.2 +++ b/public/amtl/am-string.h	Sat Nov 30 10:51:28 2013 -0500
     5.3 @@ -104,29 +104,17 @@
     5.4      return chars()[index];
     5.5    }
     5.6  
     5.7 -  void setVoid() {
     5.8 -    chars_ = NULL;
     5.9 -    length_ = kInvalidLength;
    5.10 -  }
    5.11 -
    5.12 -  bool isVoid() const {
    5.13 -    return length_ == kInvalidLength;
    5.14 -  }
    5.15 -
    5.16    size_t length() const {
    5.17 -    assert(!isVoid());
    5.18      return length_;
    5.19    }
    5.20  
    5.21    const char *chars() const {
    5.22      if (!chars_)
    5.23 -      return isVoid() ? NULL : "";
    5.24 +      return "";
    5.25      return chars_;
    5.26    }
    5.27  
    5.28   private:
    5.29 -  static const size_t kInvalidLength = (size_t)-1;
    5.30 -
    5.31    void set(const char *str, size_t length) {
    5.32      chars_ = new char[length + 1];
    5.33      length_ = length;
     6.1 --- a/public/amtl/am-utility.h	Thu Nov 21 19:26:10 2013 -0500
     6.2 +++ b/public/amtl/am-utility.h	Sat Nov 30 10:51:28 2013 -0500
     6.3 @@ -91,7 +91,7 @@
     6.4        : t_(t)
     6.5      {
     6.6      }
     6.7 -    AutoPtr(Moveable<AutoPtr<T> > &other)
     6.8 +    AutoPtr(Moveable<AutoPtr<T> > other)
     6.9      {
    6.10          t_ = other->t_;
    6.11          other->t_ = NULL;
    6.12 @@ -116,7 +116,7 @@
    6.13          t_ = t;
    6.14          return t_;
    6.15      }
    6.16 -    T *operator =(Moveable<AutoPtr<T> > &other) {
    6.17 +    T *operator =(Moveable<AutoPtr<T> > other) {
    6.18          delete t_;
    6.19          t_ = other->t_;
    6.20          other->t_ = NULL;
     7.1 --- a/public/amtl/am-vector.h	Thu Nov 21 19:26:10 2013 -0500
     7.2 +++ b/public/amtl/am-vector.h	Sat Nov 30 10:51:28 2013 -0500
     7.3 @@ -86,14 +86,22 @@
     7.4    }
     7.5  
     7.6    // Shift all elements including |at| up by one, and insert |item| at the
     7.7 -  // given position. This is a linear-time operation.
     7.8 +  // given position. If |at| is one greater than the last usable index,
     7.9 +  // i.e. |at == length()|, then this is the same as append(). No other
    7.10 +  // invalid indexes are allowed.
    7.11 +  //
    7.12 +  // This is a linear-time operation.
    7.13    bool insert(size_t at, const T &item) {
    7.14 +    if (at == length())
    7.15 +      return append(item);
    7.16      if (!moveUp(at))
    7.17        return false;
    7.18      new (&data_[at]) T(item);
    7.19      return true;
    7.20    }
    7.21    bool insert(size_t at, Moveable<T> item) {
    7.22 +    if (at == length())
    7.23 +      return append(item);
    7.24      if (!moveUp(at))
    7.25        return false;
    7.26      new (&data_[at]) T(item);
    7.27 @@ -104,7 +112,7 @@
    7.28    // element. This is a linear-time operation.
    7.29    void remove(size_t at) {
    7.30      for (size_t i = at; i < length() - 1; i++)
    7.31 -      data_[i] = T(Moveable<T>(data_[i + 1]));
    7.32 +      data_[i] = Moveable<T>(data_[i + 1]);
    7.33      pop();
    7.34    }
    7.35  
    7.36 @@ -178,11 +186,12 @@
    7.37    }
    7.38  
    7.39    bool moveUp(size_t at) {
    7.40 +    assert(at < nitems_);
    7.41      if (!growIfNeeded(1))
    7.42        return false;
    7.43      nitems_++;
    7.44      for (size_t i = nitems_ - 1; i > at; i--)
    7.45 -      data_[i] = T(Moveable<T>(data_[i - 1]));
    7.46 +      data_[i] = Moveable<T>(data_[i - 1]);
    7.47      return true;
    7.48    }
    7.49