stgAllocForGMP and friends
pumpkingod at gmail.com
Fri Jun 5 04:07:36 EDT 2009
I'm almost done with a FFI-based GMP binding (an attempt to remove
GHC's dependence on GMP primops). Currently I'm just using the default
GMP allocation functions (malloc/realloc/free), but it's tempting to
do as the current setup does and tell GMP to use the GHC allocator. I
have some questions about this:
1) stgAllocForGMP from rts/sm/Storage.c seems relatively general.
Maybe it, along with realloc and free (a dummy function?), could be
renamed externalAlloc and be "exported" (made non-static) to allow for
FFI bindings to call back into GHC's allocator (several libs allow
callers to override the default allocation functions)?
2) stgReallocForGMP currently appears to contain a manual memcpy (with
a for loop copying individual bytes). Is this for a specific reason?
3) If I do point my GMP binding to use the GHC allocator, would that
count as "calling back into haskell"? I really don't want to have to
mark any GMP function that may allocate as "safe" in my foreign import
declarations, but if it needs it there's not much I can do about it.
My integer benchmark suite should tell if it's necessary, anyway.
More information about the Cvs-ghc