Recursively add offsets of Struct.field_from_path()

This commit is contained in:
Sybren A. Stüvel 2018-02-23 11:42:30 +01:00
parent 480b82337e
commit 8d32ab513f
2 changed files with 5 additions and 4 deletions

View File

@ -160,9 +160,6 @@ class Struct:
raise KeyError('%r has no field %r, only %r' %
(self, name, sorted(self._fields_by_name.keys())))
if name_tail:
return field.dna_type.field_from_path(pointer_size, name_tail)
offset = field.offset
if index:
if field.name.is_pointer:
@ -174,6 +171,10 @@ class Struct:
(path, field.dna_type))
offset += index_offset
if name_tail:
subval, suboff = field.dna_type.field_from_path(pointer_size, name_tail)
return subval, suboff + offset
return field, offset
def field_get(self,

View File

@ -126,7 +126,7 @@ class StructTest(unittest.TestCase):
self.assertEqual(self.s.field_from_path(psize, b'path'),
(self.f_path, 16))
self.assertEqual(self.s.field_from_path(psize, (b'prev', b'path')),
(self.f_path, 16))
(self.f_path, 24))
self.assertEqual(self.s.field_from_path(psize, (b'ptr', 2)),
(self.f_pointer, 16 + 4096 + 2 * psize))
self.assertEqual(self.s.field_from_path(psize, (b'floaty', 1)),