I am attempting to create bindings from the C library libsecp256k1 into Scheme (the guile implementation) but I am guessing my question applies to other target languages. Say I want to export the function secp256k1_context_create: this function expects an int as an argument which can be one of the macros SECP256K1_CONTEXT_VERIFY, SECP256K1_CONTEXT_SIGN or SECP256K1_CONTEXT_NONE. Now these macros are part of the C API, but as far I can tell there is no way to access their values from the shared library:

$ cd /usr/local/lib
$ nm libsecp256k1.so
... (no names relating to flag values)

So it seems I need to define my own values for the flags in the target language:

(define %context-verify 257)
(define %context-sign 513)
(define %context-none 1)

However, in doing so, I am hard-coding implementation details, which means my target language library could break despite the C API being stable (actually I am not sure whether this constitute an API change if existing object code needs to be recompiled, ABI change?). Could anyone let me know whether I have missed anything, or whether there is a better approach to this problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.