mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
Rename (almost) all destructors to destroy_<type>.
We usually did this, but sometimes they were named after what they did, rather than what they cleaned up. There are still a few exceptions: 1. I didn't bother creating destroy_xxx wrappers for htable routines which already existed. 2. Sometimes destructors really are used for side-effects (eg. to simply mark that something was freed): these are clearer with boutique names. 3. Generally destructors are static, but they don't need to be: in some cases we attach a destructor then remove it later, or only attach to *some* cases. These are best with qualifiers in the destroy_<type> name. Suggested-by: @ZmnSCPxj Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
6a3ccafaf9
commit
55d962046b
@@ -8,7 +8,7 @@ struct oneshot {
|
||||
void *arg;
|
||||
};
|
||||
|
||||
static void remove_timer(struct oneshot *t)
|
||||
static void destroy_timer(struct oneshot *t)
|
||||
{
|
||||
timer_del(t->timers, &t->timer);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ struct oneshot *new_reltimer_(struct timers *timers,
|
||||
t->timers = timers;
|
||||
timer_init(&t->timer);
|
||||
timer_addrel(timers, &t->timer, relexpiry);
|
||||
tal_add_destructor(t, remove_timer);
|
||||
tal_add_destructor(t, destroy_timer);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -580,8 +580,8 @@ struct routing_channel *routing_channel_new(const tal_t *ctx,
|
||||
return chan;
|
||||
}
|
||||
|
||||
static void remove_connection_from_channel(struct node_connection *nc,
|
||||
struct routing_state *rstate)
|
||||
static void destroy_node_connection(struct node_connection *nc,
|
||||
struct routing_state *rstate)
|
||||
{
|
||||
struct routing_channel *chan = uintmap_get(
|
||||
&rstate->channels, short_channel_id_to_uint(&nc->short_channel_id));
|
||||
@@ -600,7 +600,7 @@ void channel_add_connection(struct routing_state *rstate,
|
||||
int direction = get_channel_direction(&nc->src->id, &nc->dst->id);
|
||||
assert(chan != NULL);
|
||||
chan->connections[direction] = nc;
|
||||
tal_add_destructor2(nc, remove_connection_from_channel, rstate);
|
||||
tal_add_destructor2(nc, destroy_node_connection, rstate);
|
||||
}
|
||||
|
||||
static void add_pending_node_announcement(struct routing_state *rstate, struct pubkey *nodeid)
|
||||
|
||||
@@ -681,7 +681,7 @@ void chaintopology_mark_pointers_used(struct htable *memtable,
|
||||
|
||||
/* On shutdown, channels get deleted last. That frees from our list, so
|
||||
* do it now instead. */
|
||||
static void destroy_outgoing_txs(struct chain_topology *topo)
|
||||
static void destroy_chain_topology(struct chain_topology *topo)
|
||||
{
|
||||
struct outgoing_tx *otx;
|
||||
|
||||
@@ -724,7 +724,7 @@ void setup_topology(struct chain_topology *topo,
|
||||
|
||||
bitcoind_getblockcount(topo->bitcoind, get_init_blockhash, topo);
|
||||
|
||||
tal_add_destructor(topo, destroy_outgoing_txs);
|
||||
tal_add_destructor(topo, destroy_chain_topology);
|
||||
|
||||
/* Begin fee estimation. */
|
||||
start_fee_estimate(topo);
|
||||
|
||||
@@ -28,14 +28,14 @@ struct htlc_in *find_htlc_in(const struct htlc_in_map *map,
|
||||
return htlc_in_map_get(map, &key);
|
||||
}
|
||||
|
||||
static void remove_htlc_in(struct htlc_in *hend, struct htlc_in_map *map)
|
||||
static void destroy_htlc_in(struct htlc_in *hend, struct htlc_in_map *map)
|
||||
{
|
||||
htlc_in_map_del(map, hend);
|
||||
}
|
||||
|
||||
void connect_htlc_in(struct htlc_in_map *map, struct htlc_in *hend)
|
||||
{
|
||||
tal_add_destructor2(hend, remove_htlc_in, map);
|
||||
tal_add_destructor2(hend, destroy_htlc_in, map);
|
||||
htlc_in_map_add(map, hend);
|
||||
}
|
||||
|
||||
@@ -47,14 +47,14 @@ struct htlc_out *find_htlc_out(const struct htlc_out_map *map,
|
||||
return htlc_out_map_get(map, &key);
|
||||
}
|
||||
|
||||
static void remove_htlc_out(struct htlc_out *hend, struct htlc_out_map *map)
|
||||
static void destroy_htlc_out(struct htlc_out *hend, struct htlc_out_map *map)
|
||||
{
|
||||
htlc_out_map_del(map, hend);
|
||||
}
|
||||
|
||||
void connect_htlc_out(struct htlc_out_map *map, struct htlc_out *hend)
|
||||
{
|
||||
tal_add_destructor2(hend, remove_htlc_out, map);
|
||||
tal_add_destructor2(hend, destroy_htlc_out, map);
|
||||
htlc_out_map_add(map, hend);
|
||||
}
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ fail:
|
||||
*
|
||||
* We could queue this and wait for it to come back, but this is simple.
|
||||
*/
|
||||
static void hout_subd_died(struct htlc_out *hout)
|
||||
static void destroy_hout_subd_died(struct htlc_out *hout)
|
||||
{
|
||||
log_debug(hout->key.channel->log,
|
||||
"Failing HTLC %"PRIu64" due to peer death",
|
||||
@@ -355,7 +355,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds,
|
||||
local_fail_htlc(hout->in, failure_code,
|
||||
hout->key.channel->scid);
|
||||
/* Prevent hout from being failed twice. */
|
||||
tal_del_destructor(hout, hout_subd_died);
|
||||
tal_del_destructor(hout, destroy_hout_subd_died);
|
||||
tal_free(hout);
|
||||
return;
|
||||
}
|
||||
@@ -400,7 +400,7 @@ enum onion_type send_htlc_out(struct channel *out, u64 amount, u32 cltv,
|
||||
/* Make peer's daemon own it, catch if it dies. */
|
||||
hout = new_htlc_out(out->owner, out, amount, cltv,
|
||||
payment_hash, onion_routing_packet, in);
|
||||
tal_add_destructor(hout, hout_subd_died);
|
||||
tal_add_destructor(hout, destroy_hout_subd_died);
|
||||
|
||||
msg = towire_channel_offer_htlc(out, amount, cltv, payment_hash,
|
||||
onion_routing_packet);
|
||||
@@ -894,7 +894,7 @@ static bool update_out_htlc(struct channel *channel,
|
||||
|
||||
/* First transition into commitment; now it outlives peer. */
|
||||
if (newstate == SENT_ADD_COMMIT) {
|
||||
tal_del_destructor(hout, hout_subd_died);
|
||||
tal_del_destructor(hout, destroy_hout_subd_died);
|
||||
tal_steal(ld, hout);
|
||||
|
||||
} else if (newstate == RCVD_REMOVE_ACK_REVOCATION) {
|
||||
|
||||
@@ -48,7 +48,7 @@ struct subd_req {
|
||||
void *disabler;
|
||||
};
|
||||
|
||||
static void free_subd_req(struct subd_req *sr)
|
||||
static void destroy_subd_req(struct subd_req *sr)
|
||||
{
|
||||
list_del(&sr->list);
|
||||
/* Don't disable once we're freed! */
|
||||
@@ -98,7 +98,7 @@ static void add_req(const tal_t *ctx,
|
||||
|
||||
/* Keep in FIFO order: we sent in order, so replies will be too. */
|
||||
list_add_tail(&sd->reqs, &sr->list);
|
||||
tal_add_destructor(sr, free_subd_req);
|
||||
tal_add_destructor(sr, destroy_subd_req);
|
||||
}
|
||||
|
||||
/* Caller must free. */
|
||||
|
||||
@@ -283,7 +283,10 @@ sqlite3_stmt *PRINTF_FMT(3, 4)
|
||||
return stmt;
|
||||
}
|
||||
|
||||
static void close_db(struct db *db) { sqlite3_close(db->sql); }
|
||||
static void destroy_db(struct db *db)
|
||||
{
|
||||
sqlite3_close(db->sql);
|
||||
}
|
||||
|
||||
void db_begin_transaction_(struct db *db, const char *location)
|
||||
{
|
||||
@@ -325,7 +328,7 @@ static struct db *db_open(const tal_t *ctx, char *filename)
|
||||
db = tal(ctx, struct db);
|
||||
db->filename = tal_dup_arr(db, char, filename, strlen(filename), 0);
|
||||
db->sql = sql;
|
||||
tal_add_destructor(db, close_db);
|
||||
tal_add_destructor(db, destroy_db);
|
||||
db->in_transaction = NULL;
|
||||
db_do_exec(__func__, db, "PRAGMA foreign_keys = ON;");
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ void invoices_resolve(struct invoices *invoices,
|
||||
}
|
||||
|
||||
/* Called when an invoice waiter is destructed. */
|
||||
static void invoice_waiter_dtor(struct invoice_waiter *w)
|
||||
static void destroy_invoice_waiter(struct invoice_waiter *w)
|
||||
{
|
||||
/* Already triggered. */
|
||||
if (w->triggered)
|
||||
@@ -453,7 +453,7 @@ static void add_invoice_waiter(const tal_t *ctx,
|
||||
list_add_tail(waiters, &w->list);
|
||||
w->cb = cb;
|
||||
w->cbarg = cbarg;
|
||||
tal_add_destructor(w, &invoice_waiter_dtor);
|
||||
tal_add_destructor(w, &destroy_invoice_waiter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1327,7 +1327,7 @@ find_unstored_payment(struct wallet *wallet, const struct sha256 *payment_hash)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void remove_unstored_payment(struct wallet_payment *payment)
|
||||
static void destroy_unstored_payment(struct wallet_payment *payment)
|
||||
{
|
||||
list_del(&payment->list);
|
||||
}
|
||||
@@ -1337,7 +1337,7 @@ void wallet_payment_setup(struct wallet *wallet, struct wallet_payment *payment)
|
||||
assert(!find_unstored_payment(wallet, &payment->payment_hash));
|
||||
|
||||
list_add_tail(&wallet->unstored_payments, &payment->list);
|
||||
tal_add_destructor(payment, remove_unstored_payment);
|
||||
tal_add_destructor(payment, destroy_unstored_payment);
|
||||
}
|
||||
|
||||
void wallet_payment_store(struct wallet *wallet,
|
||||
|
||||
Reference in New Issue
Block a user