Skip to content

Commit

Permalink
Update Haskell bindings (#495)
Browse files Browse the repository at this point in the history
* update for latest transformers + either

* not used

* for older ghc compat
  • Loading branch information
vmchale authored Jul 8, 2021
1 parent e154785 commit be0f29f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions bindings/haskell/keystone.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ library
other-modules: Keystone.Internal.Util
build-depends: base >= 4 && < 5
, bytestring >= 0.9.1
, transformers < 0.6
, either >= 4.4
, transformers >= 0.4 && < 0.6
hs-source-dirs: src
c-sources: src/cbits/keystone_wrapper.c
include-dirs: src/include
Expand Down
14 changes: 7 additions & 7 deletions bindings/haskell/src/Keystone.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Keystone
) where

import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Either (left, right, runEitherT)
import Control.Monad.Trans.Except (runExceptT, throwE)
import Data.ByteString (ByteString, packCStringLen)
import Data.List (intercalate)
import Foreign
Expand All @@ -50,7 +50,7 @@ runAssembler :: Assembler a -- ^ The assembler code to execute
-> IO (Either Error a) -- ^ A result on success, or an 'Error' on
-- failure
runAssembler =
runEitherT
runExceptT

-- | Create a new instance of the Keystone assembler.
open :: Architecture -- ^ CPU architecture
Expand All @@ -65,7 +65,7 @@ open arch mode = do
lift $ mkEngine ksPtr
else
-- Otherwise return an error
left err
throwE err

option :: Engine -- ^ 'Keystone' engine handle
-> OptionType -- ^ Type of option to set
Expand All @@ -74,9 +74,9 @@ option :: Engine -- ^ 'Keystone' engine handle
option ks optType optValue = do
err <- lift $ ksOption ks optType optValue
if err == ErrOk then
right ()
return ()
else
left err
throwE err

-- | Assemble a list of statements.
assemble :: Engine -- ^ 'Keystone' engine handle
Expand All @@ -97,11 +97,11 @@ assemble ks stmts addr = do
-- statement count
bs <- lift $ packCStringLen (castPtr encPtr, encSize)
lift $ ksFree encPtr
right (bs, statCount)
return (bs, statCount)
else do
-- On failure, call errno for error code
err <- errno ks
left err
throwE err
where maybeZ = maybe 0 id

-------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions bindings/haskell/src/Keystone/Internal/Core.chs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ way cabal handles ordering of chs files.
module Keystone.Internal.Core where

import Control.Monad
import Control.Monad.Trans.Either (EitherT)
import Control.Monad.Trans.Except (ExceptT)
import Foreign

{# context lib = "keystone" #}
Expand Down Expand Up @@ -48,4 +48,4 @@ mkEngine ptr =

-- | The assembler runs in the IO monad and allows for the handling of errors
-- "under the hood".
type Assembler a = EitherT Error IO a
type Assembler a = ExceptT Error IO a
1 change: 1 addition & 0 deletions bindings/haskell/src/Keystone/Internal/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ License : GPL-2
-}
module Keystone.Internal.Util where

import Control.Applicative ((<$>))
import Data.Bits

-- | Combine a list of Enums by performing a bitwise-OR.
Expand Down

0 comments on commit be0f29f

Please sign in to comment.