diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-07-05 22:26:52 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-07-05 22:26:52 -0700 |
commit | 73e6b7fcbfdf075dc4dd1843d201aff20e875987 (patch) | |
tree | ae0a50fc2f6e7662f3c162b6a68a658d8e976fd6 /struct.c | |
parent | 6024c4489837ad3813c6437a9576ab2072a184ed (diff) | |
download | txr-73e6b7fcbfdf075dc4dd1843d201aff20e875987.tar.gz txr-73e6b7fcbfdf075dc4dd1843d201aff20e875987.tar.bz2 txr-73e6b7fcbfdf075dc4dd1843d201aff20e875987.zip |
structs: get tests/012/stslot.tl to pass.
* struct.c (static_slot_rewrite_rec): A simple rearrangement:
switch to postorder traversal, doing the derived structs
first, then this struct. Why does this fix a bug? Because
when the assignment *s = *to occurs for the node at the root
of the recursion, s and from point to the same object. And
so the assignment alters from, which is the search key.
When the children are then processed, the search key doesn't
match anything: it now looks like the to slot that the
children are supposed to get, and so they don't have it, of
course. So in other words the slot being rewritten is not
found in the derived types and not rewritten there as it
should be.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -1024,6 +1024,13 @@ static void static_slot_rewrite_rec(struct struct_type *st, struct stslot *to) { cnum i; + val iter; + + for (iter = st->dvtypes; iter; iter = cdr(iter)) { + val stype = car(iter); + struct struct_type *st = coerce(struct struct_type *, stype->co.handle); + static_slot_rewrite_rec(st, from, to); + } for (i = 0; i < st->nstslots; i++) { struct stslot *s = &st->stslot[i]; @@ -1035,16 +1042,6 @@ static void static_slot_rewrite_rec(struct struct_type *st, *s = *to; } } - - { - val iter; - - for (iter = st->dvtypes; iter; iter = cdr(iter)) { - val stype = car(iter); - struct struct_type *st = coerce(struct struct_type *, stype->co.handle); - static_slot_rewrite_rec(st, from, to); - } - } } |