Made some FFI related code evaluate things more.

- Previously some foreign values were wrapped up as thunks, which moved
  around where runtime errors occured a bit.
This commit is contained in:
Dan Doel 2021-07-08 10:35:27 -04:00
parent 1c2cdd4a87
commit de2b83eeb7
2 changed files with 3 additions and 2 deletions

View File

@ -33,7 +33,7 @@ import qualified Crypto.Hash as Hash
import Unsafe.Coerce
data Foreign where
Wrap :: Reference -> e -> Foreign
Wrap :: Reference -> !e -> Foreign
promote :: (a -> a -> r) -> b -> c -> r
promote (~~) x y = unsafeCoerce x ~~ unsafeCoerce y

View File

@ -16,6 +16,7 @@ import GHC.IO.Exception (IOException(..), IOErrorType(..))
import Control.Concurrent (ThreadId)
import Control.Concurrent.MVar (MVar)
import Control.Concurrent.STM (TVar)
import Control.Exception (evaluate)
import qualified Data.Char as Char
import Data.Foldable (toList)
import Data.Text (Text, pack, unpack)
@ -95,7 +96,7 @@ instance ForeignConvention Closure where
readForeign _ [ ] _ _ = foreignCCError "Closure"
writeForeign ustk bstk c = do
bstk <- bump bstk
(ustk, bstk) <$ poke bstk c
(ustk, bstk) <$ (poke bstk =<< evaluate c)
instance ForeignConvention Text where
readForeign = readForeignBuiltin