PROTOTYPE Split headers to make it possible to use only prealloc API #1166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On top of #1126.
This prototypes one possible approach to solve #1095 by implementing the approach described in #1095 (comment):
Now that I've been working on this, I don't like this approach for various reasons:
secp256k1_(preallocated).h
, whereas the static context, flags, randomization, and callbacks are insecp256k1_main.h
. This is hard to grasp for new users and also add confusion for users who don't need the preallocated interface.#include "secp256k1.h"
from the module headers such assecp256k1_ecdh.h
(because otherwise you couldn't include the module header if you want only the prealloc interface). This means thatsecp256k1_ecdh.h
and notsecp256k1_ecdh.h
.secp256k1_(preallocated).h
and thensecp256k1_ecdh.h
because the latter needs the declaration ofsecp256k1_context
(and we couldn't even repeat that declaration somewhere to workaround this problem: Compiler tells uswarning: redefinition of typedef 'secp256k1_context' is a C11 feature
...)So I think this PR would indeed make it possible to use only the prealloc interface, but it makes the life harder for everyone, in particular for normal users who have malloc and don't even care about prealloc. I think we should switch to an approach with a macro like
PREALLOC_INTERFACE_ONLY
that you need to set before includingsecp256k1.h
(and when compiling the library itself) and that will remove all the functions that depend on malloc. But please tell me if you disagree.