{-# LINE 1 "src/Mdbx/FFI.chs" #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
module Mdbx.FFI (
MdbxEnvFlags(..),
MdbxEnv(..),
MdbxEnvMode(..),
mdbx_env_create,
mdbx_env_open,
mdbx_env_close,
MdbxTxnFlags(..),
MdbxTxn(..),
mdbx_txn_begin,
mdbx_txn_commit,
mdbx_txn_abort,
mdbx_txn_env,
MdbxDbFlags(..),
MdbxDbi(..),
mdbx_dbi_open,
mdbx_dbi_close,
MdbxVal(..),
emptyMdbxVal,
MdbxPutFlags(..),
mdbx_put,
mdbx_get,
mdbx_del,
MdbxCursorOp(..),
MdbxCursor(..),
mdbx_cursor_open,
mdbx_cursor_close,
mdbx_cursor_del,
mdbx_cursor_get,
mdbx_cursor_put,
mdbx_cursor_count,
mdbx_strerror,
mdbx_cmp,
MdbxError(..)
) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp
import Foreign
import Foreign.C
{-# LINE 70 "src/Mdbx/FFI.chs" #-}
data MdbxError = MdbxKeyexist
| MdbxFirstLmdbErrcode
| MdbxNotfound
| MdbxPageNotfound
| MdbxCorrupted
| MdbxPanic
| MdbxVersionMismatch
| MdbxInvalid
| MdbxMapFull
| MdbxDbsFull
| MdbxReadersFull
| MdbxTxnFull
| MdbxCursorFull
| MdbxPageFull
| MdbxUnableExtendMapsize
| MdbxIncompatible
| MdbxBadRslot
| MdbxBadTxn
| MdbxBadValsize
| MdbxBadDbi
| MdbxProblem
| MdbxLastLmdbErrcode
| MdbxBusy
| MdbxFirstAddedErrcode
| MdbxEmultival
| MdbxEbadsign
| MdbxWannaRecovery
| MdbxEkeymismatch
| MdbxTooLarge
| MdbxThreadMismatch
| MdbxTxnOverlapping
| MdbxLastAddedErrcode
| MdbxResultTrue
| MdbxSuccess
| MdbxResultFalse
| MdbxEperm
| MdbxEnofile
| MdbxEintr
| MdbxEio
| MdbxEnomem
| MdbxEaccess
| MdbxEremote
| MdbxEinval
| MdbxErofs
| MdbxEnosys
| MdbxEnodata
deriving (Show,Eq,Ord)
instance Enum MdbxError where
succ MdbxKeyexist = MdbxNotfound
succ MdbxFirstLmdbErrcode = MdbxNotfound
succ MdbxNotfound = MdbxPageNotfound
succ MdbxPageNotfound = MdbxCorrupted
succ MdbxCorrupted = MdbxPanic
succ MdbxPanic = MdbxVersionMismatch
succ MdbxVersionMismatch = MdbxInvalid
succ MdbxInvalid = MdbxMapFull
succ MdbxMapFull = MdbxDbsFull
succ MdbxDbsFull = MdbxReadersFull
succ MdbxReadersFull = MdbxTxnFull
succ MdbxTxnFull = MdbxCursorFull
succ MdbxCursorFull = MdbxPageFull
succ MdbxPageFull = MdbxUnableExtendMapsize
succ MdbxUnableExtendMapsize = MdbxIncompatible
succ MdbxIncompatible = MdbxBadRslot
succ MdbxBadRslot = MdbxBadTxn
succ MdbxBadTxn = MdbxBadValsize
succ MdbxBadValsize = MdbxBadDbi
succ MdbxBadDbi = MdbxProblem
succ MdbxProblem = MdbxBusy
succ MdbxLastLmdbErrcode = MdbxBusy
succ :: MdbxTxnFlags -> MdbxTxnFlags
succ MdbxBusy = MdbxEmultival
succ MdbxFirstAddedErrcode = MdbxEmultival
succ MdbxTxnFlags
MdbxEmultival = MdbxEbadsign
succ MdbxEbadsign = MdbxWannaRecovery
succ MdbxWannaRecovery = MdbxEkeymismatch
succ MdbxEkeymismatch = MdbxTooLarge
succ MdbxTooLarge = MdbxThreadMismatch
pred :: MdbxTxnFlags -> MdbxTxnFlags
succ MdbxThreadMismatch = MdbxTxnOverlapping
succ MdbxTxnOverlapping = MdbxResultTrue
succ MdbxLastAddedErrcode = MdbxResultTrue
succ MdbxResultTrue = MdbxSuccess
succ MdbxSuccess = MdbxEperm
succ MdbxResultFalse = MdbxEperm
succ MdbxEperm = MdbxEnofile
succ MdbxEnofile = MdbxEintr
succ MdbxEintr = MdbxEio
succ MdbxEio = MdbxEnomem
succ MdbxEnomem = MdbxEaccess
succ MdbxEaccess = MdbxEremote
succ MdbxEremote = MdbxEinval
succ MdbxEinval = MdbxErofs
succ MdbxErofs = MdbxEnosys
succ MdbxEnosys = MdbxEnodata
succ MdbxEnodata = error "MdbxError.succ: MdbxEnodata has no successor"
pred :: MdbxError -> MdbxError
pred MdbxError
MdbxNotfound = MdbxError
MdbxKeyexist
pred MdbxError
MdbxPageNotfound = MdbxError
MdbxNotfound
pred MdbxError
MdbxCorrupted = MdbxError
MdbxPageNotfound
pred MdbxError
MdbxPanic = MdbxError
MdbxCorrupted
pred MdbxError
MdbxVersionMismatch = MdbxError
MdbxPanic
pred MdbxError
MdbxInvalid = MdbxError
MdbxVersionMismatch
pred MdbxMapFull = MdbxError
MdbxInvalid
pred MdbxError
MdbxDbsFull = MdbxError
MdbxMapFull
pred MdbxError
MdbxReadersFull = MdbxError
MdbxDbsFull
pred MdbxError
MdbxTxnFull = MdbxError
MdbxReadersFull
pred MdbxError
MdbxCursorFull = MdbxError
MdbxTxnFull
pred MdbxError
MdbxPageFull = MdbxError
MdbxCursorFull
pred MdbxError
MdbxUnableExtendMapsize = MdbxError
MdbxPageFull
pred MdbxError
MdbxIncompatible = MdbxError
MdbxUnableExtendMapsize
pred MdbxError
MdbxBadRslot = MdbxError
MdbxIncompatible
pred MdbxError
MdbxBadTxn = MdbxError
MdbxBadRslot
pred MdbxError
MdbxBadValsize = MdbxError
MdbxBadTxn
pred MdbxError
MdbxBadDbi = MdbxError
MdbxBadValsize
pred MdbxError
MdbxProblem = MdbxError
MdbxBadDbi
succ :: MdbxDbFlags -> MdbxDbFlags
pred MdbxError
MdbxLastLmdbErrcode = MdbxError
MdbxBadDbi
pred MdbxError
MdbxBusy = MdbxError
MdbxProblem
pred MdbxError
MdbxFirstAddedErrcode = MdbxError
MdbxProblem
pred MdbxError
MdbxEmultival = MdbxError
MdbxBusy
pred MdbxDbFlags
MdbxError
MdbxEbadsign = MdbxError
MdbxEmultival
pred MdbxError
MdbxWannaRecovery = MdbxError
MdbxEbadsign
pred MdbxError
MdbxEkeymismatch = MdbxError
MdbxWannaRecovery
pred MdbxError
MdbxTooLarge = MdbxError
MdbxEkeymismatch
pred MdbxError
MdbxThreadMismatch = MdbxError
MdbxTooLarge
pred MdbxTxnOverlapping = MdbxThreadMismatch
pred MdbxLastAddedErrcode = MdbxThreadMismatch
pred MdbxResultTrue = MdbxTxnOverlapping
pred MdbxSuccess = MdbxResultTrue
pred MdbxResultFalse = MdbxResultTrue
pred MdbxEperm = MdbxSuccess
pred MdbxEnofile = MdbxEperm
pred MdbxEintr = MdbxEnofile
pred MdbxEio = MdbxEintr
pred MdbxError
MdbxEnomem = MdbxError
MdbxEio
pred MdbxError
MdbxEaccess = MdbxError
MdbxEnomem
pred MdbxError
MdbxEremote = MdbxError
MdbxEaccess
pred MdbxError
MdbxEinval = MdbxError
MdbxEremote
pred MdbxError
MdbxErofs = MdbxError
MdbxEinval
pred MdbxError
MdbxEnosys = MdbxError
MdbxErofs
pred MdbxError
MdbxEnodata = MdbxError
MdbxEnosys
pred MdbxError
MdbxKeyexist = String -> MdbxError
forall a. HasCallStack => String -> a
error String
"MdbxError.pred: MdbxKeyexist has no predecessor"
pred MdbxError
MdbxFirstLmdbErrcode = String -> MdbxError
forall a. HasCallStack => String -> a
error String
"MdbxError.pred: MdbxFirstLmdbErrcode has no predecessor"
enumFromTo :: MdbxError -> MdbxError -> [MdbxError]
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (t -> Int
forall a. Enum a => a -> Int
fromEnum t
v) Int
end of
Ordering
LT -> t
v t -> [t] -> [t]
forall a. a -> [a] -> [a]
: t -> [t]
go (t -> t
forall a. Enum a => a -> a
succ t
v)
Ordering
EQ -> [t
v]
Ordering
GT -> []
enumFrom :: MdbxError -> [MdbxError]
enumFrom MdbxError
from = MdbxError -> MdbxError -> [MdbxError]
forall a. Enum a => a -> a -> [a]
enumFromTo MdbxError
from MdbxError
MdbxEnodata
fromEnum :: MdbxError -> Int
fromEnum MdbxError
MdbxKeyexist = (-Int
30799)
fromEnum MdbxError
MdbxFirstLmdbErrcode = (-Int
30799)
fromEnum MdbxError
MdbxNotfound = (-Int
30798)
fromEnum MdbxError
MdbxPageNotfound = (-Int
30797)
fromEnum MdbxError
MdbxCorrupted = (-Int
30796)
fromEnum MdbxError
MdbxPanic = (-Int
30795)
fromEnum MdbxError
MdbxVersionMismatch = (-Int
30794)
fromEnum MdbxError
MdbxInvalid = (-Int
30793)
fromEnum MdbxError
MdbxMapFull = (-Int
30792)
fromEnum MdbxDbsFull = (-Int
30791)
fromEnum MdbxReadersFull = (-Int
30790)
fromEnum MdbxError
MdbxTxnFull = (-Int
30788)
fromEnum MdbxError
MdbxCursorFull = (-Int
30787)
fromEnum MdbxError
MdbxPageFull = (-Int
30786)
fromEnum MdbxError
MdbxUnableExtendMapsize = (-Int
30785)
fromEnum MdbxError
MdbxIncompatible = (-Int
30784)
fromEnum MdbxError
MdbxBadRslot = (-Int
30783)
fromEnum MdbxError
MdbxBadTxn = (-Int
30782)
fromEnum MdbxError
MdbxBadValsize = (-Int
30781)
fromEnum MdbxBadDbi = (-Int
30780)
fromEnum MdbxError
MdbxProblem = (-Int
30779)
fromEnum MdbxLastLmdbErrcode = (-Int
30779)
fromEnum MdbxBusy = (-Int
30778)
fromEnum MdbxFirstAddedErrcode = (-Int
30778)
fromEnum MdbxEmultival = (-Int
30421)
fromEnum MdbxEbadsign = (-Int
30420)
fromEnum MdbxWannaRecovery = (-Int
30419)
fromEnum MdbxEkeymismatch = (-Int
30418)
fromEnum MdbxError
MdbxTooLarge = (-Int
30417)
fromEnum MdbxError
MdbxThreadMismatch = (-Int
30416)
fromEnum MdbxTxnOverlapping = (-30415)
fromEnum MdbxLastAddedErrcode = (-30415)
fromEnum MdbxResultTrue = (-1)
fromEnum MdbxSuccess = 0
fromEnum MdbxResultFalse = 0
fromEnum MdbxEperm = 1
fromEnum MdbxEnofile = 2
fromEnum MdbxEintr = 4
fromEnum MdbxEio = 5
fromEnum MdbxEnomem = 12
fromEnum MdbxError
MdbxEaccess = Int
13
fromEnum MdbxEremote = 15
fromEnum MdbxError
MdbxEinval = Int
22
fromEnum MdbxError
MdbxErofs = Int
30
fromEnum MdbxError
MdbxEnosys = Int
38
fromEnum MdbxError
MdbxEnodata = Int
61
toEnum (-30799) = MdbxKeyexist
toEnum (-30798) = MdbxNotfound
toEnum (-30797) = MdbxPageNotfound
toEnum (-30796) = MdbxCorrupted
toEnum (-30795) = MdbxPanic
toEnum (-30794) = MdbxVersionMismatch
toEnum (-30793) = MdbxInvalid
toEnum (-30792) = MdbxMapFull
toEnum (-30791) = MdbxDbsFull
toEnum (-30790) = MdbxReadersFull
toEnum (-30788) = MdbxTxnFull
toEnum (-30787) = MdbxCursorFull
toEnum (-30786) = MdbxPageFull
toEnum (-30785) = MdbxUnableExtendMapsize
toEnum (-30784) = MdbxIncompatible
toEnum (-30783) = MdbxBadRslot
toEnum (-30782) = MdbxBadTxn
toEnum (-30781) = MdbxBadValsize
toEnum (-30780) = MdbxBadDbi
toEnum (-30779) = MdbxProblem
toEnum (-30778) = MdbxBusy
toEnum (-30421) = MdbxEmultival
toEnum (-30420) = MdbxEbadsign
toEnum (-30419) = MdbxWannaRecovery
toEnum (-30418) = MdbxEkeymismatch
toEnum (-30417) = MdbxTooLarge
toEnum (-30416) = MdbxThreadMismatch
toEnum (-30415) = MdbxTxnOverlapping
toEnum (-1) = MdbxResultTrue
toEnum 0 = MdbxSuccess
toEnum 1 = MdbxEperm
toEnum 2 = MdbxEnofile
toEnum 4 = MdbxEintr
toEnum 5 = MdbxEio
toEnum 12 = MdbxEnomem
toEnum 13 = MdbxEaccess
toEnum 15 = MdbxEremote
toEnum 22 = MdbxEinval
toEnum 30 = MdbxErofs
toEnum 38 = MdbxEnosys
toEnum 61 = MdbxEnodata
toEnum unmatched = error ("MdbxError.toEnum: Cannot match " ++ show unmatched)
{-# LINE 73 "src/Mdbx/FFI.chs" #-}
newtype MdbxEnv = MdbxEnv (C2HSImp.Ptr (MdbxEnv))
{-# LINE 78 "src/Mdbx/FFI.chs" #-}
deriving instance Storable MdbxEnv
data MdbxEnvFlags
= MdbxEnvDefaults
| MdbxSyncDurable
| MdbxNosubdir
| MdbxSafeNosync
| MdbxMapasync
| MdbxRdonly
| MdbxNometasync
| MdbxWritemap
| MdbxUtterlyNosync
| MdbxNotls
| MdbxExclusive
| MdbxNordahead
| MdbxNomeminit
| MdbxCoalesce
| MdbxLiforeclaim
| MdbxPageperturb
| MdbxAccede
deriving (Show, Eq, Ord)
instance Enum MdbxEnvFlags where
succ MdbxEnvDefaults = MdbxNosubdir
succ MdbxSyncDurable = MdbxNosubdir
succ MdbxNosubdir = MdbxSafeNosync
succ MdbxSafeNosync = MdbxRdonly
succ MdbxMapasync = MdbxRdonly
succ MdbxRdonly = MdbxNometasync
succ MdbxNometasync = MdbxWritemap
succ MdbxWritemap = MdbxUtterlyNosync
succ MdbxUtterlyNosync = MdbxNotls
succ MdbxNotls = MdbxExclusive
succ MdbxExclusive = MdbxNordahead
succ MdbxNordahead = MdbxNomeminit
succ MdbxNomeminit = MdbxCoalesce
succ MdbxCoalesce = MdbxLiforeclaim
succ MdbxLiforeclaim = MdbxPageperturb
succ MdbxPageperturb = MdbxAccede
succ MdbxAccede = error "MdbxEnvFlags.succ: MdbxAccede has no successor"
pred MdbxNosubdir = MdbxEnvDefaults
pred MdbxSafeNosync = MdbxNosubdir
pred MdbxMapasync = MdbxNosubdir
pred MdbxRdonly = MdbxSafeNosync
pred MdbxNometasync = MdbxRdonly
pred MdbxWritemap = MdbxNometasync
pred MdbxUtterlyNosync = MdbxWritemap
pred MdbxNotls = MdbxUtterlyNosync
pred MdbxExclusive = MdbxNotls
pred MdbxNordahead = MdbxExclusive
pred MdbxNomeminit = MdbxNordahead
pred MdbxCoalesce = MdbxNomeminit
pred MdbxLiforeclaim = MdbxCoalesce
pred MdbxPageperturb = MdbxLiforeclaim
pred MdbxAccede = MdbxPageperturb
pred MdbxEnvDefaults = error "MdbxEnvFlags.pred: MdbxEnvDefaults has no predecessor"
pred MdbxSyncDurable = error "MdbxEnvFlags.pred: MdbxSyncDurable has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from MdbxAccede
fromEnum MdbxEnvDefaults = 0
fromEnum MdbxSyncDurable = 0
fromEnum MdbxNosubdir = 16384
fromEnum MdbxSafeNosync = 65536
fromEnum MdbxMapasync = 65536
fromEnum MdbxRdonly = 131072
fromEnum MdbxNometasync = 262144
fromEnum MdbxWritemap = 524288
fromEnum MdbxUtterlyNosync = 1114112
fromEnum MdbxNotls = 2097152
fromEnum MdbxExclusive = 4194304
fromEnum MdbxNordahead = 8388608
fromEnum MdbxNomeminit = 16777216
fromEnum MdbxCoalesce = 33554432
fromEnum MdbxLiforeclaim = 67108864
fromEnum MdbxPageperturb = 134217728
fromEnum MdbxAccede = 1073741824
toEnum 0 = MdbxEnvDefaults
toEnum 16384 = MdbxNosubdir
toEnum 65536 = MdbxSafeNosync
toEnum 131072 = MdbxRdonly
toEnum 262144 = MdbxNometasync
toEnum 524288 = MdbxWritemap
toEnum 1114112 = MdbxUtterlyNosync
toEnum 2097152 = MdbxNotls
toEnum 4194304 = MdbxExclusive
toEnum 8388608 = MdbxNordahead
toEnum 16777216 = MdbxNomeminit
toEnum 33554432 = MdbxCoalesce
toEnum 67108864 = MdbxLiforeclaim
toEnum 134217728 = MdbxPageperturb
toEnum 1073741824 = MdbxAccede
toEnum unmatched = error ("MdbxEnvFlags.toEnum: Cannot match " ++ show unmatched)
{-# LINE 103 "src/Mdbx/FFI.chs" #-}
type MdbxEnvMode = (C2HSImp.CUInt)
{-# LINE 106 "src/Mdbx/FFI.chs" #-}
{-# LINE 107 "src/Mdbx/FFI.chs" #-}
mdbx_env_create :: IO ((Int), (MdbxEnv))
mdbx_env_create =
alloca $ \a1' ->
mdbx_env_create'_ a1' >>= \res ->
let {res' = fromIntegral res} in
peek a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 112 "src/Mdbx/FFI.chs" #-}
mdbx_env_open :: (MdbxEnv) -> (String) -> ([MdbxEnvFlags]) -> (MdbxEnvMode) -> IO ((Int))
mdbx_env_open a1 a2 a3 a4 =
let {a1' = id a1} in
C2HSImp.withCString a2 $ \a2' ->
let {a3' = bitMask a3} in
let {a4' = id a4} in
mdbx_env_open'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 115 "src/Mdbx/FFI.chs" #-}
mdbx_env_close :: (MdbxEnv) -> IO ((Int))
mdbx_env_close a1 =
let {a1' = id a1} in
mdbx_env_close'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 118 "src/Mdbx/FFI.chs" #-}
newtype MdbxTxn = MdbxTxn (C2HSImp.Ptr (MdbxTxn))
{-# LINE 127 "src/Mdbx/FFI.chs" #-}
deriving instance Storable MdbxTxn
data MdbxTxnFlags
= MdbxTxnReadwrite
| MdbxTxnNosync
| MdbxTxnRdonly
| MdbxTxnNometasync
| MdbxTxnRdonlyPrepare
| MdbxTxnTry
deriving (Show, Eq, Ord)
instance Enum MdbxTxnFlags where
succ MdbxTxnReadwrite = MdbxTxnNosync
succ MdbxTxnNosync = MdbxTxnRdonly
succ MdbxTxnRdonly = MdbxTxnNometasync
succ MdbxTxnNometasync = MdbxTxnRdonlyPrepare
succ MdbxTxnRdonlyPrepare = MdbxTxnTry
succ MdbxTxnTry = error "MdbxTxnFlags.succ: MdbxTxnTry has no successor"
pred MdbxTxnNosync = MdbxTxnReadwrite
pred MdbxTxnRdonly = MdbxTxnNosync
pred MdbxTxnNometasync = MdbxTxnRdonly
pred MdbxTxnRdonlyPrepare = MdbxTxnNometasync
pred MdbxTxnTry = MdbxTxnRdonlyPrepare
pred MdbxTxnReadwrite = error "MdbxTxnFlags.pred: MdbxTxnReadwrite has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from MdbxTxnTry
fromEnum MdbxTxnReadwrite = 0
fromEnum MdbxTxnNosync = 65536
fromEnum MdbxTxnRdonly = 131072
fromEnum MdbxTxnNometasync = 262144
fromEnum MdbxTxnRdonlyPrepare = 16908288
fromEnum MdbxTxnTry = 268435456
toEnum 0 = MdbxTxnReadwrite
toEnum 65536 = MdbxTxnNosync
toEnum 131072 = MdbxTxnRdonly
toEnum 262144 = MdbxTxnNometasync
toEnum 16908288 = MdbxTxnRdonlyPrepare
toEnum 268435456 = MdbxTxnTry
toEnum unmatched = error ("MdbxTxnFlags.toEnum: Cannot match " ++ show unmatched)
{-# LINE 141 "src/Mdbx/FFI.chs" #-}
mdbx_txn_begin :: (MdbxEnv) -> (Maybe MdbxTxn) -> ([MdbxTxnFlags]) -> IO ((Int), (MdbxTxn))
mdbx_txn_begin a1 a2 a3 =
let {a1' = id a1} in
maybeTxn a2 $ \a2' ->
let {a3' = bitMask a3} in
alloca $ \a4' ->
mdbx_txn_begin'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
peek a4'>>= \a4'' ->
return (res', a4'')
{-# LINE 152 "src/Mdbx/FFI.chs" #-}
mdbx_txn_commit :: (MdbxTxn) -> IO ((Int))
mdbx_txn_commit a1 =
let {a1' = id a1} in
mdbx_txn_commit'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 155 "src/Mdbx/FFI.chs" #-}
mdbx_txn_abort :: (MdbxTxn) -> IO ((Int))
mdbx_txn_abort a1 =
let {a1' = id a1} in
mdbx_txn_abort'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 158 "src/Mdbx/FFI.chs" #-}
mdbx_txn_env :: (MdbxTxn) -> IO ((MdbxEnv))
mdbx_txn_env a1 =
let {a1' = id a1} in
mdbx_txn_env'_ a1' >>= \res ->
let {res' = id res} in
return (res')
{-# LINE 161 "src/Mdbx/FFI.chs" #-}
type MdbxDbi = (C2HSImp.CUInt)
{-# LINE 168 "src/Mdbx/FFI.chs" #-}
{-# LINE 169 "src/Mdbx/FFI.chs" #-}
data MdbxDbFlags
= MdbxDbDefaults
| MdbxReversekey
| MdbxDupsort
| MdbxIntegerkey
| MdbxDupfixed
| MdbxIntegerdup
| MdbxReversedup
| MdbxCreate
| MdbxDbAccede
deriving (Show, Eq, Ord)
instance Enum MdbxDbFlags where
succ MdbxDbDefaults = MdbxReversekey
succ MdbxReversekey = MdbxDupsort
succ MdbxDupsort = MdbxIntegerkey
succ MdbxIntegerkey = MdbxDupfixed
succ MdbxDupfixed = MdbxIntegerdup
succ MdbxIntegerdup = MdbxReversedup
succ MdbxReversedup = MdbxCreate
succ MdbxCreate = MdbxDbAccede
succ MdbxDbAccede = error "MdbxDbFlags.succ: MdbxDbAccede has no successor"
pred MdbxReversekey = MdbxDbDefaults
pred MdbxDupsort = MdbxReversekey
pred MdbxIntegerkey = MdbxDupsort
pred MdbxDupfixed = MdbxIntegerkey
pred MdbxIntegerdup = MdbxDupfixed
pred MdbxReversedup = MdbxIntegerdup
pred MdbxCreate = MdbxReversedup
pred MdbxDbAccede = MdbxCreate
pred MdbxDbDefaults = error "MdbxDbFlags.pred: MdbxDbDefaults has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from MdbxDbAccede
fromEnum MdbxDbDefaults = 0
fromEnum MdbxReversekey = 2
fromEnum MdbxDupsort = 4
fromEnum MdbxIntegerkey = 8
fromEnum MdbxDupfixed = 16
fromEnum MdbxIntegerdup = 32
fromEnum MdbxReversedup = 64
fromEnum MdbxCreate = 262144
fromEnum MdbxDbAccede = 1073741824
toEnum 0 = MdbxDbDefaults
toEnum 2 = MdbxReversekey
toEnum 4 = MdbxDupsort
toEnum 8 = MdbxIntegerkey
toEnum 16 = MdbxDupfixed
toEnum 32 = MdbxIntegerdup
toEnum 64 = MdbxReversedup
toEnum 262144 = MdbxCreate
toEnum 1073741824 = MdbxDbAccede
toEnum unmatched = error ("MdbxDbFlags.toEnum: Cannot match " ++ show unmatched)
{-# LINE 185 "src/Mdbx/FFI.chs" #-}
mdbx_dbi_open :: (MdbxTxn) -> (Maybe String) -> ([MdbxDbFlags]) -> IO ((Int), (MdbxDbi))
mdbx_dbi_open a1 a2 a3 =
let {a1' = id a1} in
maybeString a2 $ \a2' ->
let {a3' = bitMask a3} in
alloca $ \a4' ->
mdbx_dbi_open'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
peek a4'>>= \a4'' ->
return (res', a4'')
{-# LINE 196 "src/Mdbx/FFI.chs" #-}
mdbx_dbi_close :: (MdbxEnv) -> (MdbxDbi) -> IO ((Int))
mdbx_dbi_close a1 a2 =
let {a1' = id a1} in
let {a2' = id a2} in
mdbx_dbi_close'_ a1' a2' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 199 "src/Mdbx/FFI.chs" #-}
data MdbxVal = MdbxVal {
mvlSize :: {-# UNPACK #-} !(C2HSImp.CULong),
mvlData :: {-# UNPACK #-} !(Ptr ())
} deriving (Eq, Show)
instance Storable MdbxVal where
sizeOf _ = 16
{-# LINE 213 "src/Mdbx/FFI.chs" #-}
alignment _ = 8
{-# LINE 214 "src/Mdbx/FFI.chs" #-}
peek ptr = do
sz <- (\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CULong}) ptr
pd <- (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) ptr
return $! MdbxVal sz pd
poke ptr (MdbxVal sz pd) = do
(\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: C2HSImp.CULong)}) ptr sz
(\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr ()))}) ptr pd
emptyMdbxVal :: MdbxVal
emptyMdbxVal = MdbxVal 0 nullPtr
type MdbxValPtr = C2HSImp.Ptr (MdbxVal)
{-# LINE 227 "src/Mdbx/FFI.chs" #-}
data MdbxPutFlags
= MdbxUpsert
| MdbxNooverwrite
| MdbxNodupdata
| MdbxCurrent
| MdbxAlldups
| MdbxReserve
| MdbxAppend
| MdbxAppenddup
| MdbxMultiple
deriving (Show, Eq, Ord)
instance Enum MdbxPutFlags where
succ MdbxUpsert = MdbxNooverwrite
succ MdbxNooverwrite = MdbxNodupdata
succ MdbxNodupdata = MdbxCurrent
succ MdbxCurrent = MdbxAlldups
succ MdbxAlldups = MdbxReserve
succ MdbxReserve = MdbxAppend
succ MdbxAppend = MdbxAppenddup
succ MdbxAppenddup = MdbxMultiple
succ MdbxMultiple = error "MdbxPutFlags.succ: MdbxMultiple has no successor"
pred MdbxNooverwrite = MdbxUpsert
pred MdbxNodupdata = MdbxNooverwrite
pred MdbxCurrent = MdbxNodupdata
pred MdbxAlldups = MdbxCurrent
pred MdbxReserve = MdbxAlldups
pred MdbxAppend = MdbxReserve
pred MdbxAppenddup = MdbxAppend
pred MdbxMultiple = MdbxAppenddup
pred MdbxUpsert = error "MdbxPutFlags.pred: MdbxUpsert has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from MdbxMultiple
fromEnum MdbxUpsert = 0
fromEnum MdbxNooverwrite = 16
fromEnum MdbxNodupdata = 32
fromEnum MdbxCurrent = 64
fromEnum MdbxAlldups = 128
fromEnum MdbxReserve = 65536
fromEnum MdbxAppend = 131072
fromEnum MdbxAppenddup = 262144
fromEnum MdbxMultiple = 524288
toEnum 0 = MdbxUpsert
toEnum 16 = MdbxNooverwrite
toEnum 32 = MdbxNodupdata
toEnum 64 = MdbxCurrent
toEnum 128 = MdbxAlldups
toEnum 65536 = MdbxReserve
toEnum 131072 = MdbxAppend
toEnum 262144 = MdbxAppenddup
toEnum 524288 = MdbxMultiple
toEnum unmatched = error ("MdbxPutFlags.toEnum: Cannot match " ++ show unmatched)
{-# LINE 243 "src/Mdbx/FFI.chs" #-}
mdbx_put :: (MdbxTxn) -> (MdbxDbi) -> (MdbxVal) -> (MdbxVal) -> ([MdbxPutFlags]) -> IO ((Int))
mdbx_put a1 a2 a3 a4 a5 =
let {a1' = id a1} in
let {a2' = id a2} in
with a3 $ \a3' ->
with a4 $ \a4' ->
let {a5' = bitMask a5} in
mdbx_put'_ a1' a2' a3' a4' a5' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 255 "src/Mdbx/FFI.chs" #-}
mdbx_get :: (MdbxTxn) -> (MdbxDbi) -> (MdbxVal) -> IO ((Int), (MdbxVal))
mdbx_get a1 a2 a3 =
let {a1' = id a1} in
let {a2' = id a2} in
with a3 $ \a3' ->
alloca $ \a4' ->
mdbx_get'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
peek a4'>>= \a4'' ->
return (res', a4'')
{-# LINE 266 "src/Mdbx/FFI.chs" #-}
mdbx_del :: (MdbxTxn) -> (MdbxDbi) -> (MdbxVal) -> (Maybe MdbxVal) -> IO ((Int))
mdbx_del a1 a2 a3 a4 =
let {a1' = id a1} in
let {a2' = id a2} in
with a3 $ \a3' ->
withMaybe a4 $ \a4' ->
mdbx_del'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 277 "src/Mdbx/FFI.chs" #-}
newtype MdbxCursor = MdbxCursor (C2HSImp.Ptr (MdbxCursor))
{-# LINE 282 "src/Mdbx/FFI.chs" #-}
deriving instance Storable MdbxCursor
data MdbxCursorOp
= MdbxFirst
| MdbxFirstDup
| MdbxGetBoth
| MdbxGetBothRange
| MdbxGetCurrent
| MdbxGetMultiple
| MdbxLast
| MdbxLastDup
| MdbxNext
| MdbxNextDup
| MdbxNextMultiple
| MdbxNextNodup
| MdbxPrev
| MdbxPrevDup
| MdbxPrevNodup
| MdbxSet
| MdbxSetKey
| MdbxSetRange
| MdbxPrevMultiple
| MdbxSetLowerbound
deriving (Show, Eq, Ord)
deriving (Enum)
{-# LINE 310 "src/Mdbx/FFI.chs" #-}
mdbx_cursor_open :: (MdbxTxn) -> (MdbxDbi) -> IO ((Int), (MdbxCursor))
mdbx_cursor_open :: MdbxTxn -> MdbxEnvMode -> IO (Int, MdbxCursor)
mdbx_cursor_open MdbxTxn
a1 MdbxEnvMode
a2 =
let {a1' :: MdbxTxn
a1' = MdbxTxn -> MdbxTxn
forall a. a -> a
id MdbxTxn
a1} in
let {a2' :: MdbxEnvMode
a2' = MdbxEnvMode -> MdbxEnvMode
forall a. a -> a
id MdbxEnvMode
a2} in
(Ptr MdbxCursor -> IO (Int, MdbxCursor)) -> IO (Int, MdbxCursor)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr MdbxCursor -> IO (Int, MdbxCursor)) -> IO (Int, MdbxCursor))
-> (Ptr MdbxCursor -> IO (Int, MdbxCursor)) -> IO (Int, MdbxCursor)
forall a b. (a -> b) -> a -> b
$ \Ptr MdbxCursor
a3' ->
MdbxTxn -> MdbxEnvMode -> Ptr MdbxCursor -> IO CInt
mdbx_cursor_open'_ MdbxTxn
a1' MdbxEnvMode
a2' Ptr MdbxCursor
a3' IO CInt -> (CInt -> IO (Int, MdbxCursor)) -> IO (Int, MdbxCursor)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
let {res' = fromIntegral res} in
peek a3'IO MdbxCursor
-> (MdbxCursor -> IO (Int, MdbxCursor)) -> IO (Int, MdbxCursor)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \MdbxCursor
a3'' ->
(Int, MdbxCursor) -> IO (Int, MdbxCursor)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
res', MdbxCursor
a3'')
{-# LINE 320 "src/Mdbx/FFI.chs" #-}
mdbx_cursor_close :: (MdbxCursor) -> IO ()
mdbx_cursor_close a1 =
let {a1' = id a1} in
mdbx_cursor_close'_ a1' >>
return ()
{-# LINE 323 "src/Mdbx/FFI.chs" #-}
mdbx_cursor_del :: (MdbxCursor) -> ([MdbxPutFlags]) -> IO ((Int))
mdbx_cursor_del a1 a2 =
let {a1' = id a1} in
let {a2' = bitMask a2} in
mdbx_cursor_del'_ a1' a2' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 326 "src/Mdbx/FFI.chs" #-}
mdbx_cursor_get :: (MdbxCursor) -> (MdbxVal) -> (MdbxCursorOp) -> IO ((Int), (MdbxVal), (MdbxVal))
mdbx_cursor_get a1 a2 a4 =
let {a1' = id a1} in
with a2 $ \a2' ->
alloca $ \a3' ->
let {a4' = (fromIntegral . fromEnum) a4} in
mdbx_cursor_get'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
peek a2'>>= \a2'' ->
peek a3'>>= \a3'' ->
return (res', a2'', a3'')
{-# LINE 329 "src/Mdbx/FFI.chs" #-}
mdbx_cursor_put :: (MdbxCursor) -> (MdbxVal) -> (MdbxVal) -> ([MdbxPutFlags]) -> IO ((Int))
mdbx_cursor_put a1 a2 a3 a4 =
let {a1' = id a1} in
with a2 $ \a2' ->
with a3 $ \a3' ->
let {a4' = bitMask a4} in
mdbx_cursor_put'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 340 "src/Mdbx/FFI.chs" #-}
mdbx_cursor_count :: (MdbxCursor) -> IO ((Int), (CSize))
mdbx_cursor_count a1 =
let {a1' = id a1} in
alloca $ \a2' ->
mdbx_cursor_count'_ a1' a2' >>= \res ->
let {res' = fromIntegral res} in
peek a2'>>= \a2'' ->
return (res', a2'')
mdbx_cmp :: MdbxTxn -> MdbxEnvMode -> MdbxVal -> MdbxVal -> IO Int
{-# LINE 343 "src/Mdbx/FFI.chs" #-}
mdbx_strerror :: (Int) -> IO ((String))
mdbx_strerror a1 =
let {a1' = fromIntegral a1} in
mdbx_strerror'_ a1' >>= \res ->
C2HSImp.peekCString res >>= \res' ->
return (res')
{-# LINE 348 "src/Mdbx/FFI.chs" #-}
mdbx_cmp :: (MdbxTxn) -> (MdbxDbi) -> (MdbxVal) -> (MdbxVal) -> IO ((Int))
mdbx_cmp a1 a2 a3 a4 =
let {a1' = id a1} in
let {a2' = id a2} in
with a3 $ \a3' ->
with a4 $ \a4' ->
mdbx_cmp'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
return (res')
maybeTxn :: Maybe MdbxTxn -> (MdbxTxn -> IO c) -> IO c
{-# LINE 351 "src/Mdbx/FFI.chs" #-}
bitMask :: Enum a => [a] -> C2HSImp.CInt
bitMask = foldl (.|.) 0 . fmap (fromIntegral . fromEnum)
maybeString :: Maybe String -> (Ptr CChar -> IO c) -> IO c
maybeString Nothing fn = fn nullPtr
maybeString (Just val) fn = withCString val fn
maybeTxn :: Maybe MdbxTxn -> (MdbxTxn -> IO c) -> IO c
maybeTxn Nothing fn = fn (MdbxTxn nullPtr)
maybeTxn (Just val) fn = fn val
withMaybe :: Storable a => Maybe a -> (Ptr a -> IO c) -> IO c
withMaybe :: Maybe a -> (Ptr a -> IO c) -> IO c
withMaybe Maybe a
Nothing Ptr a -> IO c
fn = Ptr a -> IO c
fn Ptr a
forall a. Ptr a
nullPtr
withMaybe (Just a
val) Ptr a -> IO c
fn = a -> (Ptr a -> IO c) -> IO c
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with a
val Ptr a -> IO c
fn
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_env_create"
mdbx_env_create'_ :: ((C2HSImp.Ptr (MdbxEnv)) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_env_open"
mdbx_env_open'_ :: ((MdbxEnv) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (MdbxEnvMode -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_env_close"
mdbx_env_close'_ :: ((MdbxEnv) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_txn_begin"
mdbx_txn_begin'_ :: ((MdbxEnv) -> ((MdbxTxn) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (MdbxTxn)) -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_txn_commit"
mdbx_txn_commit'_ :: ((MdbxTxn) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_txn_abort"
mdbx_txn_abort'_ :: ((MdbxTxn) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_txn_env"
mdbx_txn_env'_ :: ((MdbxTxn) -> (IO (MdbxEnv)))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_dbi_open"
mdbx_dbi_open'_ :: ((MdbxTxn) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr MdbxDbi) -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_dbi_close"
mdbx_dbi_close'_ :: ((MdbxEnv) -> (MdbxDbi -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_put"
mdbx_put'_ :: ((MdbxTxn) -> (MdbxDbi -> ((MdbxValPtr) -> ((MdbxValPtr) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_get"
mdbx_get'_ :: ((MdbxTxn) -> (MdbxDbi -> ((MdbxValPtr) -> ((MdbxValPtr) -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_del"
mdbx_del'_ :: ((MdbxTxn) -> (MdbxDbi -> ((MdbxValPtr) -> ((MdbxValPtr) -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cursor_open"
mdbx_cursor_open'_ :: ((MdbxTxn) -> (MdbxDbi -> ((C2HSImp.Ptr (MdbxCursor)) -> (IO C2HSImp.CInt))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cursor_close"
mdbx_cursor_close'_ :: ((MdbxCursor) -> (IO ()))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cursor_del"
mdbx_cursor_del'_ :: ((MdbxCursor) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cursor_get"
mdbx_cursor_get'_ :: ((MdbxCursor) -> ((MdbxValPtr) -> ((MdbxValPtr) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cursor_put"
mdbx_cursor_put'_ :: ((MdbxCursor) -> ((MdbxValPtr) -> ((MdbxValPtr) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cursor_count"
mdbx_cursor_count'_ :: ((MdbxCursor) -> ((C2HSImp.Ptr CSize) -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_strerror"
mdbx_strerror'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
foreign import ccall unsafe "Mdbx/FFI.chs.h mdbx_cmp"
mdbx_cmp'_ :: ((MdbxTxn) -> (MdbxDbi -> ((MdbxValPtr) -> ((MdbxValPtr) -> (IO C2HSImp.CInt)))))