mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
common: reduce header differences for DEVELOPER vs non-DEVELOPER.
`make update-mocks` is usually run in DEVELOPER mode, but then it includes definitions for functions which aren't declared in non-DEVELOPER mode. We hacked this in a few places, but it's fragile, and worst, now we have EXPERIMENTAL_FEATURES as well, it's complex. Instead, declare developer-only functions (but don't define them). This is a bit more awkward if you accidentally use one in non-DEVELOPER code (link error rather than compile error), but makes autogenerating test mocks much easier. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
077ba88b88
commit
837e6232c3
7 changed files with 62 additions and 78 deletions
|
@ -270,4 +270,9 @@ void memleak_cleanup(void)
|
|||
{
|
||||
notleaks = tal_free(notleaks);
|
||||
}
|
||||
#endif /* DEVELOPER */
|
||||
#else /* !DEVELOPER */
|
||||
void *notleak_(const void *ptr, bool plus_children UNNEEDED)
|
||||
{
|
||||
return cast_const(void *, ptr);
|
||||
}
|
||||
#endif /* !DEVELOPER */
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
/* Mark a pointer and all its tal children as not being leaked. */
|
||||
#define notleak_with_children(p) ((memleak_typeof(p))notleak_((p), true))
|
||||
|
||||
#if DEVELOPER
|
||||
void *notleak_(const void *ptr, bool plus_children);
|
||||
|
||||
struct htable;
|
||||
|
@ -53,11 +52,4 @@ void memleak_scan_region(struct htable *memtable,
|
|||
/* Get (and remove) a leak from memtable, or NULL */
|
||||
const void *memleak_get(struct htable *memtable, const uintptr_t **backtrace);
|
||||
|
||||
#else /* ... !DEVELOPER */
|
||||
static inline void *notleak_(const void *ptr, bool plus_children UNNEEDED)
|
||||
{
|
||||
return cast_const(void *, ptr);
|
||||
}
|
||||
#endif /* !DEVELOPER */
|
||||
|
||||
#endif /* LIGHTNING_COMMON_MEMLEAK_H */
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
#define LIGHTNING_COMMON_SUBDAEMON_H
|
||||
#include "config.h"
|
||||
#include <common/daemon.h>
|
||||
struct htable;
|
||||
|
||||
/* daemon_setup, but for subdaemons */
|
||||
void subdaemon_setup(int argc, char *argv[]);
|
||||
|
||||
#if DEVELOPER
|
||||
struct htable;
|
||||
|
||||
/* Only defined if DEVELOPER */
|
||||
bool dump_memleak(struct htable *memtable);
|
||||
#endif
|
||||
|
||||
#endif /* LIGHTNING_COMMON_SUBDAEMON_H */
|
||||
|
|
|
@ -396,10 +396,8 @@ bool routing_add_node_announcement(struct routing_state *rstate,
|
|||
bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg,
|
||||
u64 index);
|
||||
|
||||
#if DEVELOPER
|
||||
void memleak_remove_routing_tables(struct htable *memtable,
|
||||
const struct routing_state *rstate);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Get the local time.
|
||||
|
|
|
@ -35,6 +35,9 @@ void daemon_shutdown(void)
|
|||
/* Generated stub for decode_short_ids */
|
||||
struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *encoded UNNEEDED)
|
||||
{ fprintf(stderr, "decode_short_ids called!\n"); abort(); }
|
||||
/* Generated stub for dump_memleak */
|
||||
bool dump_memleak(struct htable *memtable UNNEEDED)
|
||||
{ fprintf(stderr, "dump_memleak called!\n"); abort(); }
|
||||
/* Generated stub for first_chan */
|
||||
struct chan *first_chan(const struct node *node UNNEEDED, struct chan_map_iter *i UNNEEDED)
|
||||
{ fprintf(stderr, "first_chan called!\n"); abort(); }
|
||||
|
@ -186,6 +189,18 @@ u8 *make_ping(const tal_t *ctx UNNEEDED, u16 num_pong_bytes UNNEEDED, u16 padlen
|
|||
/* Generated stub for master_badmsg */
|
||||
void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg)
|
||||
{ fprintf(stderr, "master_badmsg called!\n"); abort(); }
|
||||
/* Generated stub for memleak_enter_allocations */
|
||||
struct htable *memleak_enter_allocations(const tal_t *ctx UNNEEDED,
|
||||
const void *exclude1 UNNEEDED,
|
||||
const void *exclude2 UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_enter_allocations called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_referenced */
|
||||
void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *root UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_referenced called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_routing_tables */
|
||||
void memleak_remove_routing_tables(struct htable *memtable UNNEEDED,
|
||||
const struct routing_state *rstate UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_routing_tables called!\n"); abort(); }
|
||||
/* Generated stub for new_reltimer_ */
|
||||
struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
|
||||
const tal_t *ctx UNNEEDED,
|
||||
|
@ -203,6 +218,9 @@ struct routing_state *new_routing_state(const tal_t *ctx UNNEEDED,
|
|||
/* Generated stub for next_chan */
|
||||
struct chan *next_chan(const struct node *node UNNEEDED, struct chan_map_iter *i UNNEEDED)
|
||||
{ fprintf(stderr, "next_chan called!\n"); abort(); }
|
||||
/* Generated stub for notleak_ */
|
||||
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
|
||||
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
|
||||
/* Generated stub for read_addresses */
|
||||
struct wireaddr *read_addresses(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "read_addresses called!\n"); abort(); }
|
||||
|
@ -308,27 +326,6 @@ bool wire_sync_write(int fd UNNEEDED, const void *msg TAKES UNNEEDED)
|
|||
{ fprintf(stderr, "wire_sync_write called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
#if DEVELOPER
|
||||
/* Generated stub for dump_memleak */
|
||||
bool dump_memleak(struct htable *memtable UNNEEDED)
|
||||
{ fprintf(stderr, "dump_memleak called!\n"); abort(); }
|
||||
/* Generated stub for memleak_enter_allocations */
|
||||
struct htable *memleak_enter_allocations(const tal_t *ctx UNNEEDED,
|
||||
const void *exclude1 UNNEEDED,
|
||||
const void *exclude2 UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_enter_allocations called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_referenced */
|
||||
void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *root UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_referenced called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_routing_tables */
|
||||
void memleak_remove_routing_tables(struct htable *memtable UNNEEDED,
|
||||
const struct routing_state *rstate UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_routing_tables called!\n"); abort(); }
|
||||
/* Generated stub for notleak_ */
|
||||
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
|
||||
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
|
||||
#endif /* DEVELOPER */
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
/* Generated stub for decode_scid_query_flags */
|
||||
bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED,
|
||||
|
|
|
@ -23,6 +23,9 @@ bool derive_keyset(const struct pubkey *per_commitment_point UNNEEDED,
|
|||
const struct basepoints *other UNNEEDED,
|
||||
struct keyset *keyset UNNEEDED)
|
||||
{ fprintf(stderr, "derive_keyset called!\n"); abort(); }
|
||||
/* Generated stub for dump_memleak */
|
||||
bool dump_memleak(struct htable *memtable UNNEEDED)
|
||||
{ fprintf(stderr, "dump_memleak called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_fail */
|
||||
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
||||
|
@ -74,6 +77,21 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx UNNEEDED,
|
|||
/* Generated stub for master_badmsg */
|
||||
void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg)
|
||||
{ fprintf(stderr, "master_badmsg called!\n"); abort(); }
|
||||
/* Generated stub for memleak_enter_allocations */
|
||||
struct htable *memleak_enter_allocations(const tal_t *ctx UNNEEDED,
|
||||
const void *exclude1 UNNEEDED,
|
||||
const void *exclude2 UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_enter_allocations called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_referenced */
|
||||
void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *root UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_referenced called!\n"); abort(); }
|
||||
/* Generated stub for memleak_scan_region */
|
||||
void memleak_scan_region(struct htable *memtable UNNEEDED,
|
||||
const void *p UNNEEDED, size_t bytelen UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_scan_region called!\n"); abort(); }
|
||||
/* Generated stub for notleak_ */
|
||||
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
|
||||
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
|
||||
/* Generated stub for onchain_wire_type_name */
|
||||
const char *onchain_wire_type_name(int e UNNEEDED)
|
||||
{ fprintf(stderr, "onchain_wire_type_name called!\n"); abort(); }
|
||||
|
@ -144,27 +162,6 @@ u8 *towire_onchain_unwatch_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx
|
|||
{ fprintf(stderr, "towire_onchain_unwatch_tx called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
#if DEVELOPER
|
||||
/* Generated stub for dump_memleak */
|
||||
bool dump_memleak(struct htable *memtable UNNEEDED)
|
||||
{ fprintf(stderr, "dump_memleak called!\n"); abort(); }
|
||||
/* Generated stub for memleak_enter_allocations */
|
||||
struct htable *memleak_enter_allocations(const tal_t *ctx UNNEEDED,
|
||||
const void *exclude1 UNNEEDED,
|
||||
const void *exclude2 UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_enter_allocations called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_referenced */
|
||||
void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *root UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_referenced called!\n"); abort(); }
|
||||
/* Generated stub for memleak_scan_region */
|
||||
void memleak_scan_region(struct htable *memtable UNNEEDED,
|
||||
const void *p UNNEEDED, size_t bytelen UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_scan_region called!\n"); abort(); }
|
||||
/* Generated stub for notleak_ */
|
||||
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
|
||||
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
|
||||
#endif /* DEVELOPER */
|
||||
|
||||
/* Stubs which do get called. */
|
||||
u8 *towire_hsm_sign_local_htlc_tx(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,9 @@ bool derive_keyset(const struct pubkey *per_commitment_point UNNEEDED,
|
|||
const struct basepoints *other UNNEEDED,
|
||||
struct keyset *keyset UNNEEDED)
|
||||
{ fprintf(stderr, "derive_keyset called!\n"); abort(); }
|
||||
/* Generated stub for dump_memleak */
|
||||
bool dump_memleak(struct htable *memtable UNNEEDED)
|
||||
{ fprintf(stderr, "dump_memleak called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_fail */
|
||||
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
||||
|
@ -86,6 +89,21 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx UNNEEDED,
|
|||
/* Generated stub for master_badmsg */
|
||||
void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg)
|
||||
{ fprintf(stderr, "master_badmsg called!\n"); abort(); }
|
||||
/* Generated stub for memleak_enter_allocations */
|
||||
struct htable *memleak_enter_allocations(const tal_t *ctx UNNEEDED,
|
||||
const void *exclude1 UNNEEDED,
|
||||
const void *exclude2 UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_enter_allocations called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_referenced */
|
||||
void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *root UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_referenced called!\n"); abort(); }
|
||||
/* Generated stub for memleak_scan_region */
|
||||
void memleak_scan_region(struct htable *memtable UNNEEDED,
|
||||
const void *p UNNEEDED, size_t bytelen UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_scan_region called!\n"); abort(); }
|
||||
/* Generated stub for notleak_ */
|
||||
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
|
||||
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
|
||||
/* Generated stub for peer_billboard */
|
||||
void peer_billboard(bool perm UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "peer_billboard called!\n"); abort(); }
|
||||
|
@ -166,27 +184,6 @@ bool wire_sync_write(int fd UNNEEDED, const void *msg TAKES UNNEEDED)
|
|||
{ fprintf(stderr, "wire_sync_write called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
#if DEVELOPER
|
||||
/* Generated stub for dump_memleak */
|
||||
bool dump_memleak(struct htable *memtable UNNEEDED)
|
||||
{ fprintf(stderr, "dump_memleak called!\n"); abort(); }
|
||||
/* Generated stub for memleak_enter_allocations */
|
||||
struct htable *memleak_enter_allocations(const tal_t *ctx UNNEEDED,
|
||||
const void *exclude1 UNNEEDED,
|
||||
const void *exclude2 UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_enter_allocations called!\n"); abort(); }
|
||||
/* Generated stub for memleak_remove_referenced */
|
||||
void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *root UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_remove_referenced called!\n"); abort(); }
|
||||
/* Generated stub for memleak_scan_region */
|
||||
void memleak_scan_region(struct htable *memtable UNNEEDED,
|
||||
const void *p UNNEEDED, size_t bytelen UNNEEDED)
|
||||
{ fprintf(stderr, "memleak_scan_region called!\n"); abort(); }
|
||||
/* Generated stub for notleak_ */
|
||||
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
|
||||
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setup_locale();
|
||||
|
|
Loading…
Add table
Reference in a new issue