On 9/12/16 3:18 PM, Daniel Holbert wrote:
 (1) They guard against leaks from unused already_AddRefed.
 (2) They guard against logic errors where we should've taken the value
but forgot to do so.  (And it enforces that callees must take the value,
even if they have some error handling cases where they'd prefer not to.)

Right.

So I think (1) is irrelevant here

I agree.

It brings up one potential concern with Move: since the
callee might not take the value (intentionally or unintentionally), the
caller must *refrain* from caring about the state of its Move()'d
variable, between the Move() operation and any reassignment/cleanup.

It's worse than that. For a wide range of callers (anyone handing the ref across threads), the caller must check immediately whether the callee actually took the value and if not make sure things are released on the proper thread...

I guess my bottom-line question is: which pattern should I prefer, for
new code that wants to trivially transfer ownership of a refcounted
object into a function or a constructor?

Are threads involved?  ;)

My gut feeling is that we should use the safer pattern with already_AddRefed just so people don't start using the other pattern in anything resembling multithreaded code, though in your particular case both patterns would be fine...

-Boris
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to