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

Owner: Nobody
Requestors: FROGGS.de <email [at] froggs.de>
Cc:
AdminCc:

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



Subject: NullPointerException on jvm for same CStruct in CStruct
Date: Mon, 02 Mar 2015 12:05:20 +0100
From: Tobias Leich <email [...] froggs.de>
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 1.6k
$ perl6-m -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }' $ perl6-j --ll-exception -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }' java.lang.NullPointerException in compose_repr (gen/jvm/Metamodel.nqp:1440) in compose (gen/jvm/Metamodel.nqp:2770) in pkg_compose (src/Perl6/World.nqp:1938) in package_def (gen/jvm/Perl6-Actions.nqp:1956) in !reduce (gen/jvm/stage2/QRegex.nqp:1241) in !cursor_pass (gen/jvm/stage2/QRegex.nqp:1202) in package_def (src/Perl6/Grammar.nqp:2445) in package_declarator:sym<class> (src/Perl6/Grammar.nqp) in !protoregex (gen/jvm/stage2/QRegex.nqp:1278) in package_declarator (src/Perl6/Grammar.nqp) in term:sym<package_declarator> (src/Perl6/Grammar.nqp) in !protoregex (gen/jvm/stage2/QRegex.nqp:1278) in term (src/Perl6/Grammar.nqp) in termish (src/Perl6/Grammar.nqp:3724) in EXPR (gen/jvm/stage2/NQPHLL.nqp:558) in EXPR (src/Perl6/Grammar.nqp:3755) in statement (src/Perl6/Grammar.nqp:1338) in statementlist (src/Perl6/Grammar.nqp:1270) in LANG (gen/jvm/stage2/NQPHLL.nqp:771) in FOREIGN_LANG (src/Perl6/Grammar.nqp:1681) in comp_unit (src/Perl6/Grammar.nqp:1128) in TOP (src/Perl6/Grammar.nqp:368) in parse (gen/jvm/stage2/QRegex.nqp:1872) in parse (gen/jvm/stage2/NQPHLL.nqp:1440) in compile (gen/jvm/stage2/NQPHLL.nqp:1396) in eval (gen/jvm/stage2/NQPHLL.nqp:1138) in (gen/jvm/stage2/NQPHLL.nqp:1244) in command_eval (gen/jvm/stage2/NQPHLL.nqp:1241) in command_eval (src/Perl6/Compiler.nqp:17) in command_line (gen/jvm/stage2/NQPHLL.nqp:1226) in MAIN (gen/jvm/main.nqp:39) in <mainline> (gen/jvm/main.nqp:35) in (gen/jvm/main.nqp)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 521b
The class definition no longer results in a NullPointerException: $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; say "alive"' alive But it's not possible to create an object of class Foo (works on MoarVM): $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say "alive"' java.lang.NoClassDefFoundError: L__CStruct__1; in method bless at gen/jvm/CORE.setting:949 in method new at gen/jvm/CORE.setting:935 in block <unit> at -e:1
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 562b
At first sight this looks good now: $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say "alive"' alive Unfortunatly, another NullPointerException surfaces when looking at the newly created $a: $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar' java.lang.NullPointerException in block <unit> at -e:1 Compare with rakudo.moar: $ perl6-m -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar' (Foo)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 899b
On Mon Jun 29 14:21:31 2015, bartolin@gmx.de wrote: Show quoted text
> Unfortunatly, another NullPointerException surfaces when looking at > the newly created $a: > > $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has > Foo $.bar }; my $a = Foo.new; say $a.bar' > java.lang.NullPointerException > in block <unit> at -e:1
I tried to look at this NPE, but was unable to find a fix. However, here is what I suspect -- maybe it is useful for someone else: I think the NPE happens in nqp/src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CStructInstance.java:95 (within public SixModelObject get_attribute_boxed) with the following code: o = (Object)Structure.newInstance(structClass, ((Pointer)o)); Four lines above 'o' is created with Object o = storage.readField(name); but 'storage.readField(name)' seems to be 'null'. Maybe this is not filled properly when the Perl 6 object is created?
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.2k
On Tue Jun 30 13:41:37 2015, bartolin@gmx.de wrote: Show quoted text
> On Mon Jun 29 14:21:31 2015, bartolin@gmx.de wrote:
> > Unfortunatly, another NullPointerException surfaces when looking at > > the newly created $a: > > > > $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has > > Foo $.bar }; my $a = Foo.new; say $a.bar' > > java.lang.NullPointerException > > in block <unit> at -e:1
> > I tried to look at this NPE, but was unable to find a fix. However, > here is what I suspect -- maybe it is useful for someone else: > > I think the NPE happens in > nqp/src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CStructInstance.java:95 > (within public SixModelObject get_attribute_boxed) with the following > code: > > o = (Object)Structure.newInstance(structClass, ((Pointer)o)); > > Four lines above 'o' is created with > > Object o = storage.readField(name); > > but 'storage.readField(name)' seems to be 'null'. Maybe this is not > filled properly when the Perl 6 object is created?
This appears to be working now; closable with tests: 09:57 < [Coke]> r: class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say 42; 09:57 <+camelia> rakudo-{moar,jvm} ba7027: OUTPUT«42␤» -- Will "Coke" Coleda
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 214b
Hmm, actually the second NPE is still there: $ perl6-j -e 'class Foo is repr<CStruct> { has int32 $.idontcare; has Foo $.bar }; my $a = Foo.new; say $a.bar' java.lang.NullPointerException in block <unit> at -e:1


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