fix memory growing for empty data segments

This commit is contained in:
Ilya Rezvov
2018-04-08 10:53:14 -07:00
parent 8b5c7fa154
commit 87758b2789
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -316,6 +316,7 @@ initialize inst Module {elems, datas, start} store = do
return $ st { tableInstances = tableInstances st Vector.// [(idx, table)] } return $ st { tableInstances = tableInstances st Vector.// [(idx, table)] }
fitOrGrowMemory :: Address -> Store -> Int -> IO MemoryInstance fitOrGrowMemory :: Address -> Store -> Int -> IO MemoryInstance
fitOrGrowMemory idx st 0 = return $ memInstances st ! idx
fitOrGrowMemory idx st last = do fitOrGrowMemory idx st last = do
let m@(MemoryInstance mem maxLen) = memInstances st ! idx let m@(MemoryInstance mem maxLen) = memInstances st ! idx
let len = IOVector.length mem let len = IOVector.length mem
@@ -329,7 +330,7 @@ initialize inst Module {elems, datas, start} store = do
Nothing -> increased Nothing -> increased
Just max -> Just max ->
let maxInBytes = max * pageSize in let maxInBytes = max * pageSize in
if maxInBytes <= last if maxInBytes < last
then error $ "Max memory length reached. Max " ++ show max ++ "(" ++ show maxInBytes ++ "b), but requested " ++ show last then error $ "Max memory length reached. Max " ++ show max ++ "(" ++ show maxInBytes ++ "b), but requested " ++ show last
else increased else increased
+1 -1
View File
@@ -34,7 +34,7 @@ compile file = do
main :: IO () main :: IO ()
main = do main = do
files <- Directory.listDirectory "tests/samples" files <- Directory.listDirectory "tests/samples"
-- let files = ["func.wast"] -- let files = ["memory.wast"]
scriptTestCases <- (`mapM` files) $ \file -> do scriptTestCases <- (`mapM` files) $ \file -> do
content <- LBS.readFile $ "tests/samples/" ++ file content <- LBS.readFile $ "tests/samples/" ++ file
let Right script = Parser.parseScript <$> Lexer.scanner content let Right script = Parser.parseScript <$> Lexer.scanner content