Skip to content

Commit

Permalink
ffi: fix on windows, hopefully. ci will show
Browse files Browse the repository at this point in the history
  • Loading branch information
rockofox committed Dec 24, 2023
1 parent a7ee474 commit f4e4eee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion indigo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ library
if flag(ffi)
build-depends:
libffi,
unix
if os(windows)
build-depends: Win32
else
build-depends: unix
cpp-options: -DFFI

hs-source-dirs: lib
Expand Down
10 changes: 5 additions & 5 deletions lib/Ffi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ffi where

import Foreign.Ptr (FunPtr)

#if defined(MIN_VERSION_Win32)
#if defined(mingw32_HOST_OS)
import Control.Exception (bracket)
import Foreign.Ptr (castPtrToFunPtr)
import System.Win32.DLL
Expand Down Expand Up @@ -37,15 +37,15 @@ dllext = "so"
#endif

-- | The Haskell representation of a loaded dynamic library.
#if defined(MIN_VERSION_Win32)
#if defined(mingw32_HOST_OS)
type DynLib = HMODULE
#else
type DynLib = DL
#endif

-- | Return the address of a function symbol contained in a dynamic library.
dynLibSym :: DynLib -> String -> IO (FunPtr a)
#if defined(MIN_VERSION_Win32)
#if defined(mingw32_HOST_OS)
dynLibSym source symbol = do
addr <- getProcAddress source symbol
return $ castPtrToFunPtr addr
Expand All @@ -55,15 +55,15 @@ dynLibSym = dlsym

-- | Load a dynamic library, perform some action on it, and then free it.
withDynLib :: FilePath -> (DynLib -> IO a) -> IO a
#if defined(MIN_VERSION_Win32)
#if defined(mingw32_HOST_OS)
withDynLib file f = bracket (loadLibrary file) freeLibrary f
#else
withDynLib file = withDL file [RTLD_NOW]
#endif

-- | Open a dynamic library.
dynLibOpen :: FilePath -> IO DynLib
#if defined(MIN_VERSION_Win32)
#if defined(mingw32_HOST_OS)
dynLibOpen = loadLibrary
#else
dynLibOpen x = dlopen x [RTLD_NOW]
Expand Down

0 comments on commit f4e4eee

Please sign in to comment.