Re: refcounting - which types to use ?

2017-08-28 Thread Boris Zbarsky
On 8/16/17 6:56 AM, Enrico Weigelt, metux IT consult wrote: I'd assume that do_CreateInstance() returns the object w/ refcnt=1. Yes. It returns it as an already_AddRefed<> struct. The assignment to nsCOMPtr should increase refcount. Correct ? No, because nsCOMPtr knows not to increase the

Re: refcounting - which types to use ?

2017-08-26 Thread Ehsan Akhgari
On 08/24/2017 06:04 AM, jyaven...@mozilla.com wrote: On Thursday, August 24, 2017 at 11:56:53 AM UTC+2, James Cheng wrote: How could I make it compile error? I did write RefPtr xxx = yyy; xxx.forget(); You need to run the static analyser. The documentation about MOZ_MUST_USE_TYPE is explaine

Re: refcounting - which types to use ?

2017-08-24 Thread jyavenard
On Thursday, August 24, 2017 at 11:56:53 AM UTC+2, James Cheng wrote: > How could I make it compile error? > > I did write > > RefPtr xxx = yyy; > xxx.forget(); You need to run the static analyser. The documentation about MOZ_MUST_USE_TYPE is explained there http://searchfox.org/mozilla-centra

Re: refcounting - which types to use ?

2017-08-24 Thread James Cheng
How could I make it compile error? I did write RefPtr xxx = yyy; xxx.forget(); It is ok for compiling on my Mac. The comment [1] said " Makes it a compile time error to not use the return value of a function which has this type", but how do I make the clang format take effect? BTW, if you want

Re: refcounting - which types to use ?

2017-08-24 Thread jyavenard
On Thursday, August 17, 2017 at 1:02:56 PM UTC+2, Aryeh Gregor wrote: > Note that in this case you cannot ignore the return value -- it must > be assigned to an nsCOMPtr or a RefPtr, or else it will leak. Ideally > we would allow a return type of nsCOMPtr&&, but > currently I think we don't. This

Re: refcounting - which types to use ?

2017-08-17 Thread Aryeh Gregor
On Thu, Aug 17, 2017 at 7:07 AM, Enrico Weigelt, metux IT consult wrote: > OTOH, is there a way to create versions that really return it as rval, > so I conveniently could just call like that ? > >nsCOMPtr list = addrbook->FindRecipients(addr); You can do this with a return type of already_Ad

Re: refcounting - which types to use ?

2017-08-16 Thread Enrico Weigelt, metux IT consult
On 17.08.2017 04:03, Shih-Chiang Chien wrote: You should use |forget| to transfer the ownership of the nsIArray from list to _retval. Ok, thanks. Already suspected that (found some similar things in the code). Could we update the docs (maybe some set of examples) ? IIRC, there're some places t

Re: refcounting - which types to use ?

2017-08-16 Thread Shih-Chiang Chien
You should use |forget| to transfer the ownership of the nsIArray from list to _retval. /* nsIArray FindRecipients (in AString name); */ NS_IMETHODIMP nsAddrBookService::FindRecipients(const nsAString & addr, nsIArray * *_retval) { nsresult rv = NS_OK; nsCOMPtr list = do_CreateInst

refcounting - which types to use ?

2017-08-16 Thread Enrico Weigelt, metux IT consult
Hi folks, I'm still a bit confused on which types (nsCOMPtr, ...) to use when exactly, in combination w/ IDLs. Let's consider a case where an nsArray is created and returned (as rval, not out-parameter): IDL: [scriptable, uuid(ea0d8b3d-a549-4666-82d8-3a82cee2a3f1)] interface nsIAddrBookServic