On Fri, Apr 10, 2015 at 10:37 AM, Ehsan Akhgari <ehsan.akhg...@gmail.com>
wrote:

> On 2015-04-10 12:33 PM, Andrew McCreight wrote:
>
>>
>>
>> On Fri, Apr 10, 2015 at 8:46 AM, Ehsan Akhgari <ehsan.akhg...@gmail.com
>> <mailto:ehsan.akhg...@gmail.com>> wrote:
>>
>>     I would like to propose that we should ban the usage of refcounted
>>     objects
>>     inside lambdas in Gecko.  Here is the reason:
>>
>>     Consider the following code:
>>
>>     nsINode* myNode;
>>     TakeLambda([&]() {
>>        myNode->Foo();
>>     });
>>
>>
>> How is this any worse than any other usage of raw pointers on the stack?
>>
>> nsINode* myNode;
>> doSomething();
>> myNode->Foo();
>>
>> is the same thing.
>>
>
> It is worse since the lambda may be held on to and executed later in the
> future (i.e., past the point in time when the function returns.)
>
> But also do note that raw pointers to refcounted objects on the stack are
> very dangerous as well (for example in your above code, doSomething() could
> destroy myNode.
>
>  I also don't see how "don't use any refcounted objects inside lambdas"
>> is any easier to enforce.
>>
>
> It's easier because we don't yet have piles of code which have this
> pattern in them.  I would like to prevent us getting there so that we don't
> have to start solving this issue on a massive scale in a few years once we
> grow more lambda usage.
>
>  I also don't see why refcounted objects in particular are worth of
>> exclusion based on their lifetime in closures, but not references to
>> other allocated things.  I guess we don't have local variables like
>> |nsTArray<Foo>* myArray;| as often, but that would be just as dangerous.
>>
>
>
Yes, I have nothing against coming up with further restrictions to make
> more things safe, but mentioning other dangerous things is not an argument
> against this proposal.  ;-)
>

Well, I don't really see what is difficult about this in particular, but
I've been writing code in functional programming languages for a long time,
so maybe I'm just used to the lifetime issues around closures already.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to