@@ -9,7 +9,7 @@ module Hakyll.Core.UnixFilter
9--------------------------------------------------------------------------------
9--------------------------------------------------------------------------------
10import Control.Concurrent (forkIO)
10import Control.Concurrent (forkIO)
11import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
11import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
12−import Control.DeepSeq (NFData, deepseq)
12+import Control.DeepSeq (deepseq)
13import Control.Monad (forM_)
13import Control.Monad (forM_)
14import Data.ByteString.Lazy (ByteString)
14import Data.ByteString.Lazy (ByteString)
15import qualified Data.ByteString.Lazy as LB
15import qualified Data.ByteString.Lazy as LB
@@ -57,7 +57,8 @@ unixFilter = unixFilterWith writer reader
57 hPutStr handle input
57 hPutStr handle input
58 reader handle = do
58 reader handle = do
59 hSetEncoding handle localeEncoding
59 hSetEncoding handle localeEncoding
60− hGetContents handle
60+ out <- hGetContents handle
61+ deepseq out (return out)
63--------------------------------------------------------------------------------
64--------------------------------------------------------------------------------
@@ -70,12 +71,14 @@ unixFilterLBS :: String -- ^ Program name
70 -> [String] -- ^ Program args
71 -> [String] -- ^ Program args
71 -> ByteString -- ^ Program input
72 -> ByteString -- ^ Program input
72 -> Compiler ByteString -- ^ Program output
73 -> Compiler ByteString -- ^ Program output
73−unixFilterLBS = unixFilterWith LB.hPutStr LB.hGetContents
74+unixFilterLBS = unixFilterWith LB.hPutStr $ \handle -> do
75+ out <- LB.hGetContents handle
76+ LB.length out `seq` return out
76--------------------------------------------------------------------------------
79--------------------------------------------------------------------------------
77-- | Overloaded compiler
80-- | Overloaded compiler
78−unixFilterWith :: (Monoid o, NFData o)
81+unixFilterWith :: Monoid o
79 => (Handle -> i -> IO ()) -- ^ Writer
82 => (Handle -> i -> IO ()) -- ^ Writer
80 -> (Handle -> IO o) -- ^ Reader
83 -> (Handle -> IO o) -- ^ Reader
81 -> String -- ^ Program name
84 -> String -- ^ Program name
@@ -96,7 +99,7 @@ unixFilterWith writer reader programName args input = do
97--------------------------------------------------------------------------------
100--------------------------------------------------------------------------------
98-- | Internally used function
101-- | Internally used function
99−unixFilterIO :: (Monoid o, NFData o)
102+unixFilterIO :: Monoid o
100 => (Handle -> i -> IO ())
103 => (Handle -> i -> IO ())
101 -> (Handle -> IO o)
104 -> (Handle -> IO o)
102 -> String
105 -> String
@@ -122,14 +125,14 @@ unixFilterIO writer reader programName args input = do
122 -- Read from stdout
125 -- Read from stdout
123 _ <- forkIO $ do
126 _ <- forkIO $ do
124 out <- reader outh
127 out <- reader outh
125− deepseq out (hClose outh)
128+ hClose outh
126 writeIORef outRef out
129 writeIORef outRef out
127 putMVar lock ()
130 putMVar lock ()
129 -- Read from stderr
132 -- Read from stderr
130 _ <- forkIO $ do
133 _ <- forkIO $ do
131 err <- hGetContents errh
134 err <- hGetContents errh
132− deepseq err (hClose errh)
135+ hClose errh
133 writeIORef errRef err
136 writeIORef errRef err
134 putMVar lock ()
137 putMVar lock ()