Browse Source

bolt-gen: keep single instance of type_obj per type

we rely, perhaps a bit hackily, on there only being one copy of
each type object floating about. using `deepcopy` on a Message
for message extensions destroys this paradigm, which breaks
things in the case where it's a later defined subtype that contains
variable-length members.

to fix this, we modify `__deepcopy__` on the Field class, such
that it preserves the reference to the original type_obj instance.
pull/2938/head
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
cfd56d86ee
  1. 9
      tools/generate-bolts.py
  2. 2
      tools/test/test_cases

9
tools/generate-bolts.py

@ -50,6 +50,15 @@ class Field(object):
self.is_optional = optional self.is_optional = optional
self.field_comments = field_comments self.field_comments = field_comments
def __deepcopy__(self, memo):
deepcopy_method = self.__deepcopy__
self.__deepcopy__ = None
field = copy.deepcopy(self, memo)
self.__deepcopy__ = deepcopy_method
field.type_obj = self.type_obj
return field
def add_count(self, count): def add_count(self, count):
self.count = int(count) self.count = int(count)

2
tools/test/test_cases

@ -40,6 +40,8 @@ msgdata,test_msg,test_sbt_varsize_var_assign,subtype_var_assign,
msgdata,test_msg,test_sbt_var_len,subtype_var_len, msgdata,test_msg,test_sbt_var_len,subtype_var_len,
msgdata,test_msg,test_sbt_varlen_varsize,subtype_varlen_varsize, msgdata,test_msg,test_sbt_varlen_varsize,subtype_varlen_varsize,
msgdata,test_msg,test_sbt_arrays,subtype_arrays, msgdata,test_msg,test_sbt_arrays,subtype_arrays,
# test extension fields
msgdata,test_msg,extension_1,test_features,,option_short_id
msgtype,test_tlv1,2 msgtype,test_tlv1,2
msgdata,test_tlv1,test_struct,test_short_id, msgdata,test_tlv1,test_struct,test_short_id,

Loading…
Cancel
Save