module Language.Asm.Inline.Util where import qualified Data.ByteString as BS import qualified Data.ByteString.Internal as BS import Foreign.ForeignPtr import Foreign.ForeignPtr.Unsafe import Foreign.Ptr import GHC.Word getBSAddr :: BS.ByteString -> Ptr Word8 getBSAddr :: ByteString -> Ptr Word8 getBSAddr ByteString bs = forall a. ForeignPtr a -> Ptr a unsafeForeignPtrToPtr ForeignPtr Word8 ptr forall a b. Ptr a -> Int -> Ptr b `plusPtr` Int offset where (ForeignPtr Word8 ptr, Int offset, Int _) = ByteString -> (ForeignPtr Word8, Int, Int) BS.toForeignPtr ByteString bs withBS :: BS.ByteString -> IO a -> IO a withBS :: forall a. ByteString -> IO a -> IO a withBS ByteString str IO a action = forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b withForeignPtr ForeignPtr Word8 ptr forall a b. (a -> b) -> a -> b $ forall a b. a -> b -> a const IO a action where (ForeignPtr Word8 ptr, Int _, Int _) = ByteString -> (ForeignPtr Word8, Int, Int) BS.toForeignPtr ByteString str