On 2014-12-22 4:56 PM, L. David Baron wrote:
On Monday 2014-12-22 16:10 -0500, Jeff Muizelaar wrote:
We were talking about this problem and it was a bunch of work to figure out the 
conclusion so I decided to write a summary:

Replacing already_AddRefed with nsRefPtr causes allows two new things:

nsRefPtr<T> getT();

1. T* p = getT(); // this is unsafe because the destructor runs immediately and 
p is left dangling
2. foo(getT()); // this is safe

Possible solutions would be to:
  - remove implicit conversions to T*
  - add operator T* explicit and operator T* && = delete // this will be 
available in GCC 4.8.1 and MSVC 2014 Nov CTP

I think removing implicit conversions to T* will make a lot of code
in the tree uglier (".get()" everywhere).  That might, in turn,
encourage people to do worse things to avoid having to write .get()
everywhere; it's worth thinking about what those things will be.

Do you have any examples of those bad things? (FWIW I'm all for making bad things impossible.)

(I think it's also worth thinking about the *massive* number of
callsites that will need to be fixed if we remove implicit
conversion to T*.)

I am planning to write a tool for this task, so the number of call sites will not be a prohibitive issue.

I'd also like to keep nsRefPtr and nsCOMPtr consistent with each
other in this regard, to avoid people having to learn additional
patterns.

Sure. I think we should remove the implicit conversion from both at the same time. And from RefPtr too.

> (And, on that subject, I think development practice in
MFBT has been too readily adding new and different things instead of
moving the existing things from XPCOM into MFBT and then improving
them incrementally.)

I completely agree. The amount of pain that RefPtr.h has caused is hard to overstate, for example. :-)
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to