Fixed: Strict aliasing warnings

--HG--
branch : develop
This commit is contained in:
kervala 2016-12-10 18:55:31 +01:00
parent 3c568ce8a3
commit 50b6af6d3d
4 changed files with 30 additions and 28 deletions

View file

@ -108,7 +108,7 @@ template <class TPtr, class TKey, class TResourceFinder>
class CResourcePtr
{
private:
CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object.
CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object.
TKey Key; // The key used to find the pointer
mutable TPtr *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()

View file

@ -61,7 +61,7 @@ template <class TPtr, class TKey, class TResourceFinder> SMART_INLINE void CReso
if(pinfo->Ptr)
{
// Inform the Object that no more CResourcePtr points on it.
((TPtr*)(pinfo->Ptr))->pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
((TPtr*)(pinfo->Ptr))->pinfo = &CRefCount::NullPtrInfo;
}
// Then delete the pinfo.
delete pinfo;
@ -74,7 +74,7 @@ template <class TPtr, class TKey, class TResourceFinder> SMART_INLINE void CReso
// Cons - dest.
template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPtr, TKey, TResourceFinder>::CResourcePtr()
{
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinf o= &CRefCount::NullPtrInfo;
Ptr= NULL;
REF_TRACE("Smart()");
@ -95,7 +95,7 @@ template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPt
pinfo->RefCount++;
}
else
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
REF_TRACE("Smart(TPtr*)");
}
@ -117,7 +117,7 @@ template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPt
REF_TRACE("~Smart()");
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
}
@ -142,7 +142,7 @@ template <class TPtr, class TKey, class TResourceFinder> CResourcePtr<TPtr, TKey
else
{
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
}
@ -179,7 +179,7 @@ template <class TPtr, class TKey, class TResourceFinder> void CResourcePtr<T>::k
// First, release the refptr.
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
// Then delete the pointer.
@ -196,7 +196,7 @@ template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPt
// Refresh the Ptr.
Ptr= (TPtr*)pinfo->Ptr;
if (pinfo != static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo))
if (pinfo != &CRefCount::NullPtrInfo)
{
// Does the pointer has been deleted ?
if (Ptr == NULL)
@ -310,7 +310,7 @@ template <class TPtr, class TKey, class TResourceFinder> void CStaticResourcePtr
// First, release the refptr.
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
// Then delete the pointer.

View file

@ -43,7 +43,7 @@ public:
/// Destructor which release pinfo if necessary.
~CRefCount();
/// Default constructor init crefs to 0.
CRefCount() { crefs = 0; pinfo=static_cast<CPtrInfo*>(&NullPtrInfo); }
CRefCount() { crefs = 0; pinfo = &NullPtrInfo; }
/* The instance handle.
Can't put those to private since must be used by CRefPtr (and friend doesn't work with template).
@ -56,6 +56,7 @@ public:
sint RefCount; // RefCount of ptrinfo (!= instance)
bool IsNullPtrInfo; // For dll problems, must use a flag to mark NullPtrInfo.
};
struct CPtrInfo : public CPtrInfoBase
{
CPtrInfo(CRefCount const* p) {Ptr=p; RefCount=0; IsNullPtrInfo=false;}
@ -75,13 +76,13 @@ public:
// Can't put this to private since must be used by CSmartPtr (and friend doesn't work with template).
// Provide incref()/decref() function doen't work since decref() can't do a delete this on a non virtual dtor.
// So Ptr gestion can only be used via CSmartPtr.
mutable sint crefs; // The ref counter for SmartPtr use.
mutable CPtrInfo *pinfo; // The ref ptr for RefPtr use.
mutable sint crefs; // The ref counter for SmartPtr use.
mutable CPtrInfoBase *pinfo; // The ref ptr for RefPtr use.
/// operator= must NOT copy crefs/pinfo!!
CRefCount &operator=(const CRefCount &) {return *this;}
/// copy cons must NOT copy crefs/pinfo!!
CRefCount(const CRefCount &) {crefs = 0; pinfo=static_cast<CPtrInfo*>(&NullPtrInfo);}
CRefCount(const CRefCount &) { crefs = 0; pinfo = &NullPtrInfo; }
};
// To use CVirtualRefPtr (or if you just want to have a RefCount with virtual destructor), derive from this class.
@ -99,7 +100,7 @@ public:
#define SMART_TRACE(_s) ((void)0)
#define REF_TRACE(_s) ((void)0)
//#define SMART_TRACE(_s) printf("%s: %d \n", _s, Ptr?Ptr->crefs:0)
//#define REF_TRACE(_s) printf("%s: %d \n", _s, pinfo!=&CRefCount::NullPtrInfo?pinfo->RefCount:0)
//#define REF_TRACE(_s) printf("%s: %d \n", _s, pinfo != &CRefCount::NullPtrInfo?pinfo->RefCount:0)
/**
@ -294,7 +295,8 @@ template <class T>
class CRefPtr
{
private:
CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object.
CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object.
mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted.
@ -380,7 +382,7 @@ template <class T>
class CVirtualRefPtr
{
private:
CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object.
CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object.
mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted.

View file

@ -134,7 +134,7 @@ SMART_INLINE void CRefPtr<T>::unRef() const
if(pinfo->Ptr)
{
// Inform the Object that no more CRefPtr points on it.
pinfo->Ptr->pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo->Ptr->pinfo = &CRefCount::NullPtrInfo;
}
// Then delete the pinfo.
delete pinfo;
@ -148,7 +148,7 @@ SMART_INLINE void CRefPtr<T>::unRef() const
// Cons - dest.
template <class T> inline CRefPtr<T>::CRefPtr()
{
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
REF_TRACE("Smart()");
@ -170,7 +170,7 @@ template <class T> inline CRefPtr<T>::CRefPtr(T *v)
#endif
}
else
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
REF_TRACE("Smart(T*)");
}
@ -187,7 +187,7 @@ template <class T> inline CRefPtr<T>::~CRefPtr(void)
REF_TRACE("~Smart()");
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
}
@ -216,7 +216,7 @@ template <class T> CRefPtr<T> &CRefPtr<T>::operator=(T *v)
else
{
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
}
@ -250,7 +250,7 @@ template <class T> void CRefPtr<T>::kill()
// First, release the refptr.
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
// Then delete the pointer.
@ -316,7 +316,7 @@ SMART_INLINE void CVirtualRefPtr<T>::unRef() const
if(pinfo->Ptr)
{
// Inform the Object that no more CVirtualRefPtr points on it.
pinfo->Ptr->pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo->Ptr->pinfo = &CRefCount::NullPtrInfo;
}
// Then delete the pinfo.
delete pinfo;
@ -330,7 +330,7 @@ SMART_INLINE void CVirtualRefPtr<T>::unRef() const
// Cons - dest.
template <class T> inline CVirtualRefPtr<T>::CVirtualRefPtr()
{
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
REF_TRACE("Smart()");
@ -352,7 +352,7 @@ template <class T> inline CVirtualRefPtr<T>::CVirtualRefPtr(T *v)
#endif
}
else
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
REF_TRACE("Smart(T*)");
}
@ -370,7 +370,7 @@ template <class T> inline CVirtualRefPtr<T>::~CVirtualRefPtr(void)
REF_TRACE("~Smart()");
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
}
@ -399,7 +399,7 @@ template <class T> CVirtualRefPtr<T> &CVirtualRefPtr<T>::operator=(T *v)
else
{
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
}
@ -435,7 +435,7 @@ template <class T> void CVirtualRefPtr<T>::kill()
// First, release the refptr.
unRef();
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
pinfo = &CRefCount::NullPtrInfo;
Ptr= NULL;
// Then delete the pointer.