Skip to content

Commit 023d50b

Browse files
committed
Merge #663: Patch out any instances of printf in upstream
7a0c60e secp256k1-sys: patch out checked_malloc (Andrew Poelstra) 942a0e5 build.rs: patch out any calls to `printf` (Andrew Poelstra) 51dab7a vendor-libsecp: remove util.h patch (Andrew Poelstra) Pull request description: Rather than using a new patchfile, just `#define` it away. Also includes a commit which removes one of the existing patchfiles, which I discovered was out of date while auditing the others to see if they could be replaced by `#define`s. (No, they cannot.) Fixes #660 ACKs for top commit: tcharding: AFAICT this is right to go, ACK 7a0c60e Kixunil: ACK 7a0c60e Tree-SHA512: 83ba70b000919fb8a929804c9d5929a9929b80515f0594925d3789ef896889d3c909f9fa920bac45470611607b84f509723544fa442ff1a51eefba0de75bf68f
2 parents 4244fec + 7a0c60e commit 023d50b

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

secp256k1-sys/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ fn main() {
2020
.include("depend/secp256k1/include")
2121
.include("depend/secp256k1/src")
2222
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
23+
.flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning
2324
.define("SECP256K1_API", Some(""))
2425
.define("ENABLE_MODULE_ECDH", Some("1"))
2526
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
2627
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
27-
.define("ENABLE_MODULE_ELLSWIFT", Some("1"));
28+
.define("ENABLE_MODULE_ELLSWIFT", Some("1"))
29+
// upstream sometimes introduces calls to printf, which we cannot compile
30+
// with WASM due to its lack of libc. printf is never necessary and we can
31+
// just #define it away.
32+
.define("printf(...)", Some(""));
2833

2934
if cfg!(feature = "lowmemory") {
3035
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume negligible memory

secp256k1-sys/depend/secp256k1/src/util.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#define SECP256K1_UTIL_H
99

1010
#include "../include/secp256k1.h"
11-
extern int rustsecp256k1_v0_9_0_ecdsa_signature_parse_compact(
12-
const rustsecp256k1_v0_9_0_context *ctx,
13-
rustsecp256k1_v0_9_0_ecdsa_signature *sig, const unsigned char *input64);
11+
1412
#include <stdlib.h>
1513
#include <stdint.h>
1614
#include <stdio.h>
@@ -147,11 +145,9 @@ static const rustsecp256k1_v0_9_0_callback default_error_callback = {
147145
#endif
148146

149147
static SECP256K1_INLINE void *checked_malloc(const rustsecp256k1_v0_9_0_callback* cb, size_t size) {
150-
void *ret = malloc(size);
151-
if (ret == NULL) {
152-
rustsecp256k1_v0_9_0_callback_call(cb, "Out of memory");
153-
}
154-
return ret;
148+
(void) cb;
149+
(void) size;
150+
return NULL;
155151
}
156152

157153
#if defined(__BIGGEST_ALIGNMENT__)

secp256k1-sys/depend/util.h.patch

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
10c10,12
2-
<
1+
148,152c148,150
2+
< void *ret = malloc(size);
3+
< if (ret == NULL) {
4+
< secp256k1_callback_call(cb, "Out of memory");
5+
< }
6+
< return ret;
37
---
4-
> extern int secp256k1_ecdsa_signature_parse_compact(
5-
> const secp256k1_context *ctx,
6-
> secp256k1_ecdsa_signature *sig, const unsigned char *input64);
8+
> (void) cb;
9+
> (void) size;
10+
> return NULL;

0 commit comments

Comments
 (0)