[Haskell-cafe] global variables for foreign C functions
Andrea Rossato
mailing_list at istitutocolli.org
Tue Dec 2 16:29:56 EST 2008
On Mon, Dec 01, 2008 at 05:30:33PM -0800, Judah Jacobson wrote:
> You can limit the size of that stub file using:
>
> foreign import ccall "&progname" progname :: Ptr (Ptr CChar)
>
> which lets you access that global variable and write the
> getters/setters in Haskell rather than C.
this solves my problems quite nicely indeed, but I still cannot figure
how to write a setter function that actually works.
That is to say, after:
newCString "new_name" >>= poke progname
this:
putStrLn . show =<< peekCString =<< peek progname
would return "new_name", but the library, which is using "progname" to
produce some debugging messages, doesn't seem to get it correctly: the
original bits are gone, but instead of "new_name" I get some garbage.
Thanks to everyone for the interesting and useful hints.
Andrea
More information about the Haskell-Cafe
mailing list