Skip to content

Commit 63a3d0b

Browse files
committed
fix: Add C shim for static context to address Windows MinGW64 runtime failure
This change attempts to address a Windows MinGW64 runtime failure that occurs during testing, where we see a "32 bit pseudo relocation out of range" error. The error suggests an issue with how GHC handles pointers in Windows executables. 1. Adds a C shim (hs_secp256k1_shim.c) to handle the static context 2. Updates the Haskell FFI bindings to use the shim instead of direct access 3. Bumps version to 0.3.1 to reflect the FFI interface change
1 parent 9db4d62 commit 63a3d0b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

cbits/hs_secp256k1_shim.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <secp256k1.h>
2+
3+
/* Returns the adress of the library's built-in context */
4+
const secp256k1_context* hs_secp256k1_content_static(void)
5+
{
6+
return secp256k1_context_static;
7+
}

libsecp256k1.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: libsecp256k1
8-
version: 0.2.1
8+
version: 0.3.1
99
synopsis: Bindings for secp256k1
1010
description: Sign and verify signatures using the secp256k1 library.
1111
category: Crypto
@@ -35,6 +35,8 @@ library
3535
Paths_libsecp256k1
3636
hs-source-dirs:
3737
src
38+
c-sources:
39+
cbits/hs_secp256k1_shim.c
3840
default-extensions:
3941
ImportQualifiedPost
4042
pkgconfig-depends:

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: libsecp256k1
2-
version: 0.2.1
2+
version: 0.3.1
33
synopsis: Bindings for secp256k1
44
description: Sign and verify signatures using the secp256k1 library.
55
category: Crypto

src/Crypto/Secp256k1/Prim.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ foreign import capi safe "secp256k1.h secp256k1_context_destroy"
302302
-- type serialization/parsing functions which require a context object to maintain
303303
-- API consistency, but currently do not require expensive precomputations or dynamic
304304
-- allocations.
305-
foreign import ccall unsafe "secp256k1.h secp256k1_context_no_precomp"
306-
contextNoPrecomp :: Ctx
305+
foreign import ccall unsafe "hs_secp256k1_content_static"
306+
c_contextStatic :: IO Ctx
307+
308+
{-# NOINLINE contextStatic #-}
309+
contextStatic :: Ctx
310+
contextStatic = unsafePerformIO c_contextStatic
307311

308312

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

0 commit comments

Comments
 (0)