I don't seem to be able to use iterators on subclasses of
ResizablePMCArray. Here's an example:
$ cat t.pir
.sub main :main
.local pmc ar, iter
$P0 = subclass 'ResizablePMCArray', 'MyArray'
ar = new 'MyArray'
push ar, 1
push ar, 3
push ar, 5
$I0 = elements ar
print $I0
print "\n"
iter = new .Iterator, ar
iter_loop:
unless iter goto iter_end
$P0 = shift iter
say $P0
goto iter_loop
iter_end:
.end
$ ./parrot t.pir
3
Segmentation fault
$
Test being added to t/pmc/resizablepmcarray.t .
Thanks,
Pm
Here's a naive patch which demonstrates exactly what the problem is. The
iteration code within the PMC checks that it has an object without checking
to see if that object extends an iterable type. I hard-coded this test
because it was easier than the correct fix -- making an iterable role and
making sure that VTABLE_does() works all the way back to "array".
-- c
> I don't seem to be able to use iterators on subclasses of
> ResizablePMCArray.
Here's a better patch, but it appears to tickle a bug in Data::Dumper. I'm
not sure what the right fix is there.
I'm not a big fan of my implementation here, but this was the least invasive
strategy I could find. A better fix would be twofold:
- add a role for "iterable"
- fix the does_isa() mess in the Default PMC. There's a comment in there
about how it doesn't respect mro, and it's clear that it doesn't. However, I
don't want to duplicate the MRO logic I put in ParrotObject, but I ran into
segfaults when I put it in Default.
I suspect this also is a symptom of the problem that Parrot's never quite sure
how ParrotObject interacts with other PMCs.
I also worry somewhat that having does fall back to isa is backwards, but
that's an even bigger change.
-- c