-
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
Don't #include standard library headers unconditionally #1095
Comments
The header `stdio.h` is only needed to get access to `fprintf` used in code ifdef guarded by `USE_EXTERNAL_DEFAULT_CALLBACKS`, we can therefore guard the include statement in the same manner. The reason for doing this as that wasm builds in downstream user code have to patch in an empty `stdio.h` file in order to build because of this unconditional include. ref: https://github.com/rust-bitcoin/rust-secp256k1/blob/master/secp256k1-sys/depend/secp256k1.c.patch Fix: bitcoin-core#1095
Would it be acceptable to 'if guard' any code that calls E.g., in
|
The header `stdio.h` is only needed in code ifdef guarded by `USE_EXTERNAL_DEFAULT_CALLBACKS`, we can therefore guard the include statement in the same manner. The reason for doing this as that wasm builds in downstream user code have to patch in an empty `stdio.h` file in order to build because of this unconditional include. ref: https://github.com/rust-bitcoin/rust-secp256k1/blob/master/secp256k1-sys/depend/secp256k1.c.patch This patch does the first part of bitcoin-core#1095
This is in general the way to go. But then, when building the library itself, you would then need 'if guard' also functions like Maybe a cleaner approach would be to reorganize headers such that most functions are in some header like It would be good to know that @sipa and @jonasnick think about this because reorganizing headers would be a pretty fundamental decision.
|
Great, thanks. I'm happy to work on this under direction but I'm conscious of bumbling around changing things and generally being annoying. Like I said elsewhere I haven't touched C code for 5 years so there will likely be lots of stylistic problems to catch in review. |
I really like this idea. On the other hand, I find it difficult to commit to this setup given the uncertain future of the context, the role of malloc and scratch spaces. @real-or-random says:
I don't think we have to 'if guard' these functions entirely. We could also just change them to something like:
Less clean for sure than your suggestion, but not terrible imo. |
6a965b6 Remove usage of CHECK from non-test file (Tobin C. Harding) Pull request description: Currently CHECK is used only in test and bench mark files except for one usage in `ecmult_impl.h`. We would like to move the definition of CHECK out of `util.h` so that `util.h` no longer has a hard dependency on `stdio.h`. Done as part of an effort to allow secp256k1 to be compiled to WASM as part of `rust-secp256k1`. ### Note to reviewers Please review carefully, I don't actually know if this patch is correct. Done while working on #1095. I'm happy to make any changes both in concept and execution - I'm super rusty at C programming. cc real-or-random ACKs for top commit: sipa: utACK 6a965b6 real-or-random: utACK 6a965b6 Tree-SHA512: 6bfb456bdb92a831acd3bc202607e80f6d0a194d6b2cf745c8eceb12ba675d03a319d6d105332b0cbca474e443969295e5a8e938635453e21e057d0ee597440b
I'm happy with either approach:
|
The conclusion of my prototype for the latter option (#1166) is that we should do the former. |
We currently include <stdio.h> for
fprintf
used in the a) tests and b) in the default error callbacks ... We should not include the header unconditionally.secp256k1/src/util.h
Line 16 in 912b7cc
This is a problem downstream in rust-bitcoin/rust-secp256k1#421 .
edit:
We have a similar issue for
stdlib.h
but it is a little bit more complicated. It hasabort
, andmalloc
/free
. The story forabort
is the same as forfprintf
. Strictly speaking one doesn't needmalloc
/free
if one uses the prealloc interface but we don't provide consistent include headers for this. (You'll need the normal plus the prealloc header...) So people need to patch our sources which is anything but elegant. https://github.com/rust-bitcoin/rust-secp256k1/blob/master/secp256k1-sys/depend/secp256k1.c.patchThe text was updated successfully, but these errors were encountered: