diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2019-01-17 13:34:32 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-01-31 12:46:51 -0500 |
commit | 4fa32293c9d2658ce504b8fe6d909db2acf59983 (patch) | |
tree | 6c7519fd6a320cbaf2264c2cbfdfe1eef0d70acc /libraries/ghci | |
parent | deab6d64eac085b2e0ec68bfb3eeeda608dfb85a (diff) | |
download | haskell-4fa32293c9d2658ce504b8fe6d909db2acf59983.tar.gz |
Use ByteString to represent Cmm string literals (#16198)
Also used ByteString in some other relevant places
Diffstat (limited to 'libraries/ghci')
-rw-r--r-- | libraries/ghci/GHCi/InfoTable.hsc | 13 | ||||
-rw-r--r-- | libraries/ghci/GHCi/Message.hs | 2 |
2 files changed, 10 insertions, 5 deletions
diff --git a/libraries/ghci/GHCi/InfoTable.hsc b/libraries/ghci/GHCi/InfoTable.hsc index ec3c18ae06..87d8f8f167 100644 --- a/libraries/ghci/GHCi/InfoTable.hsc +++ b/libraries/ghci/GHCi/InfoTable.hsc @@ -22,6 +22,8 @@ import Foreign.C import GHC.Ptr import GHC.Exts import GHC.Exts.Heap +import Data.ByteString (ByteString) +import qualified Data.ByteString as BS #endif ghciTablesNextToCode :: Bool @@ -40,7 +42,7 @@ mkConInfoTable -> Int -- non-ptr words -> Int -- constr tag -> Int -- pointer tag - -> [Word8] -- con desc + -> ByteString -- con desc -> IO (Ptr StgInfoTable) -- resulting info table is allocated with allocateExec(), and -- should be freed with freeExec(). @@ -344,10 +346,10 @@ sizeOfEntryCode Right xs -> sizeOf (head xs) * length xs -- Note: Must return proper pointer for use in a closure -newExecConItbl :: StgInfoTable -> [Word8] -> IO (FunPtr ()) +newExecConItbl :: StgInfoTable -> ByteString -> IO (FunPtr ()) newExecConItbl obj con_desc = alloca $ \pcode -> do - let lcon_desc = length con_desc + 1{- null terminator -} + let lcon_desc = BS.length con_desc + 1{- null terminator -} -- SCARY -- This size represents the number of bytes in an StgConInfoTable. sz = fromIntegral (conInfoTableSizeB + sizeOfEntryCode) @@ -360,7 +362,10 @@ newExecConItbl obj con_desc let cinfo = StgConInfoTable { conDesc = ex_ptr `plusPtr` fromIntegral sz , infoTable = obj } pokeConItbl wr_ptr ex_ptr cinfo - pokeArray0 0 (castPtr wr_ptr `plusPtr` fromIntegral sz) con_desc + BS.useAsCStringLen con_desc $ \(src, len) -> + copyBytes (castPtr wr_ptr `plusPtr` fromIntegral sz) src len + let null_off = fromIntegral sz + fromIntegral (BS.length con_desc) + poke (castPtr wr_ptr `plusPtr` null_off) (0 :: Word8) _flushExec sz ex_ptr -- Cache flush (if needed) #if defined(TABLES_NEXT_TO_CODE) return (castPtrToFunPtr (ex_ptr `plusPtr` conInfoTableSizeB)) diff --git a/libraries/ghci/GHCi/Message.hs b/libraries/ghci/GHCi/Message.hs index bc0a19ca62..959942e858 100644 --- a/libraries/ghci/GHCi/Message.hs +++ b/libraries/ghci/GHCi/Message.hs @@ -107,7 +107,7 @@ data Message a where -> Int -- non-ptr words -> Int -- constr tag -> Int -- pointer tag - -> [Word8] -- constructor desccription + -> ByteString -- constructor desccription -> Message (RemotePtr StgInfoTable) -- | Evaluate a statement |