on master help sign in
Merge pull request #109 from rhymoid/update-cpp-min-version

Update CPP MIN_VERSION_* checks

commitda1ae2d25e3001ced4d012ffa39106535f9f1431 authorMichael Snoyman <michael@snoyman.com> dateFri 16 Jun 2017, 06:45 (9 years ago) parent23efce444779be
4 files changed+13−43
Data/Yaml.hs+4 Data/Yaml/Builder.hs+4 Data/Yaml/Parser.hs+1−6 Text/Libyaml.hs+4−37
Data/Yaml.hs+4
@@ -78,7 +78,11 @@ import Data.Aeson
7878 , Object, Array
7979 , withObject, withText, withArray, withScientific, withBool
8080 )
81+#if MIN_VERSION_aeson(1,0,0)
82+import Data.Aeson.Text (encodeToTextBuilder)
83+#else
8184import Data.Aeson.Encode (encodeToTextBuilder)
85+#endif
8286import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser)
8387import Data.ByteString (ByteString)
8488import qualified Data.Conduit as C
Data/Yaml/Builder.hs+4
@@ -22,7 +22,11 @@ import Prelude hiding (null)
2222
2323import Control.Arrow (second)
2424import Control.Monad.Trans.Resource (runResourceT)
25+#if MIN_VERSION_aeson(1,0,0)
26+import Data.Aeson.Text (encodeToTextBuilder)
27+#else
2528import Data.Aeson.Encode (encodeToTextBuilder)
29+#endif
2630import Data.Aeson.Types (Value(..))
2731import Data.ByteString (ByteString)
2832import qualified Data.ByteString.Char8 as S8
Data/Yaml/Parser.hs+1−6
@@ -13,12 +13,7 @@ import Control.Monad.Trans.Resource (MonadThrow, monadThrow, runResourceT)
1313import Control.Monad.Trans.Writer.Strict (tell, WriterT)
1414import Data.ByteString (ByteString)
1515import Data.Conduit
16−#if MIN_VERSION_conduit(1,1,0)
1716import Data.Conduit.Lift (runWriterC)
18−#define runWriterSC runWriterC
19−#else
20−import Data.Conduit.Lift (runWriterSC)
21−#endif
2217import qualified Data.Map as Map
2318#if !MIN_VERSION_base(4,8,0)
2419import Data.Monoid (Monoid (..))
@@ -193,7 +188,7 @@ sinkValue =
193188 Just e -> monadThrow $ UnexpectedEvent e
194189
195190sinkRawDoc :: MonadThrow m => Consumer Event m RawDoc
196−sinkRawDoc = uncurry RawDoc <$> runWriterSC sinkValue
191+sinkRawDoc = uncurry RawDoc <$> runWriterC sinkValue
197192
198193readYamlFile :: FromYaml a => FilePath -> IO a
199194readYamlFile fp = runResourceT (decodeFile fp $$ sinkRawDoc) >>= parseRawDoc
Text/Libyaml.hs+4−37
@@ -479,12 +479,7 @@ newtype ToEventRawException = ToEventRawException CInt
479479 deriving (Show, Typeable)
480480instance Exception ToEventRawException
481481
482−decode :: MonadResource m => B.ByteString
483−#if MIN_VERSION_conduit(1, 0, 0)
484− -> Producer m Event
485−#else
486− -> GSource m Event
487−#endif
482+decode :: MonadResource m => B.ByteString -> Producer m Event
488483decode bs | B8.null bs = return ()
489484decode bs =
490485 bracketP alloc cleanup (runParser . fst)
@@ -526,12 +521,7 @@ openFile file rawOpenFlags openMode = do
526521 then withCString openMode $ \openMode' -> c_fdopen fd openMode'
527522 else return nullPtr
528523
529−decodeFile :: MonadResource m => FilePath
530−#if MIN_VERSION_conduit(1, 0, 0)
531− -> Producer m Event
532−#else
533− -> GSource m Event
534−#endif
524+decodeFile :: MonadResource m => FilePath -> Producer m Event
535525decodeFile file =
536526 bracketP alloc cleanup (runParser . fst)
537527 where
@@ -559,12 +549,7 @@ decodeFile file =
559549 c_yaml_parser_delete ptr
560550 free ptr
561551
562−runParser :: MonadResource m => Parser
563−#if MIN_VERSION_conduit(1, 0, 0)
564− -> Producer m Event
565−#else
566− -> GSource m Event
567−#endif
552+runParser :: MonadResource m => Parser -> Producer m Event
568553runParser parser = do
569554 e <- liftIO $ parserParseOne' parser
570555 case e of
@@ -588,12 +573,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
588573 return $ Left $ YamlParseException problem context problemMark
589574 else Right <$> getEvent er
590575
591−encode :: MonadResource m
592−#if MIN_VERSION_conduit(1, 0, 0)
593− => Consumer Event m ByteString
594−#else
595− => GSink Event m ByteString
596−#endif
576+encode :: MonadResource m => Consumer Event m ByteString
597577encode =
598578 runEmitter alloc close
599579 where
@@ -610,11 +590,7 @@ encode =
610590
611591encodeFile :: MonadResource m
612592 => FilePath
613−#if MIN_VERSION_conduit(1, 0, 0)
614593 -> Consumer Event m ()
615−#else
616− -> GInfSink Event m
617−#endif
618594encodeFile filePath =
619595 bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u)
620596 where
@@ -628,13 +604,8 @@ encodeFile filePath =
628604
629605runEmitter :: MonadResource m
630606 => (Emitter -> IO a) -- ^ alloc
631−#if MIN_VERSION_conduit(1, 0, 0)
632607 -> (() -> a -> IO b) -- ^ close
633608 -> Consumer Event m b
634−#else
635− -> (u -> a -> IO b) -- ^ close
636− -> Pipe l Event o u m b
637−#endif
638609runEmitter allocI closeI =
639610 bracketP alloc cleanup go
640611 where
@@ -654,11 +625,7 @@ runEmitter allocI closeI =
654625 go (emitter, a) =
655626 loop
656627 where
657−#if MIN_VERSION_conduit(1, 0, 0)
658628 loop = await >>= maybe (close ()) push
659−#else
660− loop = awaitE >>= either close push
661−#endif
662629
663630 push e = do
664631 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter