[Issue 10509] New: Closure is allocated even if it may be not needed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 30 05:52:07 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10509

           Summary: Closure is allocated even if it may be not needed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-06-30 16:52:06 MSD ---
The allocation is done eager but can be lazy:
---
bool noAllocations = false;

extern(C) void* gc_malloc(size_t sz, uint ba = 0);

extern(C) void* _d_allocmemory(size_t sz)
{
    assert(!noAllocations); // fails
    return gc_malloc(sz);
}

int delegate() del;

void f(int i)
{
    if(i)
        del = () => i;
}

void main()
{
    noAllocations = true;
    f(0);
    noAllocations = false;
}
---

This hits with pain as one do not expect such behaviour and can e.g. branch out
closures in destructors expecting no allocation is done and then get strange
InvalidMemoryOperationError-s when GC is collecting.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list