Skip to content
Permalink
Browse files

[JVM] Avoid StringIndexOutOfBoundsException

This is only a quick workaround to make rakudo-j usable for the
release.

The old code led to a StringIndexOutOfBoundsException, because
nqp::substr was called with -1 as the third positional
parameter ($length). On MoarVM this seems to mean "go to the
end of the string" -- cmp.
https://github.com/MoarVM/MoarVM/blob/8eb232dbcc/src/strings/ops.c#L716-L718

A cleaner fix would probably be to let nqp::substr work similar
on the JVM backend. But that's for after the release.
  • Loading branch information...
usev6 committed Apr 26, 2019
1 parent 5069981 commit 07b4f743815fce520f1baf7499c619ea0128095b
Showing with 4 additions and 2 deletions.
  1. +2 −1 src/main.nqp
  2. +2 −1 src/perl6-debug.nqp
@@ -23,8 +23,9 @@ my $config := nqp::backendconfig();
my $sep := $config<osname> eq 'MSWin32' ?? '\\' !! '/';
#?if jvm
my $execname := nqp::atkey(nqp::jvmgetproperties,'perl6.execname');
my $rindex-pos := nqp::rindex($execname, $sep, nqp::rindex($execname, $sep) - 1);
my $install-dir := $execname ne ''
?? nqp::substr($execname, 0, nqp::rindex($execname, $sep, nqp::rindex($execname, $sep) - 1))
?? nqp::substr($execname, 0, nqp::rindex($execname, $sep, $rindex-pos < 0 ?? nqp::chars($execname) !! $rindex-pos))
!! $comp.config<prefix>;
#?endif
#?if moar
@@ -471,8 +471,9 @@ sub MAIN(*@ARGS) {
my $sep := $config<osname> eq 'MSWin32' ?? '\\' !! '/';
#?if jvm
my $execname := nqp::atkey(nqp::jvmgetproperties,'perl6.execname');
my $rindex-pos := nqp::rindex($execname, $sep, nqp::rindex($execname, $sep) - 1);
my $install-dir := $execname ne ''
?? nqp::substr($execname, 0, nqp::rindex($execname, $sep, nqp::rindex($execname, $sep) - 1))
?? nqp::substr($execname, 0, nqp::rindex($execname, $sep, $rindex-pos < 0 ?? nqp::chars($execname) !! $rindex-pos))
!! $comp.config<prefix>;
#?endif
#?if moar

1 comment on commit 07b4f74

@usev6

This comment has been minimized.

Copy link
Contributor Author

commented on 07b4f74 Apr 26, 2019

There is already an issue for the differing behaviour of nqp::substr: perl6/nqp#324

Please sign in to comment.
You can’t perform that action at this time.