Created
January 10, 2025 10:59
-
-
Save phadej/059993b3d430515fd97a3ee6033510c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal-version: 3.0 | |
name: callback-exception | |
version: 0 | |
executable problem | |
build-depends: base | |
include-dirs: include | |
hs-source-dirs: src | |
main-is: problem.hs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline int function( int(*callback)(int), int x) { | |
return callback(x); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ForeignFunctionInterface #-} | |
{-# LANGUAGE CApiFFI #-} | |
{-# LANGUAGE TypeApplications #-} | |
module Main (main) where | |
import Control.Exception | |
import Foreign | |
import Foreign.C.Types | |
x :: Int | |
x = 10 | |
foreign import ccall "wrapper" mkWrapper :: (CInt -> IO CInt) -> IO (FunPtr (CInt -> IO CInt)) | |
foreign import capi "ce.h function" func :: FunPtr (CInt -> IO CInt) -> CInt -> IO CInt | |
main :: IO () | |
main = do | |
w <- mkWrapper $ \_ -> fail "blargh" | |
res <- try @SomeException $ func w 10 | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment