
Is still someone on haskell.org ?
---------- Forwarded message ----------
Date: Thu, 19 Feb 2009 21:40:08 +0100 (CET)
From: Henning Thielemann

On Mon, Feb 23, 2009 at 10:12 AM, Henning Thielemann
Is still someone on haskell.org ?
Sorry, I don't know :).
I want to have an advancePtr on ForeignPtr in order create a subarray. Is this reasonable and possible?
I don't think so. For example, http://www.haskell.org/ghc/docs/latest/html/libraries/bytestring/Data-ByteSt... explicitly list the offset.
Do I have to use 'touchForeignPtr' as finalizer of the subarray's ForeignPtr in order to assert that the superarray lives at least as long as the subarray?
This may work, but seems like a fragile hack. Why not data SubArray a = SA {-# UNPACK #-} !(ForeignPtr a) {-# UNPACK #-} !Int withSubArray :: SubArray a -> (Ptr a -> IO b) -> IO b withSubArray (SA fptr offset) act = withForeignPtr fptr $ \ptr -> act (ptr `plusPtr` offset) ? HTH, -- Felipe.

On Mon, 23 Feb 2009, Felipe Lessa wrote:
On Mon, Feb 23, 2009 at 10:12 AM, Henning Thielemann
wrote: Is still someone on haskell.org ?
Sorry, I don't know :).
I meant ffi@haskell.org
Do I have to use 'touchForeignPtr' as finalizer of the subarray's ForeignPtr in order to assert that the superarray lives at least as long as the subarray?
This may work, but seems like a fragile hack. Why not
data SubArray a = SA {-# UNPACK #-} !(ForeignPtr a) {-# UNPACK #-} !Int
This would work, but I want to convert from StorableVector to CArray and StorableVector has an offset parameter, which is missing in CArray.

On Mon, Feb 23, 2009 at 6:48 AM, Henning Thielemann
On Mon, 23 Feb 2009, Felipe Lessa wrote:
On Mon, Feb 23, 2009 at 10:12 AM, Henning Thielemann
wrote: Is still someone on haskell.org ?
Sorry, I don't know :).
I meant ffi@haskell.org
Do I have to use 'touchForeignPtr' as finalizer of the subarray's ForeignPtr in order to assert that the superarray lives at least as long as the subarray?
This may work, but seems like a fragile hack. Why not
data SubArray a = SA {-# UNPACK #-} !(ForeignPtr a) {-# UNPACK #-} !Int
This would work, but I want to convert from StorableVector to CArray and StorableVector has an offset parameter, which is missing in CArray.
I've used something like the following for that purpose: advanceForeignPtr :: ForeignPtr a -> Int -> IO (ForeignPtr a) advanceForeignPtr fp n = withForeignPtr fp $ \p -> newForeignPtr_ (p `advancePtr` n) -Judah

On Mon, Feb 23, 2009 at 9:02 AM, Judah Jacobson
On Mon, Feb 23, 2009 at 6:48 AM, Henning Thielemann
wrote: On Mon, 23 Feb 2009, Felipe Lessa wrote:
On Mon, Feb 23, 2009 at 10:12 AM, Henning Thielemann
wrote: Is still someone on haskell.org ?
Sorry, I don't know :).
I meant ffi@haskell.org
Do I have to use 'touchForeignPtr' as finalizer of the subarray's ForeignPtr in order to assert that the superarray lives at least as long as the subarray?
This may work, but seems like a fragile hack. Why not
data SubArray a = SA {-# UNPACK #-} !(ForeignPtr a) {-# UNPACK #-} !Int
This would work, but I want to convert from StorableVector to CArray and StorableVector has an offset parameter, which is missing in CArray.
I've used something like the following for that purpose:
advanceForeignPtr :: ForeignPtr a -> Int -> IO (ForeignPtr a) advanceForeignPtr fp n = withForeignPtr fp $ \p -> newForeignPtr_ (p `advancePtr` n)
Oops, sorry, that's definitely wrong. Probably the only fix is to use touchForeignPtr in the finalizer of the new ForeignPtr, as you said. Time to fix some of my code... :-) -Judah
participants (3)
-
Felipe Lessa
-
Henning Thielemann
-
Judah Jacobson