Slightly safer and neater fix for strict aliasing bug 351231 r+sr=dbaron
authorneil@parkwaycc.co.uk
Fri, 23 Mar 2007 13:26:20 -0700
changeset 46 f46b6f5b34eb043c0ca8afe43649edae5d6f5090
parent 45 c01bca2edc43561407cc34031e94a1033ac10d3d
child 47 22b4635ef2811a3b7380aac470e0e883f87eb006
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs351231
milestone1.9a3pre
Slightly safer and neater fix for strict aliasing bug 351231 r+sr=dbaron
xpcom/glue/nsCOMPtr.cpp
xpcom/glue/nsCOMPtr.h
--- a/xpcom/glue/nsCOMPtr.cpp
+++ b/xpcom/glue/nsCOMPtr.cpp
@@ -87,74 +87,74 @@ nsCOMPtr_base::assign_with_AddRef( nsISu
     if ( rawPtr )
     	NSCAP_ADDREF(this, rawPtr);
     assign_assuming_AddRef(rawPtr);
 	}
 
 void
 nsCOMPtr_base::assign_from_qi( const nsQueryInterface qi, const nsIID& iid )
   {
-    union { nsISupports *mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( qi(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( qi(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void
 nsCOMPtr_base::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& iid )
   {
-    union { nsISupports* mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( qi(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( qi(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void
 nsCOMPtr_base::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& iid )
   {
-    union { nsISupports* mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void
 nsCOMPtr_base::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& iid )
   {
-    union { nsISupports* mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void
 nsCOMPtr_base::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& iid )
   {
-    union { nsISupports* mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void
 nsCOMPtr_base::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& iid )
   {
-    union { nsISupports* mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void
 nsCOMPtr_base::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& iid )
   {
-    union { nsISupports* mSupports; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( helper(iid, &newRawPtr.mVoid) ) )
-      newRawPtr.mSupports = 0;
-    assign_assuming_AddRef(newRawPtr.mSupports);
+    void* newRawPtr;
+    if ( NS_FAILED( helper(iid, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(nsISupports*, newRawPtr));
   }
 
 void**
 nsCOMPtr_base::begin_assignment()
   {
     assign_assuming_AddRef(0);
     return NS_REINTERPRET_CAST(void**, &mRawPtr);
   }
--- a/xpcom/glue/nsCOMPtr.h
+++ b/xpcom/glue/nsCOMPtr.h
@@ -1235,80 +1235,80 @@ nsCOMPtr<T>::assign_with_AddRef( nsISupp
       NSCAP_ADDREF(this, rawPtr);
     assign_assuming_AddRef(NS_REINTERPRET_CAST(T*, rawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_qi( const nsQueryInterface qi, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( qi(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( qi(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( qi(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( qi(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( gs(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( gs(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void
 nsCOMPtr<T>::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& aIID )
   {
-    union { T* mT; void *mVoid; } newRawPtr;
-    if ( NS_FAILED( helper(aIID, &newRawPtr.mVoid) ) )
-      newRawPtr.mT = 0;
-    assign_assuming_AddRef(newRawPtr.mT);
+    void* newRawPtr;
+    if ( NS_FAILED( helper(aIID, &newRawPtr) ) )
+      newRawPtr = 0;
+    assign_assuming_AddRef(NS_STATIC_CAST(T*, newRawPtr));
   }
 
 template <class T>
 void**
 nsCOMPtr<T>::begin_assignment()
   {
     assign_assuming_AddRef(0);
     union { T** mT; void** mVoid; } result;