-
Notifications
You must be signed in to change notification settings - Fork 1k
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
secp256k1_context_static
should be a const
variable [edited]
#1637
Comments
Can you elaborate a bit? Which bindings and what are the issues? |
In Swift, when
This is definitely a false positive, because the instance is I remember having had issues with exported variables in the past with other languages. I don't remember the exact details. It may have been with Javascript, Go, Lua, or Matlab. It is less of an issue when the variable is of a builtin type, which is the case here with a pointer. While it is easily possible to find work-arounds for any ffi, providing functions only is just more intuitive. Consider this Python: >>> from ctypes import CDLL
>>> lib = CDLL("libsecp256k1.5.dylib")
>>> lib
<CDLL 'libsecp256k1.5.dylib', handle 6d672be0 at 0x102b3a430>
>>> lib.secp256k1_selftest
<_FuncPtr object at 0x102b83340>
>>> lib.secp256k1_selftest()
-1486072369
>>> lib.secp256k1_context_static
<_FuncPtr object at 0x102b83a00> # <--- orly?
>>> lib.secp256k1_context_static()
fish: Job 1, 'python3' terminated by signal SIGBUS (Misaligned address error) |
Not sure. A pointer to Anyway, I agree that if Swift's FFI is happy with a function that returns a pointer to const, then it should also be happy with a variable of the same type... I don't think it hurts to add something like this:
But then we'd need to do the same for all the other exported variables (and add a rule to |
The Swift FFI is right, actually. The variable I think we should change the definition from const secp256k1_context *secp256k1_context_static = &secp256k1_context_static_; to: const secp256k1_context * const secp256k1_context_static = &secp256k1_context_static_; (and similarly in the .h file) |
Oh, indeed. @purpleKarrot Can you check if this solves your problem? |
Yes. I confirm this fixes the problem: 5f6bacc |
Great, are you willing to open a PR? |
secp256k1_context_static
should be a const
variable [edited]
I took the liberty to edit the title of the issue. |
Some language bindings have issues with exported variables. The static context is currently exported as a variable:
which is implemented as:
A more portable way would be to provide it through a function:
with implementation:
PS: It is clear that changing the symbol into a function is a breaking change and therefore off the table. However, please consider adding a new symbol with the proposed implementation.
The text was updated successfully, but these errors were encountered: