Преглед изворни кода

Update some SQObjectPtr operators overloading to check same type.

mingodad пре 12 година
родитељ
комит
1101ab70a7
1 измењених фајлова са 20 додато и 15 уклоњено
  1. 20 15
      SquiLu/squirrel/sqobject.h

+ 20 - 15
SquiLu/squirrel/sqobject.h

@@ -194,10 +194,12 @@ struct SQObjectPtr;
 		_unVal.sym = x; \
 	} \
 	inline SQObjectPtr& operator=(_class x) \
-	{  \
-		__Release(_type,_unVal); \
-		_type = type; \
-		SQ_OBJECT_RAWINIT() \
+	{  \
+		if(_type != type){\
+			__Release(_type,_unVal); \
+			_type = type; \
+			SQ_OBJECT_RAWINIT() \
+		}\
 		_unVal.sym = x; \
 		return *this; \
 	}
@@ -246,10 +248,12 @@ struct SQObjectPtr : public SQObject
 		_unVal.nInteger = bBool?1:0;
 	}
 	inline SQObjectPtr& operator=(bool b)
-	{
-		__Release(_type,_unVal);
-		SQ_OBJECT_RAWINIT()
-		_type = OT_BOOL;
+	{
+		if(_type != OT_BOOL){
+			__Release(_type,_unVal);
+			SQ_OBJECT_RAWINIT()
+			_type = OT_BOOL;
+		}
 		_unVal.nInteger = b?1:0;
 		return *this;
 	}
@@ -260,33 +264,34 @@ struct SQObjectPtr : public SQObject
 	}
 
 	inline SQObjectPtr& operator=(const SQObjectPtr& obj)
-	{
+	{
+		//saving temporarily the old value for cases
+		//where we are assigning a inner value to the old value
+		//local tbl = {a=2, b=4}; tbl = tbl.a;
 		SQObjectType tOldType =_type;
 		SQObjectValue unOldVal =_unVal;
 		_unVal = obj._unVal;
 		_type = obj._type;
 		__AddRef(_type,_unVal);
-		__Release(tOldType,unOldVal);
+		__Release(tOldType,unOldVal);
 		return *this;
 	}
 	inline SQObjectPtr& operator=(const SQObject& obj)
-	{
+	{
 		SQObjectType tOldType =_type;
 		SQObjectValue unOldVal =_unVal;
 		_unVal = obj._unVal;
 		_type = obj._type;
 		__AddRef(_type,_unVal);
-		__Release(tOldType,unOldVal);
+		__Release(tOldType,unOldVal);
 		return *this;
 	}
 
 	inline void Null()
 	{
-		SQObjectType tOldType = _type;
-		SQObjectValue unOldVal = _unVal;
+		__Release(_type,_unVal);
 		_type = OT_NULL;
 		_unVal.raw = (SQRawObjectVal)NULL;
-		__Release(tOldType ,unOldVal);
 	}
 	private:
 		SQObjectPtr(const SQChar *){} //safety