Ticket #8748: ghc-7.8.1_rc1-fix-UNREG-threaded.patch

File ghc-7.8.1_rc1-fix-UNREG-threaded.patch, 1.9 KB (added by slyfox, 4 years ago)

ghc-7.8.1_rc1-fix-UNREG-threaded.patch - finally fix -threaded RTS in unreg mode

  • rts/Capability.c

    commit 97bc9663c9f7310668c013d3c03d546c0bd546b0
    Author: Sergei Trofimovich <slyfox@gentoo.org>
    Date:   Mon Feb 10 15:55:25 2014 +0300
    
        rts/Capability.c: fix crash in -threaded mode on UNREG build
        
        UNREG mode has quite nasty invariant to maintain:
            capabilities[0] == &MainCapability
        
        and it's a non-heap memory, while other
        capabilities are dynamically allocated.
        
        Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
    
    diff --git a/rts/Capability.c b/rts/Capability.c
    index 5988d42..16b71b7 100644
    a b moreCapabilities (nat from USED_IF_THREADS, nat to USED_IF_THREADS) 
    357357        // BaseReg (eg. unregisterised), so in this case
    358358        // capabilities[0] must coincide with &MainCapability.
    359359        capabilities[0] = &MainCapability;
     360        initCapability(&MainCapability, 0);
    360361    }
    361 
    362     for (i = 0; i < to; i++) {
    363         if (i < from) {
    364             capabilities[i] = old_capabilities[i];
    365         } else {
    366             capabilities[i] = stgMallocBytes(sizeof(Capability),
    367                                              "moreCapabilities");
    368             initCapability(capabilities[i], i);
     362    else
     363    {
     364        for (i = 0; i < to; i++) {
     365            if (i < from) {
     366                capabilities[i] = old_capabilities[i];
     367            } else {
     368                capabilities[i] = stgMallocBytes(sizeof(Capability),
     369                                                 "moreCapabilities");
     370                initCapability(capabilities[i], i);
     371            }
    369372        }
    370373    }
    371374
    freeCapabilities (void) 
    983986    nat i;
    984987    for (i=0; i < n_capabilities; i++) {
    985988        freeCapability(capabilities[i]);
    986         stgFree(capabilities[i]);
     989        if (capabilities[i] != &MainCapability)
     990            stgFree(capabilities[i]);
    987991    }
    988992#else
    989993    freeCapability(&MainCapability);