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

[perl #131666] NativeCall MoarVM panic

2 views
Skip to first unread message

Vladimir Marek

unread,
Jun 28, 2017, 1:15:03 AM6/28/17
to bugs-bi...@rt.perl.org
# New Ticket Created by Vladimir Marek
# Please include the string: [perl #131666]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=131666 >


I took the NativeCall sample from here:

https://perl6advent.wordpress.com/2015/12/21/day-21-nativecall-backs-and-beyond-c/

--------------------------------------------------------------------------------
use NativeCall;

sub XML_SetElementHandler(OpaquePointer $parser,
&start (OpaquePointer, Str, CArray[Str]),
&end (OpaquePointer, Str))
is native('expat') { ... }

sub XML_ParserCreate(Str --> OpaquePointer) is native('expat') { ... }
sub XML_ParserFree(OpaquePointer) is native('expat') { ... }
sub XML_Parse(OpaquePointer, Buf, int32, int32 --> int32) is native('expat') { ... }

my $xml = q:to/XML/;
<calendar>
<advent day="21">
<topic title="NativeCall Bits and Pieces"/>
</advent>
</calendar>
XML

my $depth = 0;

sub start-element($, $elem, $attr)
{
say "open $elem".indent($depth * 4);
++$depth;
}

sub end-element($, $elem)
{
--$depth;
say "close $elem".indent($depth * 4);
}

my $parser = XML_ParserCreate('UTF-8');
XML_SetElementHandler($parser, &start-element, &end-element);

my $buf = $xml.encode('UTF-8');
XML_Parse($parser, $buf, $buf.elems, 1);

XML_ParserFree($parser);
--------------------------------------------------------------------------------


All works fine, unless I try to use the $attr in start-element

sub start-element($, $elem, $attr)
{
say "open $elem".indent($depth * 4);
say $attr.elems;
++$depth;
}


The program then terminates with:

MoarVM panic: Internal error: Unwound entire stack and missed handler


I have seen that on Solaris, but Linux has the same issue. In both cases
custom build perl6 using 'rakudobrew build moar' so I suppose latest
git revision.

Thank you
--
Vlad

David Warring via RT

unread,
Apr 30, 2019, 2:00:03 AM4/30/19
to Vladimi...@oracle.com
Can confirm this is still current behaviour with Rakudo 2019. I have came across exactly the same issue and found this ticket. I've noticed, If I change the example to catch exceptions. It then runs:

sub start-element($, $elem, $attr)
{
say "open $elem".indent($depth * 4);
say $attr.elems;
++$depth;
CATCH { default { warn "whoops: $_" } }
}

Produces:

open calendar
whoops: Don't know how many elements a C array returned from a library
in block at /tmp/tst.p6 line 27
open advent
whoops: Don't know how many elements a C array returned from a library
in block at /tmp/tst.p6 line 27
...etc

Underlying issue seems to be that any uncaught exception in a NativeCall Perl callback currently results in a unfriendly NativeCall MoarVM panic. The exception itself is lost.
0 new messages