import Foreign.C.Types
import Foreign.C.TypesISO
+#include "MachDeps.h"
+
#ifdef __GLASGOW_HASKELL__
import GHC.Storable
#elif defined(__HUGS__)
-- restrictions might apply; see 'peek'.
-- circular default instances
+#ifdef __GLASGOW_HASKELL__
peekElemOff = peekElemOff_ undefined
where peekElemOff_ :: a -> Ptr a -> Int -> IO a
peekElemOff_ undef ptr off = peekByteOff ptr (off * sizeOf undef)
+#else
+ peekElemOff ptr off = peekByteOff ptr (off * sizeOfPtr ptr undefined)
+#endif
pokeElemOff ptr off val = pokeByteOff ptr (off * sizeOf val) val
peekByteOff ptr off = peek (ptr `plusPtr` off)
poke ptr = pokeElemOff ptr 0
\end{code}
+#ifndef __GLASGOW_HASKELL__
+\begin{code}
+sizeOfPtr :: Storable a => Ptr a -> a -> Int
+sizeOfPtr px x = sizeOf x
+\end{code}
+#endif
+
System-dependent, but rather obvious instances
\begin{code}
peekElemOff = read; \
pokeElemOff = write }
+#ifdef __GLASGOW_HASKELL__
STORABLE(Char,SIZEOF_INT32,ALIGNMENT_INT32,
readWideCharOffPtr,writeWideCharOffPtr)
+#elif defined(__HUGS__)
+STORABLE(Char,SIZEOF_CHAR,ALIGNMENT_HSCHAR,
+ readCharOffPtr,writeCharOffPtr)
+#endif
STORABLE(Int,SIZEOF_HSINT,ALIGNMENT_HSINT,
readIntOffPtr,writeIntOffPtr)