mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
tools/generate_wire.py: make varlen structs self-allocate.
If we tell it a struct is variable length, make fromwire() allocate and return it off ctx. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
6ca0c6e0ec
commit
ad8dfaca1c
@@ -280,10 +280,12 @@ class Message(object):
|
||||
if f.fieldtype.is_assignable():
|
||||
subcalls.append('\t\t({})[i] = fromwire_{}(&cursor, plen);'
|
||||
.format(name, basetype))
|
||||
elif basetype in varlen_structs:
|
||||
subcalls.append('\t\t{}[i] = fromwire_{}(ctx, &cursor, plen);'
|
||||
.format(f.name, basetype))
|
||||
else:
|
||||
ctx = "ctx, " if basetype in varlen_structs else ""
|
||||
subcalls.append('\t\tfromwire_{}({}&cursor, plen, {} + i);'
|
||||
.format(basetype, ctx, name))
|
||||
subcalls.append('\t\tfromwire_{}(&cursor, plen, {} + i);'
|
||||
.format(basetype, name))
|
||||
|
||||
def print_fromwire(self,is_header):
|
||||
ctx_arg = 'const tal_t *ctx, ' if self.has_variable_fields else ''
|
||||
@@ -297,6 +299,8 @@ class Message(object):
|
||||
args.append(', {} {}[{}]'.format(f.fieldtype.name, f.name, f.num_elems))
|
||||
elif f.is_variable_size():
|
||||
args.append(', {} **{}'.format(f.fieldtype.name, f.name))
|
||||
elif f.basetype() in varlen_structs:
|
||||
args.append(', {} **{}'.format(f.fieldtype.name, f.name))
|
||||
else:
|
||||
args.append(', {} *{}'.format(f.fieldtype.name, f.name))
|
||||
|
||||
@@ -331,11 +335,12 @@ class Message(object):
|
||||
else:
|
||||
subcalls.append('\t*{} = fromwire_{}(&cursor, plen);'
|
||||
.format(f.name, basetype))
|
||||
elif basetype in varlen_structs:
|
||||
subcalls.append('\t*{} = fromwire_{}(ctx, &cursor, plen);'
|
||||
.format(f.name, basetype))
|
||||
else:
|
||||
subcalls.append("\t//4th case {name}".format(name=f.name))
|
||||
ctx = "ctx, " if basetype in varlen_structs else ""
|
||||
subcalls.append('\tfromwire_{}({}&cursor, plen, {});'
|
||||
.format(basetype, ctx, f.name))
|
||||
subcalls.append('\tfromwire_{}(&cursor, plen, {});'
|
||||
.format(basetype, f.name))
|
||||
|
||||
return template.format(
|
||||
name=self.name,
|
||||
|
||||
Reference in New Issue
Block a user