Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amount representations: initial groundwork. #2353

Merged
Next

type_to_string: return const char *.

Always be const if you can.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information...
rustyrussell committed Feb 18, 2019
commit be4d913e8352ba06e760ab423dab2abb88a70ac0
@@ -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,
union printable_types u)
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;
@@ -38,12 +38,12 @@ 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,
union printable_types u);
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, \
union printable_types u) \
static const char *fmt_##typename##_(const tal_t *ctx, \
union printable_types u) \
{ \
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)

#define REGISTER_TYPE_TO_HEXSTR(typename) \
static char *fmt_##typename##_(const tal_t *ctx, \
union printable_types u) \
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 */
@@ -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);
@@ -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);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.