mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
setup: make all htables use tal.
This makes them easier to clean up. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ccan/ccan/err/err.h>
|
#include <ccan/ccan/err/err.h>
|
||||||
|
#include <ccan/ccan/htable/htable.h>
|
||||||
#include <common/autodata.h>
|
#include <common/autodata.h>
|
||||||
#include <common/setup.h>
|
#include <common/setup.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
@@ -24,6 +25,15 @@ static struct wally_operations wally_tal_ops = {
|
|||||||
.free_fn = wally_free,
|
.free_fn = wally_free,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void *htable_tal(struct htable *ht, size_t len)
|
||||||
|
{
|
||||||
|
return tal_arrz(ht, u8, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void htable_tal_free(struct htable *ht, void *p)
|
||||||
|
{
|
||||||
|
tal_free(p);
|
||||||
|
}
|
||||||
|
|
||||||
void common_setup(const char *argv0)
|
void common_setup(const char *argv0)
|
||||||
{
|
{
|
||||||
@@ -47,6 +57,9 @@ void common_setup(const char *argv0)
|
|||||||
errx(1, "Error setting libwally operations: %i", wally_ret);
|
errx(1, "Error setting libwally operations: %i", wally_ret);
|
||||||
secp256k1_ctx = wally_get_secp_context();
|
secp256k1_ctx = wally_get_secp_context();
|
||||||
|
|
||||||
|
/* Make htable* use tal for the tables themselves. */
|
||||||
|
htable_set_allocator(htable_tal, htable_tal_free);
|
||||||
|
|
||||||
setup_tmpctx();
|
setup_tmpctx();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,9 +172,14 @@ int main(int argc, char *argv[])
|
|||||||
assert(htable_count(f->cur) == 0);
|
assert(htable_count(f->cur) == 0);
|
||||||
assert(htable_count(f->old) == 0);
|
assert(htable_count(f->old) == 0);
|
||||||
|
|
||||||
/* They should have no children, and f should only have 2. */
|
/* They should have no children (except htable contents for one!), and
|
||||||
assert(!tal_first(f->cur));
|
* f should only have 2. */
|
||||||
assert(!tal_first(f->old));
|
if (tal_first(f->cur) == NULL)
|
||||||
|
assert(tal_first(f->old) == f->old->table);
|
||||||
|
else {
|
||||||
|
assert(tal_first(f->cur) == f->cur->table);
|
||||||
|
assert(tal_first(f->old) == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
assert((tal_first(f) == f->cur
|
assert((tal_first(f) == f->cur
|
||||||
&& tal_next(f->cur) == f->old
|
&& tal_next(f->cur) == f->old
|
||||||
|
|||||||
Reference in New Issue
Block a user