Closed
Bug 776358
Opened 12 years ago
Closed 9 years ago
RefPtr should implement an already_AddRefed() constructor
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
RESOLVED
DUPLICATE
of bug 1121489
People
(Reporter: ekr, Unassigned)
Details
Note that nsRefPtr has this:
template <typename I>
nsRefPtr( const already_AddRefed<I>& aSmartPtr )
: mRawPtr(aSmartPtr.mRawPtr)
// construct from |dont_AddRef(expr)|
{
}
But RefPtr does not appear to.
Reporter | ||
Updated•12 years ago
|
OS: Mac OS X → All
Hardware: x86 → All
Comment 1•12 years ago
|
||
I don't think it's a good idea to encourage mixing MFBT RefPtr and XPCOM smart pointers.
Reporter | ||
Comment 2•12 years ago
|
||
Well, if that's not desirable then they shouldn't use the same reference increment/decrement operators.
Since they do, I think the ship has already sailed on that.
Comment 3•12 years ago
|
||
Reporter | ||
Comment 4•12 years ago
|
||
Sure.
My general principle here is that if things are invariants, then they should be enforced by the compiler where possible. Hence, if we don't want people mixing MFBT RefPtr and XPCOM smart pointers, then RefPtr<T> shouldn't use AddRef() and Release(), but rather some other functions, even if they do the same thing as AddRef() and Release(). E.g., RefPtrAddRef(), RefPtrRelease(). That way the compiler would stop you from using the MFBT and XPCOM smart pointers on the same objects (or at least it would be a lot harder. I could imagine further template trickery to make it effectively impossible). It's the fact that the different varieties of ref-counted pointers use the same interface that encourages mixing, not the existence/non-existence of already_AddRefed.
Conversely, if the interfaces are to be compatible, then each of the ref-counted pointer classes should be complete, which in this case means having an already_AddRefed constructor variant.
Updated•9 years ago
|
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•