X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FStrings.hs;fp=Mate%2FStrings.hs;h=435f6ec08fda6861c81e2183596f940f52373e73;hb=29d516ed97f310dff3b3ece9655d323f9c148b83;hp=22567a845157fbb7a3124cdc87d50518dbb71931;hpb=af88fa2a73378fa634a8ccb51bda5c982cad6b91;p=mate.git diff --git a/Mate/Strings.hs b/Mate/Strings.hs index 22567a8..435f6ec 100644 --- a/Mate/Strings.hs +++ b/Mate/Strings.hs @@ -7,6 +7,7 @@ module Mate.Strings ( import Data.Word import qualified Data.Map as M import qualified Data.ByteString.Lazy as B +import qualified Data.ByteString.Internal as BI import Text.Printf import Foreign.Ptr @@ -31,10 +32,11 @@ getUniqueStringAddr str = do allocateJavaString :: B.ByteString -> IO Word32 allocateJavaString str = do -- TODO(bernhard): is this also true for UTF8 stuff? - -- (+1) for \0 - let strlen = (+1) $ fromIntegral $ B.length str + let strlen = fromIntegral $ B.length str arr <- newArray $ ((map fromIntegral $ B.unpack str) :: [Word8]) - newstr <- mallocBytes strlen + -- (+1) for \0 + newstr <- mallocBytes (strlen + 1) + BI.memset newstr 0 (fromIntegral $ strlen + 1) copyBytes newstr arr strlen let w32_ptr = fromIntegral $ ptrToIntPtr newstr printf "new str ptr: 0x%08x (%s)@%d\n" w32_ptr (toString str) strlen