Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeCall MoarVM panic #6364

Open
p6rt opened this issue Jun 27, 2017 · 3 comments
Open

NativeCall MoarVM panic #6364

p6rt opened this issue Jun 27, 2017 · 3 comments

Comments

@p6rt
Copy link

p6rt commented Jun 27, 2017

Migrated from rt.perl.org#131666 (status was 'open')

Searchable as RT131666$

@p6rt
Copy link
Author

p6rt commented Jun 27, 2017

From Vladimir.Marek@oracle.com

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

@p6rt
Copy link
Author

p6rt commented Apr 30, 2019

From @dwarring

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​:

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

@p6rt
Copy link
Author

p6rt commented Apr 30, 2019

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant