aboutsummaryrefslogtreecommitdiff
path: root/src/Internal/Digest.chs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-04-28 17:03:04 -0700
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-04-28 17:03:04 -0700
commit226c84a6e5464ca74468e690250227f70e8fa1c8 (patch)
tree74200fbc5a3c1efb57b8d20a1c7fac9b1672b8d4 /src/Internal/Digest.chs
parent8acf77aede21ca6d82415639557306babe3c71bf (diff)
Factor out common resource create/initialize/set-finalizer cycle
Diffstat (limited to 'src/Internal/Digest.chs')
-rw-r--r--src/Internal/Digest.chs8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/Internal/Digest.chs b/src/Internal/Digest.chs
index d451f1c..4708c47 100644
--- a/src/Internal/Digest.chs
+++ b/src/Internal/Digest.chs
@@ -28,6 +28,7 @@ import Foreign
import Foreign.C.Types
import Foreign.Ptr.Cast (asVoidPtr)
+import Foreign.Ptr.CreateWithFinalizer (createWithFinalizer)
{#import Internal.Base#}
import Result
@@ -43,11 +44,8 @@ evpSHA512 = {#call pure EVP_sha512 as ^#}
-- | Memory-safe allocator for 'EVPMDCtx'.
mallocEVPMDCtx :: IO (ForeignPtr EVPMDCtx)
-mallocEVPMDCtx = do
- fp <- mallocForeignPtr
- withForeignPtr fp {#call EVP_MD_CTX_init as ^#}
- addForeignPtrFinalizer btlsFinalizeEVPMDCtxPtr fp
- return fp
+mallocEVPMDCtx =
+ createWithFinalizer {#call EVP_MD_CTX_init as ^#} btlsFinalizeEVPMDCtxPtr
foreign import ccall "&btlsFinalizeEVPMDCtx"
btlsFinalizeEVPMDCtxPtr :: FinalizerPtr EVPMDCtx