X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FStrings.hs;h=f1762b0a5ae1e9790639b69857ebf9bc5e9f9e82;hb=4c504fbb0b276782af6cd250e5e9fd4fdcc26967;hp=ba2166364aca3c3537ac119655a34924b708eb15;hpb=4acc971dbcafd34fa7f5716513ae4dd47e0ea0eb;p=mate.git diff --git a/Mate/Strings.hs b/Mate/Strings.hs index ba21663..f1762b0 100644 --- a/Mate/Strings.hs +++ b/Mate/Strings.hs @@ -1,6 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ForeignFunctionInterface #-} +#include "debug.h" module Mate.Strings ( getUniqueStringAddr ) where @@ -13,22 +13,24 @@ import qualified Data.ByteString.Internal as BI import Text.Printf #endif +import JVM.ClassFile + import Foreign.Ptr -import Foreign.Marshal.Alloc import Foreign.Marshal.Utils import Foreign.Marshal.Array import Mate.Types +import Mate.Debug +import Mate.GarbageAlloc getUniqueStringAddr :: B.ByteString -> IO Word32 getUniqueStringAddr str = do - smap <- get_stringsmap >>= ptr2stringsmap + smap <- getStringMap case M.lookup str smap of Nothing -> do addr <- allocateJavaString str - let smap' = M.insert str addr smap - stringsmap2ptr smap' >>= set_stringsmap + setStringMap $ M.insert str addr smap return addr Just addr -> return addr @@ -36,13 +38,11 @@ allocateJavaString :: B.ByteString -> IO Word32 allocateJavaString str = do -- TODO(bernhard): is this also true for UTF8 stuff? let strlen = fromIntegral $ B.length str - arr <- newArray $ ((map fromIntegral $ B.unpack str) :: [Word8]) + arr <- newArray ((map fromIntegral $ B.unpack str) :: [Word8]) -- (+1) for \0 - newstr <- mallocBytes (strlen + 1) + newstr <- mallocString (strlen + 1) BI.memset newstr 0 (fromIntegral $ strlen + 1) copyBytes newstr arr strlen let w32_ptr = fromIntegral $ ptrToIntPtr newstr -#ifdef DEBUG - printf "new str ptr: 0x%08x (%s)@%d\n" w32_ptr (toString str) strlen -#endif + printfStr "new str ptr: 0x%08x (%s)@%d\n" w32_ptr (toString str) strlen return w32_ptr