-- |
-- Module      : Data.Vector.Storable.Internal
-- Copyright   : (c) Roman Leshchinskiy 2009-2010
-- License     : BSD-style
--
-- Maintainer  : Roman Leshchinskiy <rl@cse.unsw.edu.au>
-- Stability   : experimental
-- Portability : non-portable
--
-- Ugly internal utility functions for implementing 'Storable'-based vectors.
--

module Data.Vector.Storable.Internal (
  getPtr, setPtr, updPtr
) where

import Foreign.ForeignPtr ()
import Foreign.Ptr        ()
import GHC.ForeignPtr   ( ForeignPtr(..) )
import GHC.Ptr          ( Ptr(..) )

getPtr :: ForeignPtr a -> Ptr a
{-# INLINE getPtr #-}
getPtr :: ForeignPtr a -> Ptr a
getPtr (ForeignPtr addr :: Addr#
addr _) = Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
addr

setPtr :: ForeignPtr a -> Ptr a -> ForeignPtr a
{-# INLINE setPtr #-}
setPtr :: ForeignPtr a -> Ptr a -> ForeignPtr a
setPtr (ForeignPtr _ c :: ForeignPtrContents
c) (Ptr addr :: Addr#
addr) = Addr# -> ForeignPtrContents -> ForeignPtr a
forall a. Addr# -> ForeignPtrContents -> ForeignPtr a
ForeignPtr Addr#
addr ForeignPtrContents
c

updPtr :: (Ptr a -> Ptr a) -> ForeignPtr a -> ForeignPtr a
{-# INLINE updPtr #-}
updPtr :: (Ptr a -> Ptr a) -> ForeignPtr a -> ForeignPtr a
updPtr f :: Ptr a -> Ptr a
f (ForeignPtr p :: Addr#
p c :: ForeignPtrContents
c) = case Ptr a -> Ptr a
f (Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
p) of { Ptr q :: Addr#
q -> Addr# -> ForeignPtrContents -> ForeignPtr a
forall a. Addr# -> ForeignPtrContents -> ForeignPtr a
ForeignPtr Addr#
q ForeignPtrContents
c }