Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  data-files for test-suite (harry)
   2. Re:  FFI, export a ByteString (Antoine Latter)


----------------------------------------------------------------------

Message: 1
Date: Sun, 2 Jun 2013 13:12:53 +0000 (UTC)
From: harry <[email protected]>
Subject: [Haskell-beginners] data-files for test-suite
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

My cabal file has a test-suite section which requires an input file. I can
get it with data-files and getDataFileName, but presumably this will be
installed with the package. However, I only need it for running the
exitcode-stdio-1.0. Is there another way of accessing test data?




------------------------------

Message: 2
Date: Sun, 2 Jun 2013 09:53:28 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] FFI, export a ByteString
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAKjSnQGN0q=94d8snqvazgsh4knvbjejeag43ampfmpn+x8...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

The function 'castStablePtrToPtr' does not actually return a pointer
you can usefully de-reference in C - it just gives you a value that
will fit into a 'void*' in C-land.

A StablePtr is, conceptually, just a pointer-sized index into an array
maintained by the Haskell runtime, you can only de-reference it in
Haskell. But you can pass it around in C because it fits into a
pointer-sized variable or struct member.

On Thu, Apr 11, 2013 at 10:59 AM, Kees Bleijenberg
<[email protected]> wrote:
> My function in Haskell takes a CString and returns a ByteString (of Word8).
>
> I tried to put this function in a Haskell made Windows dll.  I want to use
> this function in a program written in C.
>
>
>
> The most simple program  that compiled was:
>
>
>
> Import qualified B.ByteString as B
>
> import Foreign.StablePtr
>
> import Foreign.C.String
>
> import Foreign.Ptr
>
>
>
> foreign export stdcall parseRuitType :: CString -> IO (Ptr ())
>
> parseRuitType s = do
>
>                             p <- (newStablePtr ( B.pack [10,11,12]))
>
>                             return $ castStablePtrToPtr p
>
>
>
> For testing I ignore s.
>
>
>
> In the C-program :
>
> hs_init(NULL,NULL)
>
> res = parseRuitType (?5? )
>
> No errors, but the returned value res (or the dereferenced res) makes no
> sense (not 10,11,12).
>
>
>
> My idea was: the result of the function(a ByteString of Word8) must be
> locked. No garbage collection. But newStablePtr does not return a pointer.
> So I have to convert the newStablePtr to a real pointer and then coerce this
> in the C program to a pointer to  a array of word8??
>
> I?ve tried to return the ByteString  in the Haskell function. But now the
> compiler complains: Unacceptable result type in foreign declaration :
> B.ByteString
>
>
>
> I?am missing the big picture.  Any ideas?
>
>
>
> Greetings
>
> Kees
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 60, Issue 4
****************************************

Reply via email to