Browse Source

type_to_string: return const char *.

Always be const if you can.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
confirmed-only
Rusty Russell 6 years ago
parent
commit
19d13f1781
  1. 6
      common/type_to_string.c
  2. 14
      common/type_to_string.h
  3. 2
      lightningd/channel.c
  4. 2
      lightningd/opening_control.c

6
common/type_to_string.c

@ -13,10 +13,10 @@ REGISTER_TYPE_TO_HEXSTR(ripemd160);
/* This one in bitcoin/ but doesn't have its own C file */ /* This one in bitcoin/ but doesn't have its own C file */
REGISTER_TYPE_TO_HEXSTR(preimage); REGISTER_TYPE_TO_HEXSTR(preimage);
char *type_to_string_(const tal_t *ctx, const char *typename, const char *type_to_string_(const tal_t *ctx, const char *typename,
union printable_types u) union printable_types u)
{ {
char *s = NULL; const char *s = NULL;
size_t i; size_t i;
static size_t num_p; static size_t num_p;
static struct type_to_string **t = NULL; static struct type_to_string **t = NULL;

14
common/type_to_string.h

@ -38,12 +38,12 @@ union printable_types {
((void)sizeof((ptr) == (type *)NULL), \ ((void)sizeof((ptr) == (type *)NULL), \
((union printable_types)((const type *)ptr)))) ((union printable_types)((const type *)ptr))))
char *type_to_string_(const tal_t *ctx, const char *typename, const char *type_to_string_(const tal_t *ctx, const char *typename,
union printable_types u); union printable_types u);
#define REGISTER_TYPE_TO_STRING(typename, fmtfn) \ #define REGISTER_TYPE_TO_STRING(typename, fmtfn) \
static char *fmt_##typename##_(const tal_t *ctx, \ static const char *fmt_##typename##_(const tal_t *ctx, \
union printable_types u) \ union printable_types u) \
{ \ { \
return fmtfn(ctx, u.typename); \ return fmtfn(ctx, u.typename); \
} \ } \
@ -53,8 +53,8 @@ char *type_to_string_(const tal_t *ctx, const char *typename,
AUTODATA(type_to_string, &ttos_##typename) AUTODATA(type_to_string, &ttos_##typename)
#define REGISTER_TYPE_TO_HEXSTR(typename) \ #define REGISTER_TYPE_TO_HEXSTR(typename) \
static char *fmt_##typename##_(const tal_t *ctx, \ static const char *fmt_##typename##_(const tal_t *ctx, \
union printable_types u) \ union printable_types u) \
{ \ { \
return tal_hexstr(ctx, u.typename, sizeof(*u.typename)); \ return tal_hexstr(ctx, u.typename, sizeof(*u.typename)); \
} \ } \
@ -65,7 +65,7 @@ char *type_to_string_(const tal_t *ctx, const char *typename,
struct type_to_string { struct type_to_string {
const char *typename; const char *typename;
char *(*fmt)(const tal_t *ctx, union printable_types u); const char *(*fmt)(const tal_t *ctx, union printable_types u);
}; };
AUTODATA_TYPE(type_to_string, struct type_to_string); AUTODATA_TYPE(type_to_string, struct type_to_string);
#endif /* LIGHTNING_COMMON_TYPE_TO_STRING_H */ #endif /* LIGHTNING_COMMON_TYPE_TO_STRING_H */

2
lightningd/channel.c

@ -195,7 +195,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
if (!log) { if (!log) {
/* FIXME: update log prefix when we get scid */ /* FIXME: update log prefix when we get scid */
/* FIXME: Use minimal unique pubkey prefix for logs! */ /* FIXME: Use minimal unique pubkey prefix for logs! */
char *idname = type_to_string(peer, struct pubkey, &peer->id); const char *idname = type_to_string(peer, struct pubkey, &peer->id);
channel->log = new_log(channel, channel->log = new_log(channel,
peer->log_book, "%s chan #%"PRIu64":", peer->log_book, "%s chan #%"PRIu64":",
idname, dbid); idname, dbid);

2
lightningd/opening_control.c

@ -604,7 +604,7 @@ new_uncommitted_channel(struct peer *peer)
{ {
struct lightningd *ld = peer->ld; struct lightningd *ld = peer->ld;
struct uncommitted_channel *uc = tal(ld, struct uncommitted_channel); struct uncommitted_channel *uc = tal(ld, struct uncommitted_channel);
char *idname; const char *idname;
uc->peer = peer; uc->peer = peer;
assert(!peer->uncommitted_channel); assert(!peer->uncommitted_channel);

Loading…
Cancel
Save