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. 4
      common/type_to_string.c
  2. 8
      common/type_to_string.h
  3. 2
      lightningd/channel.c
  4. 2
      lightningd/opening_control.c

4
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 */
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)
{
char *s = NULL;
const char *s = NULL;
size_t i;
static size_t num_p;
static struct type_to_string **t = NULL;

8
common/type_to_string.h

@ -38,11 +38,11 @@ union printable_types {
((void)sizeof((ptr) == (type *)NULL), \
((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);
#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) \
{ \
return fmtfn(ctx, u.typename); \
@ -53,7 +53,7 @@ char *type_to_string_(const tal_t *ctx, const char *typename,
AUTODATA(type_to_string, &ttos_##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) \
{ \
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 {
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);
#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) {
/* FIXME: update log prefix when we get scid */
/* 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,
peer->log_book, "%s chan #%"PRIu64":",
idname, dbid);

2
lightningd/opening_control.c

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

Loading…
Cancel
Save