packages feed

leveldb-haskell 0.5 → 0.5.1

raw patch · 5 files changed

+28/−7 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Database.LevelDB.Base: withDB :: (MonadMask m, MonadIO m) => FilePath -> Options -> (DB -> m a) -> m a

Files

examples/iterforkio.hs view
@@ -8,7 +8,6 @@  import Control.Concurrent import Control.Concurrent.Async-import Control.Exception import Data.Default  import Database.LevelDB.Base@@ -16,13 +15,13 @@ import qualified Data.ByteString.Char8 as BS  main :: IO ()-main = bracket (open "/tmp/leveltest" def{ createIfMissing = True }) close $ \ db -> do+main = withDB "/tmp/leveltest" def{ createIfMissing = True } $ \ db -> do      let xs = [1..100] :: [Int]      write db def (map (\ x -> Put (BS.pack . show $ x) "") xs) -    bracket (createIter db def) releaseIter $ \ iter -> do+    withIter db def $ \ iter -> do         _   <- iterFirst iter         lck <- newMVar iter         es  <- mapConcurrently (getEntry lck) xs
leveldb-haskell.cabal view
@@ -1,5 +1,5 @@ name:                leveldb-haskell-version:             0.5+version:             0.5.1 synopsis:            Haskell bindings to LevelDB homepage:            http://github.com/kim/leveldb-haskell bug-reports:         http://github.com/kim/leveldb-haskell/issues
src/Data/Stream/Monadic.hs view
@@ -225,7 +225,7 @@             Yield x s' -> Yield x (Just s') {-# INLINE [0] snoc #-} --- | Unlike 'Data.List.head', this function does not diverge if the 'Stream is+-- | Unlike 'Data.List.head', this function does not diverge if the 'Stream' is -- empty. Instead, 'Nothing' is returned. head :: Monad m => Stream m a -> m (Maybe a) head (Stream next s0) = loop =<< s0
src/Database/LevelDB/Base.hs view
@@ -30,6 +30,7 @@     , defaultWriteOptions      -- * Basic Database Manipulations+    , withDB     , open     , put     , delete@@ -97,6 +98,14 @@             return db      addFinalizer ref = void . mkWeakIORef ref++-- | Run an action with a 'DB'.+--+-- > withDB path opts = bracket (open path opts) unsafeClose+--+-- Note that the 'DB' handle will be released promptly when this function exits.+withDB :: (MonadMask m, MonadIO m) => FilePath -> Options -> (DB -> m a) -> m a+withDB path opts = bracket (open path opts) (liftIO . unsafeClose)  -- | Run an action with a 'Snapshot' of the database. withSnapshot :: (MonadMask m, MonadIO m) => DB -> (Snapshot -> m a) -> m a
src/Database/LevelDB/Internal.hs view
@@ -1,4 +1,6 @@ {-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE CPP             #-}+ -- | -- Module      : Database.LevelDB.Internal -- Copyright   : (c) 2012-2013 The leveldb-haskell Authors@@ -17,7 +19,7 @@      , unsafeClose -    -- * "Smart" constructors and deconstructors+    -- * \"Smart\" constructors and deconstructors     , freeCReadOpts     , freeComparator     , freeFilterPolicy@@ -95,9 +97,20 @@ -- will segfault (internally, leveldb performs a @delete@ on the pointer). unsafeClose :: DB -> IO () unsafeClose (DB db_ptr opts_ptr ref) = do-    alive <- atomicModifyIORef' ref ((,) False)+    alive <- modify ref ((,) False)     when alive $         c_leveldb_close db_ptr `finally` freeOpts opts_ptr++modify :: IORef a -> (a -> (a,b)) -> IO b+#if MIN_VERSION_base(4,6,0)+modify = atomicModifyIORef'+#else+modify ref f = do+    b <- atomicModifyIORef ref+            (\x -> let (a, b) = f x+                    in (a, a `seq` b))+    b `seq` return b+#endif  mkOpts :: Options -> IO Options' mkOpts Options{..} = do