예제 #1
0
파일: HsFFI.c 프로젝트: 23Skidoo/ghc
void
hs_free_stable_ptr(HsStablePtr sp)
{
    /* The cast is for clarity only, both HsStablePtr and StgStablePtr are
       typedefs for void*. */
    freeStablePtr((StgStablePtr)sp);
}
예제 #2
0
void
freeHaskellFunctionPtr(void* ptr)
{
    ffi_closure *cl;

    cl = (ffi_closure*)ptr;
    freeStablePtr(cl->user_data);
    stgFree(cl->cif->arg_types);
    stgFree(cl->cif);
    freeExec(cl);
}
예제 #3
0
파일: Globals.c 프로젝트: alexbiehl/ghc
void
exitGlobalStore(void)
{
    uint32_t i;
#ifdef THREADED_RTS
    closeMutex(&globalStoreLock);
#endif
    for (i=0; i < MaxStoreKey; i++) {
        if (store[i] != 0) {
            freeStablePtr(store[i]);
            store[i] = 0;
        }
    }
}
예제 #4
0
파일: Adjustor.c 프로젝트: AnalogFile/ghc
/* There are subtle differences between how libffi adjustors work on
 * different platforms, and the situation is a little complex.
 * 
 * HOW ADJUSTORS/CLOSURES WORK ON LIBFFI:
 * libffi's ffi_closure_alloc() function gives you two pointers to a closure,
 * 1. the writable pointer, and 2. the executable pointer. You write the
 * closure into the writable pointer (and ffi_prep_closure_loc() will do this
 * for you) and you execute it at the executable pointer.
 *
 * THE PROBLEM:
 * The RTS deals only with the executable pointer, but when it comes time to
 * free the closure, libffi wants the writable pointer back that it gave you
 * when you allocated it.
 *
 * On Linux we solve this problem by storing the address of the writable
 * mapping into itself, then returning both writable and executable pointers
 * plus 1 machine word for preparing the closure for use by the RTS (see the
 * Linux version of allocateExec() in rts/sm/Storage.c). When we want to
 * recover the writable address, we subtract 1 word from the executable
 * address and fetch. This works because Linux kernel magic gives us two
 * pointers with different addresses that refer to the same memory. Whatever
 * you write into the writeable address can be read back at the executable
 * address. This method is very efficient.
 *
 * On iOS this breaks for two reasons: 1. the two pointers do not refer to
 * the same memory (so we can't retrieve anything stored into the writable
 * pointer if we only have the exec pointer), and 2. libffi's
 * ffi_closure_alloc() assumes the pointer it has returned you is a
 * ffi_closure structure and treats it as such: It uses that memory to
 * communicate with ffi_prep_closure_loc(). On Linux by contrast
 * ffi_closure_alloc() is viewed simply as a memory allocation, and only
 * ffi_prep_closure_loc() deals in ffi_closure structures. Each of these
 * differences is enough make the efficient way used on Linux not work on iOS.
 * Instead on iOS we use hash tables to recover the writable address from the
 * executable one. This method is conservative and would almost certainly work
 * on any platform, but on Linux it makes sense to use the faster method.
 */
void
freeHaskellFunctionPtr(void* ptr)
{
    ffi_closure *cl;

#if defined(ios_HOST_OS)
    cl = execToWritable(ptr);
#else
    cl = (ffi_closure*)ptr;
#endif
    freeStablePtr(cl->user_data);
    stgFree(cl->cif->arg_types);
    stgFree(cl->cif);
    freeExec(ptr);
}
예제 #5
0
static void freeSptEntry(void* entry) {
  freeStablePtr(*(StgStablePtr*)entry);
  stgFree(entry);
}
void FrequencyQueue::free_all_pointers(){

    for (auto it = this->internal_vector.begin() ; it != this->internal_vector.end(); ++it){
        freeStablePtr((*it).element);
    }    
}