XPCOMGC/Stack Pointers: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 15: Line 15:
+  nsIBar* bar;
+  nsIBar* bar;
    
    
-  nsCOMPtr<nsIBaz> gahbaz = do_QueryInterface(gah);
-  nsCOMPtr<nsIBaz> boo, gahbaz = do_QueryInterface(gah);
+  nsIBaz* gahbaz = do_QueryInterface(gah);
+  nsIBaz* boo, *gahbaz = do_QueryInterface(gah);


-  nsresult rv = gahbaz->GetBar(getter_AddRefs(bar));
-  nsresult rv = gahbaz->GetBar(getter_AddRefs(bar));
+  nsresult rv = gahbaz->GetBar(&bar);
+  nsresult rv = gahbaz->GetBar(&bar);
   }</pre>
   }</pre>

Revision as of 22:09, 12 October 2007

Automatic rewriting spec for XPCOMGC:

Detect every instance of nsCOMPtr that is used as a stack variable, and rewrite it to be a raw pointer.

  • Remove use of getter_AddRefs with these objects.
  • Rewrite nsCOMPtr::swap()
  • Remove nsCOMPtr::get() for stack vars
  • Function return values & parameters are part of the stack
    • Rewrite already_AddRefed<Foo> return values
    • Rewrite nsCOMPtr &bla parameters

e.g.

  nsFoo::Function(nsISupports* gah)
  {
-   nsCOMPtr<nsIBar> bar;
+   nsIBar* bar;
  
-   nsCOMPtr<nsIBaz> boo, gahbaz = do_QueryInterface(gah);
+   nsIBaz* boo, *gahbaz = do_QueryInterface(gah);

-   nsresult rv = gahbaz->GetBar(getter_AddRefs(bar));
+   nsresult rv = gahbaz->GetBar(&bar);
  }