Re: Ptr and ForeignPtr Questions

2001-10-10 Thread Ashley Yakeley
At 2001-10-10 01:19, I wrote: >foreign import "foo" raw_foo :: Ptr () -> IO (Ptr ()); > >foo :: Ptr SomeLinkedList -> IO (ConstPtr Char); >foo = importFunction raw_foo; Actually I don't need to convert the pointers, do I? If I have (Storable SomeLinkedList), I can just declare

Re: Ptr and ForeignPtr Questions

2001-10-10 Thread Ashley Yakeley
At 2001-09-23 23:54, I wrote: >As you point out, there are restrictions >on just what existing C functions you can bind to. If your function looks >like this: > > const char* foo (struct SomeLinkedList*); > >...you have no choice but to write 'impedance-matching' code for that >function.

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Ashley Yakeley
At 2001-09-23 23:12, Manuel M. T. Chakravarty wrote: >> I was just hoping for GHC to be able to spit out headers for 'foreign >> import' functions that the user could then define. This merely means a >> map from some restricted set of Haskell function types to C types. > >Functionality like tha

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-23 19:14, Manuel M. T. Chakravarty wrote: > > >Hmm, we must be misunderstanding each other. Given that you > >have > > > > foreign import strcat :: Ptr CChar -> Ptr CChar -> IO (Ptr CChar) > > > >How do you want to know whether the C proto

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Ashley Yakeley
At 2001-09-23 19:14, Manuel M. T. Chakravarty wrote: >Hmm, we must be misunderstanding each other. Given that you >have > > foreign import strcat :: Ptr CChar -> Ptr CChar -> IO (Ptr CChar) > >How do you want to know whether the C prototype is > > char *strcat(char *dest, const char *src)

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-23 04:04, Marcin 'Qrczak' Kowalczyk wrote: > > >It would be impossible then to directly call a C function with a > >parameter declared as a const pointer. It's illegal in C to have > >mismatching prototypes of the same function. > > You can

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-23 04:02, Manuel M. T. Chakravarty wrote: > > >> I would assume that Ptr types would always be mapped to non-const > >> pointers. Do you have an example of a Haskell type for a foreign import > >> function, for which the corresponding C fu

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Ashley Yakeley
At 2001-09-23 15:56, Marcin 'Qrczak' Kowalczyk wrote: >> But do you have an example of a Haskell type for a foreign import >> function, for which the corresponding C function type would be ambiguous? > >Ptr CChar (as an argument). It could be either char * or const char *. It's always char*. A

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Ashley Yakeley
At 2001-09-23 04:04, Marcin 'Qrczak' Kowalczyk wrote: >It would be impossible then to directly call a C function with a >parameter declared as a const pointer. It's illegal in C to have >mismatching prototypes of the same function. You can always do this: module MyModule where { f

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Marcin 'Qrczak' Kowalczyk
Sun, 23 Sep 2001 15:41:41 -0700, Ashley Yakeley <[EMAIL PROTECTED]> pisze: > But do you have an example of a Haskell type for a foreign import > function, for which the corresponding C function type would be ambiguous? Ptr CChar (as an argument). It could be either char * or const char *. --

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Ashley Yakeley
At 2001-09-23 04:02, Manuel M. T. Chakravarty wrote: >> I would assume that Ptr types would always be mapped to non-const >> pointers. Do you have an example of a Haskell type for a foreign import >> function, for which the corresponding C function type would be ambiguous? > >Take, for example,

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Marcin 'Qrczak' Kowalczyk
Sun, 23 Sep 2001 02:04:49 -0700, Ashley Yakeley <[EMAIL PROTECTED]> pisze: > I would assume that Ptr types would always be mapped to non-const > pointers. It would be impossible then to directly call a C function with a parameter declared as a const pointer. It's illegal in C to have mismatchin

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-23 00:45, Manuel M. T. Chakravarty wrote: > > >No, unfortunately not. Consider, for example, that storage > >qualifiers would have to be generated correctly and there is > >no way to determine form a Haskell type whether a `const' > >modifi

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Ashley Yakeley
At 2001-09-23 00:45, Manuel M. T. Chakravarty wrote: >No, unfortunately not. Consider, for example, that storage >qualifiers would have to be generated correctly and there is >no way to determine form a Haskell type whether a `const' >modifier needs to be added. I would assume that Ptr types wo

Re: Ptr and ForeignPtr Questions

2001-09-23 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-21 02:20, Manuel M. T. Chakravarty wrote: > > >One could attempt to generate C prototypes from the Haskell > >type declarations or similar things, btu it doesn't work > >out. > > Why not? Isn't there a straightforward type map? No, unfortu

Re: Ptr and ForeignPtr Questions

2001-09-21 Thread Ashley Yakeley
At 2001-09-21 02:20, Manuel M. T. Chakravarty wrote: >One could attempt to generate C prototypes from the Haskell >type declarations or similar things, btu it doesn't work >out. Why not? Isn't there a straightforward type map? -- Ashley Yakeley, Seattle WA __

Re: Ptr and ForeignPtr Questions

