Recursively add offsets of Struct.field_from_path()
This commit is contained in:
parent
480b82337e
commit
8d32ab513f
@ -160,9 +160,6 @@ class Struct:
|
|||||||
raise KeyError('%r has no field %r, only %r' %
|
raise KeyError('%r has no field %r, only %r' %
|
||||||
(self, name, sorted(self._fields_by_name.keys())))
|
(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
|
offset = field.offset
|
||||||
if index:
|
if index:
|
||||||
if field.name.is_pointer:
|
if field.name.is_pointer:
|
||||||
@ -174,6 +171,10 @@ class Struct:
|
|||||||
(path, field.dna_type))
|
(path, field.dna_type))
|
||||||
offset += index_offset
|
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
|
return field, offset
|
||||||
|
|
||||||
def field_get(self,
|
def field_get(self,
|
||||||
|
|||||||
@ -126,7 +126,7 @@ class StructTest(unittest.TestCase):
|
|||||||
self.assertEqual(self.s.field_from_path(psize, b'path'),
|
self.assertEqual(self.s.field_from_path(psize, b'path'),
|
||||||
(self.f_path, 16))
|
(self.f_path, 16))
|
||||||
self.assertEqual(self.s.field_from_path(psize, (b'prev', b'path')),
|
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.assertEqual(self.s.field_from_path(psize, (b'ptr', 2)),
|
||||||
(self.f_pointer, 16 + 4096 + 2 * psize))
|
(self.f_pointer, 16 + 4096 + 2 * psize))
|
||||||
self.assertEqual(self.s.field_from_path(psize, (b'floaty', 1)),
|
self.assertEqual(self.s.field_from_path(psize, (b'floaty', 1)),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user