Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #40958] [BUG] - can't iterate subclass of ResizablePMCArray

3 views
Skip to first unread message

Patrick R . Michaud

unread,
Nov 20, 2006, 5:20:27 PM11/20/06
to bugs-bi...@rt.perl.org
# New Ticket Created by Patrick R. Michaud
# Please include the string: [perl #40958]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=40958 >


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

Chromatic

unread,
Dec 6, 2006, 11:22:51 PM12/6/06
to perl6-i...@perl.org, Patrick R.Michaud

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

rpa_iterate_naive.patch

Chromatic

unread,
Dec 11, 2006, 12:36:11 AM12/11/06
to perl6-i...@perl.org, Patrick R.Michaud
On Monday 20 November 2006 14:20, Patrick R.Michaud wrote:

> 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

rpm_iterator_does.patch
0 new messages