Open
Bug 1294408
Opened 8 years ago
Updated 2 years ago
Distinguish lambda uses & allocations schemes when they are created.
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
NEW
People
(Reporter: nbp, Unassigned)
References
Details
The idea is first explained in Bug 1164522 comment 16. The first idea, is to make all the allocation around mozilla::function explicit, such that the JS engine can check for OOM, as we already do for all other allocations. The second idea, is to distinguish the usage such that we can assert statically & dynamically about aliasing errors of lambdas. The following is a code example of what we might expect to use: > // use a mozilla::function input, which uses StackFunction / HeapFunction > // constructor, while increasing the reference counted lambda used as a backend. > void foo(mozilla:function f); > > void bar() > { > char a; > // Wrap a lambda, to be used as a mozilla::function with a stack allocation. > auto f = StackFunction([&] () { return a; }) > foo(f); > // Dynamically assert that we release the last reference of f, to ensure that we > // have no more stack aliases of an unwound frame. > } > > bool baz() > { > char a; > // (static analysis) ERROR: uses stack reference '[&]' in > // heap-allocated functions. > auto f = HeapFunction([&] () { return a; }); > if (!f) // Check for OOM on heap allocated functions. > return false > // Works: Uses a copy '[=]' of stack variables instead of keeping references. > auto g = HeapFunction([=] () { return a; }); > if (!g) // Check for OOM. > return false > foo(g); > return true; > }
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•