Skip to content

C shim for static context to address Windows MinGW64 runtime failure #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cbits/hs_secp256k1_shim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <secp256k1.h>

/* Returns the adress of the library's built-in context */
const secp256k1_context* hs_secp256k1_content_static(void)
{
return secp256k1_context_static;
}
4 changes: 3 additions & 1 deletion libsecp256k1.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: libsecp256k1
version: 0.2.1
version: 0.3.1
synopsis: Bindings for secp256k1
description: Sign and verify signatures using the secp256k1 library.
category: Crypto
Expand Down Expand Up @@ -35,6 +35,8 @@ library
Paths_libsecp256k1
hs-source-dirs:
src
c-sources:
cbits/hs_secp256k1_shim.c
default-extensions:
ImportQualifiedPost
pkgconfig-depends:
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: libsecp256k1
version: 0.2.1
version: 0.3.1
synopsis: Bindings for secp256k1
description: Sign and verify signatures using the secp256k1 library.
category: Crypto
Expand Down
10 changes: 7 additions & 3 deletions src/Crypto/Secp256k1/Prim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ foreign import capi safe "secp256k1.h secp256k1_context_destroy"
-- type serialization/parsing functions which require a context object to maintain
-- API consistency, but currently do not require expensive precomputations or dynamic
-- allocations.
foreign import ccall unsafe "secp256k1.h secp256k1_context_no_precomp"
contextNoPrecomp :: Ctx
foreign import ccall unsafe "hs_secp256k1_content_static"
c_contextStatic :: IO Ctx

{-# NOINLINE contextStatic #-}
contextStatic :: Ctx
contextStatic = unsafePerformIO c_contextStatic


-- | Copy a secp256k1 context object into caller-provided memory.
Expand Down Expand Up @@ -445,7 +449,7 @@ foreign import capi safe "secp256k1.h secp256k1_context_set_error_callback"
-- undefined.
--
-- When this function has not been called (or called with fn==NULL), then the
-- default handler will be used. The library provides a default handler which
-- default handler will be used. The library provides a default handler which
-- writes the message to stderr and calls abort. This default handler can be
-- replaced at link time if the preprocessor macro
-- USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build
Expand Down
Loading