-
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
Conditionally include stdio.h
and stdlib.h
#1148
Conversation
stdio.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, thanks!
This is a good opportunity to move the definitions of CHECK
and TEST_FAILURE
(but probably not EXPECT
to tests.c
, if you're willing to add a commit. Otherwise we can do it in a follow-up PR.
bah, sloppy work by me. I'll try first to fix the |
Sure thing, happy to look into it. |
EDIT: I realised after posting that all these files are either tests of benches, so I did #1149 I must be missing something, git grep -l ' CHECK\('
src/bench.c
src/bench_ecmult.c
src/bench_internal.c
src/ecmult_impl.h
src/modules/ecdh/bench_impl.h
src/modules/ecdh/tests_impl.h
src/modules/extrakeys/tests_exhaustive_impl.h
src/modules/extrakeys/tests_impl.h
src/modules/recovery/bench_impl.h
src/modules/recovery/tests_exhaustive_impl.h
src/modules/recovery/tests_impl.h
src/modules/schnorrsig/bench_impl.h
src/modules/schnorrsig/tests_exhaustive_impl.h
src/modules/schnorrsig/tests_impl.h
src/tests.c
src/tests_exhaustive.c
src/util.h
src/valgrind_ctime_test.c |
d185a6f
to
6dfbbb4
Compare
6dfbbb4
to
c36765f
Compare
I had a play with this @real-or-random but got stuck, leaving for another day. The investigation did lead me however to the observation, now implemented in patch 1, to conditionally include |
c36765f
to
77d97d9
Compare
stdio.h
stdio.h
and stdlib.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK mod nit for the first commit
As for the second commit, if I compile with PREALLOC_INTERFACE_ONLY
defined, I get a bunch of errors and warnings. I tried to fix them in my branch until I realized that stdlib is still needed for checked_malloc/realloc
, i.e., compilation of my branch with ./configure CPPFLAGS="-DPREALLOC_INTERFACE_ONLY -DUSE_EXTERNAL_DEFAULT_CALLBACKS"
will error out because of that (if we manage to get this to work nonetheless we should add a CI test for PREALLOC_INTERFACE_ONLY
that at least tests successful compilation).
src/util.h
Outdated
#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS | ||
#include <stdio.h> | ||
#endif | ||
|
||
#ifdef VERIFY | ||
#include <stdio.h> | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
#if defined(VERIFY) || !defined(USE_EXTERNAL_DEFAULT_CALLBACKS)
#include <stdio.h>
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers, rebased and used the suggestion in patch 1.
Can a maintainer please confirm you guys use this process, that this rebasing to keep the PR consisting of only the valid patch series.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks mate.
The header `stdio.h` is only needed in code ifdef guarded by `USE_EXTERNAL_DEFAULT_CALLBACKS` and also (indirectly) by `VERIFY`, we can therefore guard the include statement in the same manner. The reason for doing this as that wasm builds downstream have to patch in an empty `stdio.h` file in order to build because of the unconditional include.
If we are using the preallocated interface only then stdlib.h is not required. Currently we unconditionally include it. Add ifdef guards around any code that uses malloc and friends and then conditionally include `stdlib.h` based on `PREALLOC_INTERFACE_ONLY`. The benefit of this patch is that downstream users who wish to build libsecp256k1 into WASM will not need to patch into their build an empty `stdlib.h` file.
77d97d9
to
303a201
Compare
Any clues on the CI fail crew?
Can I view |
Oh that's a failure that's expected to occur with a certain low (but still too high to be annoying) probability, see #367 if you're interested in the details. I've restarted the job. |
Thanks! |
To be honest, I think we should take a step back and first discuss whether we would like to separate the headers as I suggested in #1095 (comment). That looks like a very fundamental change but it should be backwards compatible. That would be cleaner and it would make this PR here obsolete. Let me still comment on the PR.
The proper way to do this is to just wrap the Before I came to this realization, I was about to comment that I think we don't want to change In general, it's a little bit inelegant to make
Arguably that's maybe not terribly useful if you also set
Well testing is another problem. Many of the tests currently error out when they can't call |
Thanks @real-or-random, I don't think chopping up headers is a good task for someone new to a project, I'm going to leave this one for now. Will move the PR to draft for the discussion to indicate its not a merge candidate. |
No forward path, closing. |
Indeed. It's tracked in #1095, I hope I can come back to this soon. This is a major pain point for users. |
stddef.h is available for wasm while stdio.h is not available. See bitcoin-core/secp256k1#1149 See bitcoin-core/secp256k1#1148
stddef.h is available for wasm while stdio.h is not available. See bitcoin-core/secp256k1#1149 See bitcoin-core/secp256k1#1148
stddef.h is available for wasm while stdio.h is not available. See bitcoin-core/secp256k1#1149 See bitcoin-core/secp256k1#1148
stddef.h is available for wasm while stdio.h is not available. See bitcoin-core/secp256k1#1149 See bitcoin-core/secp256k1#1148
Currently in order to use
secp256k1
in WASM builds one must patch into the build system empty header files forstdlib.h
andstdio.h
[0].stdio.h
based on the presence ofUSE_EXTERNAL_DEFAULT_CALLBACKS
andVERIFY
.PREALLOC_INTERFACE_ONLY
and ifndef guards any calls to malloc and friends as well as the include ofstdio.h
.Works towards fixing: #1095
1095 does not mention
string.h
but it is a problem as well. I cannot work out how to resolve it so attempting to push this in without it. Happy to extend this further if anyone has any ideas.Notes on testing
I could not work out how to test this in
rust-secp256k1
so the I have not proved that this PR removes the requirement to include empty headers described above.[0] - https://github.com/rust-bitcoin/rust-secp256k1/blob/master/secp256k1-sys/depend/secp256k1.c.patch