Kenichi Komiya wrote:
> 
> Hi,
> 
> I have one newbie quetion about the ownership semantics.
> 
> I noticed that following method in nsIInterfaceInfo.idl treats
> returned value in the way I do not understand.
> 
>       nsIIDPtr getIIDForParam(in PRUint16 methodIndex,
>                              [const] in nsXPTParamInfoPtr param);
> 
> In my naive understanding, all out param (and returned value for that
> matter) should be freed by the caller (unless they are shared).  But
> the implementation and clients of this interface seem to agree that
> the retruned nsIIDPtr need not be freed by caller.
> 
> I must be overlooking something obvious.  Could someone enlighten me?
> 
> Regards,
> Kenichi Komiya.

Huh? I can't speak for the PyXPCOM caller in the tree. But the
implementation in xpti and the callers in xpconnect go to a lot
of trouble to balance the cloning and freeing of the resultant
iid. You were correct in your understanding of the rules, you
just didn't dig deep enough when looking at the cases where
getIIDForParam is used.

all uses:
http://lxr.mozilla.org/seamonkey/search?string=getIIDForParam

implementation...
http://lxr.mozilla.org/seamonkey/source/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp#420

...which calls...

http://lxr.mozilla.org/seamonkey/source/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp#224

.. which copies the iid for return to the caller.

Look at a caller...
http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/src/xpcwrappedjsclass.cpp#1101

... which gets the iid and tracks whether or not the iid must be
freed and then frees it a few lines later after using it in a
call.

A quick look at one use in PyXPCOM shows it also freeing the
alloc'd iid a couple steps later.

If you can see an instance of misuse please point it out.

John.

Reply via email to