Skip Menu |
Report information
Id: 131666
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: Vladimir.Marek [at] oracle.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: Vladimir Marek <Vladimir.Marek [...] oracle.com>
Date: Tue, 27 Jun 2017 12:44:22 +0200
Subject: NativeCall MoarVM panic
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 1.8k
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
RT-Send-CC: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 2.7k
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. On Tue, 27 Jun 2017 05:59:08 -0700, Vladimir.Marek@oracle.com wrote: Show quoted text
> 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


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org