XPCOMGC/Stack Pointers: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 12: Line 12:
<pre>  nsFoo::Function(nsISupports* gah)
<pre>  nsFoo::Function(nsISupports* gah)
   {
   {
    //rewrite stack declarations
-  nsCOMPtr<nsIBar> bar;
-  nsCOMPtr<nsIBar> bar;
+  nsIBar* bar;
+  nsIBar* bar;
    
    
    // support multi-var declarations
-  nsCOMPtr<nsIBaz> boo, gahbaz = do_QueryInterface(gah);
-  nsCOMPtr<nsIBaz> boo, gahbaz = do_QueryInterface(gah);
+  nsIBaz* boo, *gahbaz = do_QueryInterface(gah);
+  nsIBaz* boo, *gahbaz = do_QueryInterface(gah);


    // Don't use getter_AddRefs for stack variables
-  nsresult rv = gahbaz->GetBar(getter_AddRefs(bar));
-  nsresult rv = gahbaz->GetBar(getter_AddRefs(bar));
+  nsresult rv = gahbaz->GetBar(&bar);
+  nsresult rv = gahbaz->GetBar(&bar);
    // Make the getter_AddRefs downcasting magic explicit
-  Function(getter_AddRefs(boo));
+  Function((nsISupports**)&boo);
   
    // keep heap-allocated variables untouched
    gahbaz->GetBar(getter_AddRefs(mClassMember));
   }</pre>
   }</pre>
Confirmed users
381

edits