Merge rust-bitcoin/rust-secp256k1#663: Patch out any instances of printf in upstream

7a0c60edcd secp256k1-sys: patch out checked_malloc (Andrew Poelstra)
942a0e5e2c build.rs: patch out any calls to `printf` (Andrew Poelstra)
51dab7ac04 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 7a0c60edcd
  Kixunil:
    ACK 7a0c60edcd

Tree-SHA512: 83ba70b000919fb8a929804c9d5929a9929b80515f0594925d3789ef896889d3c909f9fa920bac45470611607b84f509723544fa442ff1a51eefba0de75bf68f
This commit is contained in:
Andrew Poelstra 2023-11-15 18:24:59 +00:00
commit 023d50b4db
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 19 additions and 14 deletions

View File

@ -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

View File

@ -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>
@ -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__)

View File

@ -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;