2001-09-21 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-21 01:39, Manuel M. T. Chakravarty wrote: > > >That's ok. All I am saying is that the FFI doesn't ensure > >any concistency between the Haskell and the C type. > > Well it can't can it? There's no type information in object-code symbols >

Re: Ptr and ForeignPtr Questions

2001-09-21 Thread Ashley Yakeley
At 2001-09-21 01:39, Manuel M. T. Chakravarty wrote: >That's ok. All I am saying is that the FFI doesn't ensure >any concistency between the Haskell and the C type. Well it can't can it? There's no type information in object-code symbols (unless you use C++ identifier mangling, which Haskell d

Re: Ptr and ForeignPtr Questions

2001-09-21 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-20 19:32, Manuel M. T. Chakravarty wrote: > > >What I meant with the remark that you quote is that if you > >would use > > > > foreign import foo :: Ptr Int -> IO Float > > > >with > > > > float foo (float *x) > > { > >return *x; > >

Re: Ptr and ForeignPtr Questions

2001-09-20 Thread Ashley Yakeley
At 2001-09-20 19:32, Manuel M. T. Chakravarty wrote: >What I meant with the remark that you quote is that if you >would use > > foreign import foo :: Ptr Int -> IO Float > >with > > float foo (float *x) > { >return *x; > } > >the system will not complain, but your program may dump >core.

Re: Ptr and ForeignPtr Questions

2001-09-20 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-20 06:55, Manuel M. T. Chakravarty wrote: > > >The FFI does not ensure any type consistency between the > >arguments to `Ptr'/`ForeignPtr' and the corresponding C > >types. > > I've been using 'Ptr Word8' with newArray to pass lists of byte

Re: Ptr and ForeignPtr Questions

2001-09-20 Thread Ashley Yakeley
At 2001-09-20 06:55, Manuel M. T. Chakravarty wrote: >The FFI does not ensure any type consistency between the >arguments to `Ptr'/`ForeignPtr' and the corresponding C >types. I've been using 'Ptr Word8' with newArray to pass lists of bytes to C functions. They appear as unsigned char arrays in

Re: Ptr and ForeignPtr Questions

2001-09-20 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > At 2001-09-19 23:45, Manuel M. T. Chakravarty wrote: > > >> What if the type is polymorphic (e.g. > >> declared as 'Storable a => Ptr a' rather than something like 'Ptr Word8')? > > > >Also possible, as the argument to `Ptr' is just dummy. > > What?

RE: Ptr and ForeignPtr Questions

2001-09-20 Thread Ashley Yakeley
At 2001-09-20 02:46, Simon Marlow wrote: >No, it's not safe. The reason is that the compiler can track a >ForeignPtr to discover when it dies, in order to run the finalizer, but >it can't track a Ptr. As soon as you drop all references to the >ForeignPtr then the finalizer will run, even if you

RE: Ptr and ForeignPtr Questions

2001-09-20 Thread Simon Marlow
> At 2001-09-20 02:14, Simon Marlow wrote: > > >I'll just add that the docs have been updated for 5.02, > > Do you have a URL for that? Not yet, but the release is imminent (really!) so it'll be up on the web site shortly. > >And don't forget that using foreignPtrToPtr is quite dangerous; much

Re: Ptr and ForeignPtr Questions

2001-09-20 Thread Ashley Yakeley
At 2001-09-20 02:31, I wrote: >int foo (char selector,char* arg) ... > if (selector == 200) I guess that should be int foo (unsigned char selector,char* arg) -- Ashley Yakeley, Seattle WA ___ Glasgow-haskell-users mailing list [E

RE: Ptr and ForeignPtr Questions

2001-09-20 Thread Ashley Yakeley
At 2001-09-20 02:14, Simon Marlow wrote: >I'll just add that the docs have been updated for 5.02, Do you have a URL for that? >And don't forget that using foreignPtrToPtr is quite dangerous; much >better to use withForeignPtr instead, otherwise you might find the >ForeignPtr being finalised ear

Re: Ptr and ForeignPtr Questions

2001-09-20 Thread Ashley Yakeley
At 2001-09-19 23:45, Manuel M. T. Chakravarty wrote: >> What if the type is polymorphic (e.g. >> declared as 'Storable a => Ptr a' rather than something like 'Ptr Word8')? > >Also possible, as the argument to `Ptr' is just dummy. What? What about 'withObject'? A Haskell 'Ptr a' is a C array-poi

RE: Ptr and ForeignPtr Questions

2001-09-20 Thread Simon Marlow
> Ashley Yakeley <[EMAIL PROTECTED]> wrote, > > > The documentation for FFI in the GHC user's guide seems to > be out of date > > with regard to passing Ptrs across. > > > > 1. My reference is > > > > (from >

Re: Ptr and ForeignPtr Questions

2001-09-19 Thread Manuel M. T. Chakravarty
Ashley Yakeley <[EMAIL PROTECTED]> wrote, > The documentation for FFI in the GHC user's guide seems to be out of date > with regard to passing Ptrs across. > > 1. My reference is > > (from

Ptr and ForeignPtr Questions

2001-09-19 Thread Ashley Yakeley
The documentation for FFI in the GHC user's guide seems to be out of date with regard to passing Ptrs across. 1. My reference is (from ) Is this the latest documentation avail