Skip to content

Commit

Permalink
Merge rust-bitcoin#663: Patch out any instances of printf in upstream
Browse files Browse the repository at this point in the history
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 rust-bitcoin#660

ACKs for top commit:
  tcharding:
    AFAICT this is right to go, ACK 7a0c60e
  Kixunil:
    ACK 7a0c60e

Tree-SHA512: 83ba70b000919fb8a929804c9d5929a9929b80515f0594925d3789ef896889d3c909f9fa920bac45470611607b84f509723544fa442ff1a51eefba0de75bf68f
  • Loading branch information
apoelstra committed Nov 15, 2023
2 parents 4244fec + 7a0c60e commit 023d50b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
7 changes: 6 additions & 1 deletion secp256k1-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ fn main() {
.include("depend/secp256k1/include")
.include("depend/secp256k1/src")
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
.flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning
.define("SECP256K1_API", Some(""))
.define("ENABLE_MODULE_ECDH", Some("1"))
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
.define("ENABLE_MODULE_ELLSWIFT", Some("1"));
.define("ENABLE_MODULE_ELLSWIFT", Some("1"))
// upstream sometimes introduces calls to printf, which we cannot compile
// with WASM due to its lack of libc. printf is never necessary and we can
// just #define it away.
.define("printf(...)", Some(""));

if cfg!(feature = "lowmemory") {
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume negligible memory
Expand Down
12 changes: 4 additions & 8 deletions secp256k1-sys/depend/secp256k1/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#define SECP256K1_UTIL_H

#include "../include/secp256k1.h"
extern int rustsecp256k1_v0_9_0_ecdsa_signature_parse_compact(
const rustsecp256k1_v0_9_0_context *ctx,
rustsecp256k1_v0_9_0_ecdsa_signature *sig, const unsigned char *input64);

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -147,11 +145,9 @@ static const rustsecp256k1_v0_9_0_callback default_error_callback = {
#endif

static SECP256K1_INLINE void *checked_malloc(const rustsecp256k1_v0_9_0_callback* cb, size_t size) {
void *ret = malloc(size);
if (ret == NULL) {
rustsecp256k1_v0_9_0_callback_call(cb, "Out of memory");
}
return ret;
(void) cb;
(void) size;
return NULL;
}

#if defined(__BIGGEST_ALIGNMENT__)
Expand Down
14 changes: 9 additions & 5 deletions secp256k1-sys/depend/util.h.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
10c10,12
<
148,152c148,150
< void *ret = malloc(size);
< if (ret == NULL) {
< secp256k1_callback_call(cb, "Out of memory");
< }
< return ret;
---
> extern int secp256k1_ecdsa_signature_parse_compact(
> const secp256k1_context *ctx,
> secp256k1_ecdsa_signature *sig, const unsigned char *input64);
> (void) cb;
> (void) size;
> return NULL;

0 comments on commit 023d50b

Please sign in to comment.