Browse Source

wally: override wally to use tal-context

See attached. This lets us do fancy things with tal_steal
nifty/pset-pre
niftynei 5 years ago
committed by Rusty Russell
parent
commit
c5a0d8cfbf
  1. 22
      common/daemon.c

22
common/daemon.c

@ -18,6 +18,8 @@
#include <unistd.h> #include <unistd.h>
#include <wally_core.h> #include <wally_core.h>
static const tal_t *wally_tal_ctx;
#if BACKTRACE_SUPPORTED #if BACKTRACE_SUPPORTED
static void (*bt_print)(const char *fmt, ...) PRINTF_FMT(1,2); static void (*bt_print)(const char *fmt, ...) PRINTF_FMT(1,2);
static void (*bt_exit)(void); static void (*bt_exit)(void);
@ -119,6 +121,21 @@ static void add_steal_notifiers(const tal_t *root)
} }
#endif #endif
static void *wally_tal(size_t size)
{
return tal_arr_label(wally_tal_ctx, u8, size, "wally_notleak");
}
static void wally_free(void *ptr)
{
tal_free(ptr);
}
static struct wally_operations wally_tal_ops = {
.malloc_fn = wally_tal,
.free_fn = wally_free,
};
void daemon_setup(const char *argv0, void daemon_setup(const char *argv0,
void (*backtrace_print)(const char *fmt, ...), void (*backtrace_print)(const char *fmt, ...),
void (*backtrace_exit)(void)) void (*backtrace_exit)(void))
@ -153,7 +170,11 @@ void daemon_setup(const char *argv0,
/* We handle write returning errors! */ /* We handle write returning errors! */
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
/* We set up Wally, the bitcoin wallet lib */
wally_tal_ctx = tal_label(NULL, char, "wally_ctx_notleak");
wally_init(0); wally_init(0);
wally_set_operations(&wally_tal_ops);
secp256k1_ctx = wally_get_secp_context(); secp256k1_ctx = wally_get_secp_context();
setup_tmpctx(); setup_tmpctx();
@ -164,6 +185,7 @@ void daemon_shutdown(void)
{ {
tal_free(tmpctx); tal_free(tmpctx);
wally_cleanup(0); wally_cleanup(0);
wally_free(wally_tal_ctx);
} }
void daemon_maybe_debug(char *argv[]) void daemon_maybe_debug(char *argv[])

Loading…
Cancel
Save