hsc: Passing -1 as CString/Ptr a?

2001-11-22 Thread Volker Stolz

Hi, I want to invoke the C-function 'dlsym', which has three 
possible options for a parameter of type (void*):

- NULL
- void* to a string, i.e. CString in Haskell
- RTLD_NEXT = (void *)(-1)

The first two ones are no problem, I can use a CString and
'nullPtr'. For the last one, I have the problem that in
the Next-case I cannot write

pack :: Flag - CString
pack Null = nullPtr
pack Name str = str
pack Next = #const RTLD_NEXT

because there's no way to cast Int to a Ptr -- at least I
didn't find any. Unluckily, the C-codes (void *)(-1) even
gets expanded by hsc to the literal 4294967295 which can't be
right either.

So currently I'm facing two possible solutions:
  pack Next = nullPtr `plusPtr` 4294967295 (expanded from ... #const RTLD_NEXT)
or
  pack Next = nullPtr `plusPtr` (-1) (which is not a good idea since it doesn't
   use the C-constant)

Ptr is abstract so I cannot create this Ptr myself. Maybe the Ptr-module
just lacks a 'minusOnePtr' similar to 'nullPtr'?
-- 
Volker Stolz * [EMAIL PROTECTED] * PGP + S/MIME

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: hsc: Passing -1 as CString/Ptr a?

2001-11-22 Thread Marcin 'Qrczak' Kowalczyk

Thu, 22 Nov 2001 13:57:32 +0100, Volker Stolz [EMAIL PROTECTED] pisze:

 Hi, I want to invoke the C-function 'dlsym', which has three 
 possible options for a parameter of type (void*):
 
 - NULL
 - void* to a string, i.e. CString in Haskell
 - RTLD_NEXT = (void *)(-1)

You can obtain the value from an embedded C function.

foreign import unsafe rtldNext :: Ptr a
#def inline void *rtldNext (void) {return RTLD_NEXT;}

-- 
 __(  Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/
  ^^
QRCZAK


___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users