Changeset 14997 for src/Pugs/Prim.hs

Show
Ignore:
Timestamp:
01/05/07 11:01:29 (23 months ago)
Author:
audreyt
Message:

* Pugs.Prim: Fix t/xx-uncategorized/say-crash.t by printing

in 4096-byte chunks instead of running the strict encodeUTF8
on the entire string. This commit fixed the bug, but the
next one should generalize this fix to make encode/decode
sufficiently chunk-lazy...
Reported by gaal++.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim.hs

    r14953 r14997  
    11061106    ys <- fromVals y 
    11071107    op1 "sort" . VList $ xs ++ ys 
    1108 op2 "IO::say" = op2Print hPutStrLn 
    1109 op2 "IO::print" = op2Print hPutStr 
     1108op2 "IO::say" = op2Print True 
     1109op2 "IO::print" = op2Print False 
    11101110op2 "printf" = op3 "IO::printf" (VHandle stdout) 
    11111111op2 "BUILDALL" = cascadeMethod reverse "BUILD" 
     
    11611161    asFractional = foldr (\d x -> (x / (base % 1)) + (d % 1)) (0 % 1) 
    11621162 
    1163 op2Print :: (Handle -> String -> IO ()) -> Val -> Val -> Eval Val 
    1164 op2Print f h v = do 
     1163op2Print :: Bool -> Val -> Val -> Eval Val 
     1164op2Print newline h v = do 
    11651165    handle <- fromVal h 
    11661166    strs   <- mapM fromVal =<< case v of 
     
    11681168        _         -> return [v] 
    11691169    guardIO $ do 
    1170         f handle . concatMap encodeUTF8 $ strs 
     1170        forM strs $ \str -> do 
     1171            forM (chunk 4096 str) $ \chunk -> do 
     1172                hPutStr handle chunk 
     1173        when newline (hPutStr handle "\n") 
    11711174        return $ VBool True 
     1175    where 
     1176    chunk :: Int -> [a] -> [[a]] 
     1177    chunk _    [] = [] 
     1178    chunk size xs = case splitAt size xs of (xs', xs'') -> xs' : chunk size xs'' 
    11721179 
    11731180op2Split :: Val -> Val -> Eval Val 
     
    13521359op3 "IO::printf" = \x y z -> do 
    13531360    rv      <- evalExp $ App (_Var "&sprintf") Nothing [Val y, Val z] 
    1354     op2Print hPutStr x rv 
     1361    op2Print False x rv 
    13551362op3 other = \_ _ _ -> fail ("Unimplemented 3-ary op: " ++ other) 
    13561363